From: Richard Lawrence <richard.lawrence@berkeley.edu>
To: emacs-orgmode@gnu.org
Subject: [patch] Support CUSTOM_ID property in latex export
Date: Sat, 15 Feb 2014 12:19:54 -0800 [thread overview]
Message-ID: <87y51cgmc5.fsf@aquinas.i-did-not-set--mail-host-address--so-tickle-me> (raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Patch to support CUSTOM_ID property in latex export --]
[-- Type: text/x-diff, Size: 2537 bytes --]
From 81115d0884c165778520aa1b4d4fa83580417e1c Mon Sep 17 00:00:00 2001
From: Richard Lawrence <richard.lawrence@berkeley.edu>
Date: Sat, 15 Feb 2014 11:59:44 -0800
Subject: [PATCH] LaTeX export: support CUSTOM_ID property in section labels
and link refs
* lisp/ox-latex.el (org-latex-headline): when exporting a headline, if
it has a CUSTOM_ID property, use that value as the associated
label for a section (or whatever)
(org-latex-link): when exporting a link, if the
destination is a headline with a CUSTOM_ID property, use that value
in the referencing command
Fixes an issue raised at: http://thread.gmane.org/gmane.emacs.orgmode/54039
TINYCHANGE
---
lisp/ox-latex.el | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 5815874..cbca0a5 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1372,11 +1372,14 @@ holding contextual information."
(full-text (funcall org-latex-format-headline-function
todo todo-type priority text tags))
;; Associate \label to the headline for internal links.
+ ;; Use the value of :CUSTOM_ID: property as label if it is defined.
(headline-label
- (format "\\label{sec-%s}\n"
- (mapconcat 'number-to-string
- (org-export-get-headline-number headline info)
- "-")))
+ (let ((custom-label (org-element-property :CUSTOM_ID headline)))
+ (if custom-label (format "\\label{%s}\n" custom-label)
+ (format "\\label{sec-%s}\n"
+ (mapconcat 'number-to-string
+ (org-export-get-headline-number headline info)
+ "-")))))
(pre-blanks
(make-string (org-element-property :pre-blank headline) 10)))
(if (or (not section-fmt) (org-export-low-level-p headline info))
@@ -1846,11 +1849,15 @@ INFO is a plist holding contextual information. See
;; title.
(headline
(let ((label
- (format "sec-%s"
- (mapconcat
- 'number-to-string
- (org-export-get-headline-number destination info)
- "-"))))
+ (or
+ ;; Case 1: headline has a CUSTOM_ID property; use that as label
+ (org-element-property :CUSTOM_ID destination)
+ ;; Case 2: headline has no CUSTOM_ID; use default numbering
+ (format "sec-%s"
+ (mapconcat
+ 'number-to-string
+ (org-export-get-headline-number destination info)
+ "-")))))
(if (and (plist-get info :section-numbers) (not desc))
(format "\\ref{%s}" label)
(format "\\hyperref[%s]{%s}" label
--
1.7.10.4
[-- Attachment #2: Type: text/plain, Size: 1940 bytes --]
Hi Orgsters,
Here is a patch to add support for using CUSTOM_ID properties for labels
and refs in the LaTeX exporter.
The patch uses the value of CUSTOM_ID when exporting a headline for the
associated \label, and when exporting a link for the associated \ref
command (or whatever).
For example, from this Org file:
===============================================================================
* Headline 1
:PROPERTIES:
:CUSTOM_ID: sec:headline1
:END:
Links to headlines which have no CUSTOM_ID still work normally, like
this one: [[Headline 2]].
* Headline 2
Links to headlines which have a CUSTOM_ID property will use this
value to refer to them:
This link refers to Headline 1 using the builtin syntax for
CUSTOM_ID: [[#sec:headline1]].
This one uses the fuzzy search on the headline text: [[Headline 1]].
===============================================================================
the relevant section is now exported as:
===============================================================================
\section{Headline 1}
\label{sec:headline1}
Links to headlines which have no CUSTOM\(_{\text{ID}}\) still work normally, like
this one: \ref{sec-2}.
\section{Headline 2}
\label{sec-2}
Links to headlines which have a CUSTOM\(_{\text{ID}}\) property will use this
value to refer to them:
This link refers to Headline 1 using the builtin syntax for
CUSTOM\(_{\text{ID}}\): \ref{sec:headline1}.
This one uses the fuzzy search on the headline text: \ref{sec:headline1}.
===============================================================================
Previously, the label for Headline 1 would have been \label{sec-1}, and
the links under Headline 2 would have been exported as \ref{sec-1}.
This addresses an issue that was raised here, but got no response:
http://thread.gmane.org/gmane.emacs.orgmode/54039
I also need this behavior, which is why I wrote this.
Hope that's helpful!
Best,
Richard
next reply other threads:[~2014-02-15 20:21 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-15 20:19 Richard Lawrence [this message]
2014-02-15 22:44 ` [patch] Support CUSTOM_ID property in latex export Nicolas Goaziou
2014-02-15 23:43 ` Richard Lawrence
2014-02-16 9:10 ` Nicolas Goaziou
2014-02-16 20:10 ` Richard Lawrence
2014-02-18 21:56 ` Nicolas Goaziou
2014-02-18 22:35 ` Richard Lawrence
2014-02-19 12:43 ` Nicolas Goaziou
2014-02-20 5:04 ` Richard Lawrence
2014-02-21 19:35 ` Richard Lawrence
2014-02-22 9:24 ` Nicolas Goaziou
2014-02-22 20:35 ` Richard Lawrence
2014-02-22 22:31 ` Nicolas Goaziou
2014-02-23 0:37 ` Richard Lawrence
2014-02-23 8:37 ` Nicolas Goaziou
2014-02-23 8:53 ` Achim Gratz
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=87y51cgmc5.fsf@aquinas.i-did-not-set--mail-host-address--so-tickle-me \
--to=richard.lawrence@berkeley.edu \
--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).