emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] Exporting fuzzy links using LaTeX's autoref


From: Clément Pit--Claudel
Subject: [O] Exporting fuzzy links using LaTeX's autoref
Date: Mon, 8 Aug 2016 22:03:11 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

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

[Prev in Thread] Current Thread [Next in Thread]