emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Richard Lawrence <richard.lawrence@berkeley.edu>
To: emacs-orgmode@gnu.org
Cc: "Kyeong Soo (Joseph) Kim" <kyeongsoo.kim@gmail.com>
Subject: Re: Changed behaviours of LaTeX exporter in version 8.0+
Date: Thu, 18 Sep 2014 09:10:15 -0700	[thread overview]
Message-ID: <87lhpg3o60.fsf@berkeley.edu> (raw)
In-Reply-To: CACsgZ=qx3LjfefuMRYo=CeGu=XvEfnyMVdHwZ68rAv+QMxm0ng@mail.gmail.com

Hi Joseph,

"Kyeong Soo (Joseph) Kim" <kyeongsoo.kim@gmail.com> 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
references.

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."
  (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)))

; Parts:
(org-add-link-type
 "part"
 (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:
(org-add-link-type
 "chap"
 (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:
(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)))

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

#+END_SRC

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
headline.

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
    :PROPERTIES:
    :CUSTOM_ID: sec:interesting
    :END:

is exported as

\section{Another interesting section}
\label{sec:interesting}

(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!

Best,
Richard

  reply	other threads:[~2014-09-18 16:15 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-18  4:50 Changed behaviours of LaTeX exporter in version 8.0+ Kyeong Soo (Joseph) Kim
2014-09-18  7:07 ` Kyeong Soo (Joseph) Kim
2014-09-18  7:32   ` Kyeong Soo (Joseph) Kim
2014-09-18 16:10     ` Richard Lawrence [this message]
     [not found]       ` <CACsgZ=r1vzPQg1KB3N7j6Mn+nyu=PUrxJCeRr5ebqmpywsQ0bg@mail.gmail.com>
2014-09-19 15:49         ` Richard Lawrence
2014-09-20 15:32           ` Kyeong Soo (Joseph) Kim
2014-09-22 16:00             ` Nicolas Goaziou
2014-09-23  3:03               ` Kyeong Soo (Joseph) Kim
2014-09-27 22:01                 ` Nicolas Goaziou
2014-09-29  4:51                   ` Kyeong Soo (Joseph) Kim
2014-09-29  7:07                     ` Nicolas Goaziou
2014-09-29  7:57                       ` Kyeong Soo (Joseph) Kim
2014-09-29  8:53                         ` Rasmus
2014-09-29  9:59                           ` Kyeong Soo (Joseph) Kim
2014-09-29 10:09                             ` Rasmus
2014-09-29 12:18                               ` Kyeong Soo (Joseph) Kim
2014-09-29 14:18                                 ` Rasmus
2014-09-29 14:18                                 ` Rasmus
2014-10-01  9:39                                   ` Kyeong Soo (Joseph) Kim
2014-09-18 15:47   ` Richard Lawrence
  -- strict thread matches above, loose matches on Subject: below --
2014-09-17 14:54 Kyeong Soo (Joseph) Kim
2014-09-17 19:01 ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lhpg3o60.fsf@berkeley.edu \
    --to=richard.lawrence@berkeley.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=kyeongsoo.kim@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).