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: signature.asc
Description: OpenPGP digital signature

Reply via email to