From: John Kitchin <jkitchin@andrew.cmu.edu>
To: Richard Lawrence <richard.lawrence@berkeley.edu>
Cc: Ilya <filip83pov@yandex.ru>, emacs-orgmode@gnu.org
Subject: Re: LaTeX export with section number, name and page in internal links
Date: Tue, 08 Dec 2015 15:29:46 -0500 [thread overview]
Message-ID: <m2mvtkiszp.fsf@andrew.cmu.edu> (raw)
In-Reply-To: <87mvtkubrm.fsf@berkeley.edu>
> I do something like this with custom link types.
Aha! I am not the only one ;)
>
> First of all, have a look at the variable
>
> org-latex-prefer-user-labels
Is this a new 8.3 variable? It doesn't seem to be in my 8.2.10 MELPA
version.
>
> if you haven't already. Setting it will cause Org to use CUSTOM_ID
> properties to generate labels, so you don't need to manually insert your
> own.
>
> I use the following bit of Elisp to define some link types for referring
> to sections this way. You could modify this to insert the LaTeX command
> you're interested in (as opposed to just \ref{}). With your example
> above, you'd write something like
I like your idea. I think you could simplify it to just:
(org-add-link-type
"sec"
(lambda (path)
(org-open-link-from-string (format "[[#%s]]" path)))
(lambda (path desc format)
(cond
((eq format 'latex)
(format "%s~\\ref{%s}" (or desc "Section") path)))))
and refer to [[sec:section-1]] that looks like this below.
** some title
:PROPERTIES:
:CUSTOM_ID: section-1
:END:
>
> #+BEGIN_EXAMPLE
> I want reference to Section 1.1 from here (See [[sec:section-1]]).
> #+END_EXAMPLE
>
> Here's the code:
> #+BEGIN_SRC elisp
> ;; Link types for targeting sections, tables, etc.
> ;; These assume that headlines with CUSTOM_ID defined will export using
> ;; that value as their \label keys.
> (defun org-find-headline-by-custom-id (prefix path)
> "Find a headline in the current buffer by CUSTOM_ID value PREFIX:PATH."
> (save-excursion
> (goto-char (point-min))
> (and
> ; borrowed from org.el; there doesn't seem to be a function that searches
> ; for a headline with a specific property value
> (re-search-forward
> (concat "^[ \t]*:CUSTOM_ID:[ \t]+" prefix ":" path "[ \t]*$") nil t)
> (setq pos (match-beginning 0))))
> (if pos
> (progn
> (goto-char pos)
> (org-back-to-heading t))
> (message (format "Headline with CUSTOM_ID %s:%s not found." prefix path))))
>
> (defun org-export-dissertation-link (prefix path desc format)
> "Export a link to a dissertation section, etc.
>
> In LaTeX, the exported link will look like:
> DESC~\\ref{PREFIX:PATH}
> "
> (when (member format '(latex linguistics))
> (format "%s~\\ref{%s:%s}" desc prefix path)))
>
> ; Sections:
> (org-add-link-type
> "sec"
> (lambda (path)
> (org-find-headline-by-custom-id "sec" path))
> (lambda (path desc format)
> (org-export-dissertation-link "sec" path (or desc "Section") format)))
>
> ; etc. etc.
> #+END_SRC elisp
>
> Best,
> Richard
>
> OpenPGP Key ID: CF6FA646
> Fingerprint: 9969 43E1 CF6F A646
>
> (See http://www.ocf.berkeley.edu/~rwl/encryption.html for more information.)
--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
next prev parent reply other threads:[~2015-12-08 20:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-03 11:08 LaTeX export with section number, name and page in internal links Ilya
2015-12-03 11:31 ` John Kitchin
2015-12-03 13:30 ` Ilya Filippov
2015-12-08 14:19 ` Ken Mankoff
2015-12-03 14:27 ` Fwd: " Ilya Filippov
2015-12-08 16:48 ` Richard Lawrence
2015-12-08 20:29 ` John Kitchin [this message]
2015-12-09 17:47 ` Richard Lawrence
-- strict thread matches above, loose matches on Subject: below --
2015-12-03 5:36 Ilya Filippov
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=m2mvtkiszp.fsf@andrew.cmu.edu \
--to=jkitchin@andrew.cmu.edu \
--cc=emacs-orgmode@gnu.org \
--cc=filip83pov@yandex.ru \
--cc=richard.lawrence@berkeley.edu \
/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).