From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard Lawrence Subject: Re: [patch] Support CUSTOM_ID property in latex export Date: Fri, 21 Feb 2014 11:35:24 -0800 Message-ID: <87ob20gsxv.fsf@aquinas.i-did-not-set--mail-host-address--so-tickle-me> References: <87y51cgmc5.fsf@aquinas.i-did-not-set--mail-host-address--so-tickle-me> <87mwhsro6c.fsf@gmail.com> <87vbwggcwb.fsf@berkeley.edu> <87iosfs9sb.fsf@gmail.com> <871tz24y4q.fsf@aquinas.i-did-not-set--mail-host-address--so-tickle-me> <87lhx82igv.fsf@gmail.com> <87mwho9hij.fsf@aquinas.i-did-not-set--mail-host-address--so-tickle-me> <87d2ij2ryp.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47284) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGvuO-00053U-FT for emacs-orgmode@gnu.org; Fri, 21 Feb 2014 14:37:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WGvuI-00014r-SB for emacs-orgmode@gnu.org; Fri, 21 Feb 2014 14:37:16 -0500 Received: from mail-pd0-f178.google.com ([209.85.192.178]:60005) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WGvuI-00014g-J2 for emacs-orgmode@gnu.org; Fri, 21 Feb 2014 14:37:10 -0500 Received: by mail-pd0-f178.google.com with SMTP id fp1so3689302pdb.23 for ; Fri, 21 Feb 2014 11:37:08 -0800 (PST) In-Reply-To: <87d2ij2ryp.fsf@gmail.com> 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: Nicolas Goaziou Cc: emacs-orgmode@gnu.org --=-=-= Hi Nicolas and all, Here's a new patch that adds a variable org-latex-custom-id-as-label to control whether CUSTOM_ID should be used to generate labels during LaTeX export. Let me know what you think. In particular, I wasn't sure if I should provide more information in the defcustom statement beyond :group and :type (like :package-version?). Also, does the docstring represent the trade-offs of using this variable well enough? I wasn't sure how to get git format-patch to generate a single patch for the changes between my branch and master (since there are now two commits on my branch), so this was generated with git diff --patch. If you want me to send the commit message, etc. can you let me know how to do this in whatever way is most convenient for you? --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=custom-id.patch diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 5815874..df22768 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -375,6 +375,47 @@ which format headlines like for Org version prior to 8.0." :package-version '(Org . "8.0") :type 'function) +(defcustom org-latex-custom-id-as-label nil + "Toggle use of CUSTOM_ID properties for generating section labels. + +If non-nil, Org will use the value of a headline's CUSTOM_ID +property as the argument to the \label command for the LaTeX +section corresponding to the headline. + +Setting this variable gives you control over how Org generates +labels for sections during LaTeX export. One reason to do this +is that it allows you to refer to headlines using a single label +both in Org's link syntax and in embedded LaTeX code. + +For example, when this variable is non-nil, a headline like this: + + ** Some section + :PROPERTIES: + :CUSTOM_ID: sec:foo + :END: + This is section [[#sec:foo]]. + #+BEGIN_LATEX + And this is still section \ref{sec:foo}. + #+END_LATEX + +will be exported to LaTeX as: + + \subsection{Some section} + \label{sec:foo} + This is section \ref{sec:foo}. + And this is still section \ref{sec:foo}. + +Note, however, that when a headline defines a value for +CUSTOM_ID, Org simply passes this value to \label unchanged. You +are responsible for ensuring that the value is a valid LaTeX +\label key, that it is unique throughout the generated document, +etc. + +For headlines that do not define the CUSTOM_ID property, Org will +continue to use its default labeling scheme to generate labels +and resolve links into section references." + :group 'org-export-latex + :type 'boolean) ;;;; Footnotes @@ -1373,10 +1414,14 @@ 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) - "-"))) + (let ((custom-label (and org-latex-custom-id-as-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)) @@ -1845,12 +1890,16 @@ INFO is a plist holding contextual information. See ;; number. Otherwise, display description or headline's ;; title. (headline - (let ((label - (format "sec-%s" - (mapconcat - 'number-to-string - (org-export-get-headline-number destination info) - "-")))) + (let* ((custom-label (and org-latex-custom-id-as-label + (org-element-property :CUSTOM_ID destination))) + (label + (or + custom-label + (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 --=-=-= Best, Richard (If possible, please encrypt your reply to me using my PGP key: Key ID: CF6FA646 Fingerprint: 9969 43E1 CF6F A646. See http://www.ocf.berkeley.edu/~rwl/encryption.html for more information.) --=-=-=--