emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Exporting fuzzy links using LaTeX's autoref
@ 2016-08-09  2:03 Clément Pit--Claudel
  0 siblings, 0 replies; 2+ messages in thread
From: Clément Pit--Claudel @ 2016-08-09  2:03 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1868 bytes --]

Hi all,

The LaTeX command \autoref{} produces a hyperlink that covers both the target type and its number; for example, \autoref{chap:org} produces something like _Chapter 3_. It's very similar to Chapter \ref{chap:org}, but:

* "Chapter" is clickable
* I can demote this chapter to a section, or change a figure into a tale, and the word "Chapter" or "Figure" will appropriately change.

I'd like to use this facility in my org-mode documents. I started defining a new link type [[autoref:(1)][(2)]]; (1) is the actual link, and (2) is the text to use in HTML export (Figure, Section, ...); LaTeX export ignores it (this isn't ideal, because in the buffer it only shows Figure, section, etc.; bu since the follow function of custom links only gets the path, I didn't find another way).

This mostly worked:

(org-add-link-type "autoref" #'org-autoref-follow  #'org-autoref-export)

(defun org-autoref-follow (path)
  "Follow fuzzy link PATH."
  (unless (run-hook-with-args-until-success
           'org-open-link-functions path)
    (let ((destination (org-with-wide-buffer
                        (org-link-search path (point)) ;; should be +2 of beginning
                        (point))))
      (unless (and (<= (point-min) destination)
                   (>= (point-max) destination))
        (widen))
      (goto-char destination))))

but then I started looking at org-autoref-export, and things got hairy. org-latex-link gets three arguments (link desc info), which it uses in the fuzzy link case to call (org-export-resolve-fuzzy-link link info). But custom links don't get quite as much info: they just get the path, and not the `info' parameter. I wasn't sure how to proceed at that point, so I wrote my function as :around advice on org-latex-link; which is not too satisfactory.

Did I miss something?

Thanks!
Clément.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Exporting fuzzy links using LaTeX's autoref
@ 2016-10-13 13:35 Konstantin Kliakhandler
  0 siblings, 0 replies; 2+ messages in thread
From: Konstantin Kliakhandler @ 2016-10-13 13:35 UTC (permalink / raw)
  To: clement.pit; +Cc: emacs-orgmode

Hi Clément,

I don’t know if you’ve found a satisfactory solution yet, but I found the following to work quite well in my case:

  ;; Define an export function for autoref links
  (defun kk/org-autoref-export (path desc format)
    "Export an autoref type reference for the given path"
    (case format
      ('latex (string-join `("\\autoref{" ,path "}")))))

  ;; Define a function for following org links
  (defun kk/org-follow-path (path)
    "Follow an org path given in the argument"
    (org-open-link-from-string (string-join `("[[" ,path "]]"))))

  ;; Register autoref link type
  (org-add-link-type "ar" 'kk/org-follow-path 'kk/org-autoref-export)

It works fine for items that have a #+NAME attached to them, perhaps to other stuff as well (though I haven’t tested this).
Hope it helps.

Good luck,
Kosta

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-10-13 13:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-13 13:35 Exporting fuzzy links using LaTeX's autoref Konstantin Kliakhandler
  -- strict thread matches above, loose matches on Subject: below --
2016-08-09  2:03 Clément Pit--Claudel

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).