From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard Lawrence Subject: Re: LaTeX export with section number, name and page in internal links Date: Tue, 08 Dec 2015 08:48:45 -0800 Message-ID: <87mvtkubrm.fsf@berkeley.edu> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49678) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a6LRD-0004LT-Ke for emacs-orgmode@gnu.org; Tue, 08 Dec 2015 11:48:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a6LR9-0007ta-FF for emacs-orgmode@gnu.org; Tue, 08 Dec 2015 11:48:27 -0500 Received: from mail-pa0-x229.google.com ([2607:f8b0:400e:c03::229]:32836) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a6LR8-0007rx-Sm for emacs-orgmode@gnu.org; Tue, 08 Dec 2015 11:48:23 -0500 Received: by pabur14 with SMTP id ur14so14624998pab.0 for ; Tue, 08 Dec 2015 08:48:21 -0800 (PST) In-Reply-To: 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: Ilya , emacs-orgmode@gnu.org Hi Ilya, Ilya 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.)