[Top][All Lists]

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

Re: [O] Changed behaviours of LaTeX exporter in version 8.0+

From: Richard Lawrence
Subject: Re: [O] Changed behaviours of LaTeX exporter in version 8.0+
Date: Thu, 18 Sep 2014 09:10:15 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

Hi Joseph,

"Kyeong Soo (Joseph) Kim" <address@hidden> writes:

> Sorry for asking another question; this time it is for the
> cross-referencing in LaTeX export, which existed before (e.g., Sec. 16 of
> manual for <8.0) but is gone now.
> ...
> Now with 8.2.7c and the following org internal link to a section
> ... described in Sec. [[*SectionOne][SectionOne]] ...
> LaTeX export generates the following code:
> ... described in Sec. \texttt{SectionOne}, ...

I think the problem here is that you don't have a link type, and the new
LaTeX exporter doesn't convert links it doesn't understand into

I use a series of custom link types to make references to document
parts in my dissertation.  Here's the code I use; you will probably want
to adapt it to your use case:

#+BEGIN_SRC elisp
;; use CUSTOM_ID properties to generate labels
(setq org-latex-custom-id-as-label t)

(defun org-find-headline-by-custom-id (prefix path)
  "Find a headline in the current buffer by CUSTOM_ID value PREFIX:PATH."
    (goto-char (point-min))
      ; borrowed from org.el; there doesn't seem to be a function that searches
      ; for a headline with a specific property value
       (concat "^[ \t]*:CUSTOM_ID:[ \t]+" prefix ":" path "[ \t]*$") nil t)
      (setq pos (match-beginning 0))))
   (if pos
         (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:
    (when (member format '(latex linguistics))
      (format "%s~\\ref{%s:%s}" desc prefix path)))

; Parts:
 (lambda (path)
   (org-find-headline-by-custom-id "part" path))
 (lambda (path desc format)
   (org-export-dissertation-link "part" path (or desc "Part") format)))

; Chapters:
 (lambda (path)
   (org-find-headline-by-custom-id "chap" path))
 (lambda (path desc format)
   (org-export-dissertation-link "chap" path (or desc "Chapter") format)))

; Sections:
 (lambda (path)
   (org-find-headline-by-custom-id "sec" path))
 (lambda (path desc format)
   (org-export-dissertation-link "sec" path (or desc "Section") format)))

; Tables:
 (lambda (path) (org-link-search (concat "tab:" path)))
 (lambda (path desc format)
   (org-export-dissertation-link "tab" path (or desc "Table") format)))


So a link like "[[sec:foo]]" renders as "Section~\ref{sec:foo}",
"[[chap:foo]]" renders as "Chapter~\ref{chap:foo}", etc. when exported
to LateX, and you can follow links to jump to the appropriate document

Note that this works by giving my document sections fixed labels by
setting the CUSTOM_ID property.  I give headlines a descriptive name in
this property, using the LaTeX convention of prefixing "sec:", etc. to
keep my labels straight; Org then generates \label commands for document
parts using the CUSTOM_ID property.  This requires setting
org-latex-custom-id-as-label.  For example, a headline like

*** Another interesting section
    :CUSTOM_ID: sec:interesting

is exported as

\section{Another interesting section}

(The prefixes are important, since they function both as link types and
as parts of label/ref keys.  As you'll notice, the
org-export-dissertation-link function adds them back in to the key.)

I find this setup keeps things working well across revisions,
re-ordering and re-naming of sections, etc.

Hope that helps!


reply via email to

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