From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: LaTeX export with section number, name and page in internal links Date: Tue, 08 Dec 2015 15:29:46 -0500 Message-ID: References: <87mvtkubrm.fsf@berkeley.edu> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56487) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a6OtW-0004Ax-U6 for emacs-orgmode@gnu.org; Tue, 08 Dec 2015 15:29:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a6OtS-0007Rw-U1 for emacs-orgmode@gnu.org; Tue, 08 Dec 2015 15:29:54 -0500 Received: from mail-qg0-x22a.google.com ([2607:f8b0:400d:c04::22a]:33652) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a6OtS-0007Rj-Q6 for emacs-orgmode@gnu.org; Tue, 08 Dec 2015 15:29:50 -0500 Received: by qgea14 with SMTP id a14so35598698qge.0 for ; Tue, 08 Dec 2015 12:29:50 -0800 (PST) In-reply-to: <87mvtkubrm.fsf@berkeley.edu> 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: Richard Lawrence Cc: Ilya , emacs-orgmode@gnu.org > I do something like this with custom link types. Aha! I am not the only one ;) > > First of all, have a look at the variable > > org-latex-prefer-user-labels Is this a new 8.3 variable? It doesn't seem to be in my 8.2.10 MELPA version. > > 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 I like your idea. I think you could simplify it to just: (org-add-link-type "sec" (lambda (path) (org-open-link-from-string (format "[[#%s]]" path))) (lambda (path desc format) (cond ((eq format 'latex) (format "%s~\\ref{%s}" (or desc "Section") path))))) and refer to [[sec:section-1]] that looks like this below. ** some title :PROPERTIES: :CUSTOM_ID: section-1 :END: > > #+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.) -- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu