From: Richard Lawrence <richard.lawrence@berkeley.edu>
To: 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 08:48:45 -0800 [thread overview]
Message-ID: <87mvtkubrm.fsf@berkeley.edu> (raw)
In-Reply-To: <loom.20151203T120613-367@post.gmane.org>
Hi Ilya,
Ilya <filip83pov@yandex.ru> writes:
> I export my Org-Mode notes with internal links to LaTeX and I want it to
> look like this ''Section 1.1 [Section name], page 99'' (Like in the Org
> Manual). I use this construction:
>
> #+BEGIN_EXAMPLE
> * Chapter 1
> ** Section 1.1
> :PROPERTIES:
> :CUSTOM_ID: section-1
> :END:
> * Chapter 2
> ** Section 2.1
> I want reference to Section 1.1 from here (See #section-1)
> #+END_EXAMPLE
>
> But as a result I get only the number of the section ''1.1'', not the
> ''Section 1.1 [Section name], page 99''.
> What options I need to use?
I do something like this with custom link types.
First of all, have a look at the variable
org-latex-prefer-user-labels
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
#+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.)
next prev parent reply other threads:[~2015-12-08 16:48 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 [this message]
2015-12-08 20:29 ` John Kitchin
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mvtkubrm.fsf@berkeley.edu \
--to=richard.lawrence@berkeley.edu \
--cc=emacs-orgmode@gnu.org \
--cc=filip83pov@yandex.ru \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.