emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] LaTeX export with section number, name and page in internal link


From: Richard Lawrence
Subject: Re: [O] LaTeX export with section number, name and page in internal links
Date: Tue, 08 Dec 2015 08:48:45 -0800
User-agent: Notmuch/0.18.2 (http://notmuchmail.org) Emacs/24.4.1 (x86_64-pc-linux-gnu)

Hi Ilya,

Ilya <address@hidden> 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.)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]