From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard Lawrence Subject: [patch] Support CUSTOM_ID property in latex export Date: Sat, 15 Feb 2014 12:19:54 -0800 Message-ID: <87y51cgmc5.fsf@aquinas.i-did-not-set--mail-host-address--so-tickle-me> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38047) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WElk9-00006L-VU for emacs-orgmode@gnu.org; Sat, 15 Feb 2014 15:21:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WElk4-0007z2-Si for emacs-orgmode@gnu.org; Sat, 15 Feb 2014 15:21:45 -0500 Received: from mail-pb0-f54.google.com ([209.85.160.54]:41528) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WElk4-0007yu-J6 for emacs-orgmode@gnu.org; Sat, 15 Feb 2014 15:21:40 -0500 Received: by mail-pb0-f54.google.com with SMTP id uo5so13857747pbc.27 for ; Sat, 15 Feb 2014 12:21:38 -0800 (PST) Received: from aquinas (c-67-164-45-159.hsd1.ca.comcast.net. [67.164.45.159]) by mx.google.com with ESMTPSA id yz5sm74391144pac.9.2014.02.15.12.21.36 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 15 Feb 2014 12:21:37 -0800 (PST) Received: from rwl by aquinas with local (Exim 4.80) (envelope-from ) id 1WEliM-0007Zq-UN for emacs-orgmode@gnu.org; Sat, 15 Feb 2014 12:19:54 -0800 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-LaTeX-export-support-CUSTOM_ID-property-in-section-l.patch Content-Description: Patch to support CUSTOM_ID property in latex export >From 81115d0884c165778520aa1b4d4fa83580417e1c Mon Sep 17 00:00:00 2001 From: Richard Lawrence 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 --=-=-= 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 --=-=-=--