emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Clément Pit--Claudel" <clement.pit@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Exporting fuzzy links using LaTeX's autoref
Date: Mon, 8 Aug 2016 22:03:11 -0400	[thread overview]
Message-ID: <89a1be0e-011a-8875-0886-28a18ab13b87@gmail.com> (raw)


[-- 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 --]

             reply	other threads:[~2016-08-09  2:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-09  2:03 Clément Pit--Claudel [this message]
  -- strict thread matches above, loose matches on Subject: below --
2016-10-13 13:35 Exporting fuzzy links using LaTeX's autoref Konstantin Kliakhandler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=89a1be0e-011a-8875-0886-28a18ab13b87@gmail.com \
    --to=clement.pit@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).