emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ox-latex.el --- CUSTOM_ID-as-section-label-in-latex-export
@ 2013-06-24 16:26 Eric Schulte
  2013-06-24 16:48 ` Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Schulte @ 2013-06-24 16:26 UTC (permalink / raw)
  To: Org Mode Mailing List

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: 0001-CUSTOM_ID-as-section-label-in-latex-export.patch --]
[-- Type: text/x-patch, Size: 1694 bytes --]

From c087e84a8fd80b277bf064eb31f1b893c25f1b4a Mon Sep 17 00:00:00 2001
From: Eric Schulte <schulte.eric@gmail.com>
Date: Mon, 24 Jun 2013 10:25:03 -0600
Subject: [PATCH] CUSTOM_ID as section label in latex export

  When exporting to HTML, custom ids of headlines become references to
  the resulting section in the exported document.  This is both more
  stable and more readable than using section numbers.  This commit adds
  this option to the latex exporter.

* lisp/ox-latex.el (org-latex-headline): If headlines have the CUSTOM_ID
  property set, then this value is used as the label instead of the
  section number.
---
 lisp/ox-latex.el | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index f2c6261..68b43e1 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1399,10 +1399,15 @@ holding contextual information."
 			       todo todo-type priority text tags))
 	   ;; Associate \label to the headline for internal links.
 	   (headline-label
-	    (format "\\label{sec-%s}\n"
-		    (mapconcat 'number-to-string
-			       (org-export-get-headline-number headline info)
-			       "-")))
+	    ;; Optionally use the custom-id instead of section number
+	    (if (org-element-property :CUSTOM_ID headline)
+		(format "\\label{%s}\n"
+			(org-element-property :CUSTOM_ID headline))
+	      (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))
-- 
1.8.3.1


[-- Attachment #2: Type: text/plain, Size: 46 bytes --]


-- 
Eric Schulte
http://cs.unm.edu/~eschulte

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ox-latex.el --- CUSTOM_ID-as-section-label-in-latex-export
  2013-06-24 16:26 [PATCH] ox-latex.el --- CUSTOM_ID-as-section-label-in-latex-export Eric Schulte
@ 2013-06-24 16:48 ` Nicolas Goaziou
  2013-06-24 17:08   ` Eric Schulte
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2013-06-24 16:48 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Org Mode Mailing List

Hello,

Eric Schulte <schulte.eric@gmail.com> writes:

> From c087e84a8fd80b277bf064eb31f1b893c25f1b4a Mon Sep 17 00:00:00 2001
> From: Eric Schulte <schulte.eric@gmail.com>
> Date: Mon, 24 Jun 2013 10:25:03 -0600
> Subject: [PATCH] CUSTOM_ID as section label in latex export
>
>   When exporting to HTML, custom ids of headlines become references to
>   the resulting section in the exported document.  This is both more
>   stable and more readable than using section numbers.  This commit adds
>   this option to the latex exporter.

Thanks for the patch.

Though, it isn't as stable as relying on section numbers: there is no
guarantee the custom id will be unique nor that it will not contain any
forbidden character.

This patch also breaks cross references, which expects labels to be
built from section number (see `org-latex-link').

Since you (almost?) never need to write \ref{custom-id} in the Org
buffer, I don't think it is bad to keep current label system.

Another option would be to have both \label{sec-...} and
\label{custom-id}. But it would require the user to check validity of
its id.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ox-latex.el --- CUSTOM_ID-as-section-label-in-latex-export
  2013-06-24 16:48 ` Nicolas Goaziou
@ 2013-06-24 17:08   ` Eric Schulte
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Schulte @ 2013-06-24 17:08 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Org Mode Mailing List

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> Hello,
>
> Eric Schulte <schulte.eric@gmail.com> writes:
>
>> From c087e84a8fd80b277bf064eb31f1b893c25f1b4a Mon Sep 17 00:00:00 2001
>> From: Eric Schulte <schulte.eric@gmail.com>
>> Date: Mon, 24 Jun 2013 10:25:03 -0600
>> Subject: [PATCH] CUSTOM_ID as section label in latex export
>>
>>   When exporting to HTML, custom ids of headlines become references to
>>   the resulting section in the exported document.  This is both more
>>   stable and more readable than using section numbers.  This commit adds
>>   this option to the latex exporter.
>
> Thanks for the patch.
>
> Though, it isn't as stable as relying on section numbers: there is no
> guarantee the custom id will be unique nor that it will not contain any
> forbidden character.
>
> This patch also breaks cross references, which expects labels to be
> built from section number (see `org-latex-link').
>

Oh, I see now that I can simply use [[#id]] links and they will be
translated as appropriate.  This will then also resolve these references
if I export the paper to HTML.

Thanks for the explanation,

>
> Since you (almost?) never need to write \ref{custom-id} in the Org
> buffer, I don't think it is bad to keep current label system.
>
> Another option would be to have both \label{sec-...} and
> \label{custom-id}. But it would require the user to check validity of
> its id.
>
>
> Regards,

-- 
Eric Schulte
http://cs.unm.edu/~eschulte

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-06-24 17:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-24 16:26 [PATCH] ox-latex.el --- CUSTOM_ID-as-section-label-in-latex-export Eric Schulte
2013-06-24 16:48 ` Nicolas Goaziou
2013-06-24 17:08   ` Eric Schulte

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).