emacs-orgmode
[Top][All Lists]
Advanced

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

[Orgmode] [PATCH 2/2] Allow option of using bare \ref links in LaTeX exp


From: Lawrence Mitchell
Subject: [Orgmode] [PATCH 2/2] Allow option of using bare \ref links in LaTeX export
Date: Thu, 20 Jan 2011 13:23:23 +0000

* lisp/org-latex.el (org-export-latex-unprettify-internal-links): New
variable.
(org-export-latex-links): Use it.
* org-mode/lisp/org-exp.el (org-export-plist-vars): Add
:LaTeX-bare-refs settable through the bare-ref option with default
given by `org-export-latex-unprettify-internal-links'.
(org-get-current-options): Deal with :LaTeX-bare-refs.
* org-mode/doc/org.texi (Export options, Header and sectioning):
Document `org-export-latex-unprettify-internal-links' and associated
option.

If org-export-latex-unprettify-internal-links is non-nil, then links
with an auto-generated raw-path (for example "sec-1_2_10") will be
exported to LaTeX as bare references with \ref{raw-path} rather than
textually with \hyperref[raw-path]{desc}.

This means you can write "As seen in section [[some section heading]]"
and have it exported to "As seen in section \ref{sec-number}".
---
 doc/org.texi      |   37 +++++++++++++++++++++++++++++++++++++
 lisp/org-exp.el   |    4 +++-
 lisp/org-latex.el |   25 +++++++++++++++++++++----
 3 files changed, 61 insertions(+), 5 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index d37e3a2..8ad5029 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -9348,6 +9348,7 @@ settings.  Here you can:
 @cindex emphasized text
 @cindex @TeX{} macros
 @cindex @LaTeX{} fragments
address@hidden section labels, for LaTeX
 @cindex author info, in export
 @cindex time info, in export
 @example
@@ -9370,6 +9371,7 @@ tags:      @r{turn on/off inclusion of tags, may also be 
@code{not-in-toc}}
 *:         @r{turn on/off emphasized text (bold, italic, underlined)}
 TeX:       @r{turn on/off simple @TeX{} macros in plain text}
 LaTeX:     @r{configure export of @LaTeX{} fragments.  Default @code{auto}}
+bare-ref:  @r{turn on/off bare references in @TeX{} and @LaTeX{} export}
 skip:      @r{turn on/off skipping the text before the first heading}
 author:    @r{turn on/off inclusion of author name/email into exported file}
 email:     @r{turn on/off inclusion of author email into exported file}
@@ -9969,6 +9971,41 @@ can also use @code{#+LATEX_HEADER: address@hidden@}} to 
add lines to the
 header.  See the docstring of @code{org-export-latex-classes} for more
 information.
 
+By default, internal links in an Org document are exported and linked with
address@hidden in @LaTeX{}.  If you would like bare references to headlines
+to be referred as plain references (by number with @samp{\ref}) then set the
+variable @code{org-export-latex-unprettify-internal-links} to @code{t}.  As
+an example consider the following document
+
address@hidden org-export-latex-unprettify-internal-links
address@hidden section labels, for LaTeX
address@hidden
+* A header
+Here is some text referring to [[A header]]
address@hidden example
+
+When @code{org-export-latex-unprettify-internal-links} is @code{nil} (the
+default), this is exported as
+
address@hidden
address@hidden address@hidden
address@hidden@}
+
+Here is some text referring to address@hidden address@hidden
address@hidden example
+
+When @code{org-export-latex-unprettify-internal-links} is @code{t}, the
+export is
address@hidden
address@hidden address@hidden
address@hidden@}
+
+Here is some text referring to address@hidden@}
address@hidden example
+
+This setting can also be set in the OPTIONS line through the @code{bare-ref}
+option (see @ref{Export options}).
+
 @node Quoting LaTeX code, Tables in LaTeX export, Header and sectioning, LaTeX 
and PDF export
 @subsection Quoting @LaTeX{} code
 
diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index d099c82..64b6671 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -606,6 +606,7 @@ table.el tables."
     (:priority               "pri"       org-export-with-priority)
     (:TeX-macros             "TeX"       org-export-with-TeX-macros)
     (:LaTeX-fragments        "LaTeX"     org-export-with-LaTeX-fragments)
+    (:LaTeX-bare-refs         "bare-ref"  
org-export-latex-unprettify-internal-links)
     (:latex-listings         nil         org-export-latex-listings)
     (:skip-before-1st-heading "skip"     
org-export-skip-text-before-1st-heading)
     (:fixed-width            ":"         org-export-with-fixed-width)
@@ -2789,7 +2790,7 @@ Does include HTML export options as well as TODO and 
CATEGORY stuff."
 #+KEYWORDS: 
 #+LANGUAGE:  %s
 #+OPTIONS:   H:%d num:%s toc:%s \\n:%s @:%s ::%s |:%s ^:%s -:%s f:%s *:%s <:%s
-#+OPTIONS:   TeX:%s LaTeX:%s skip:%s d:%s todo:%s pri:%s tags:%s
+#+OPTIONS:   TeX:%s LaTeX:%s bare-ref:%s skip:%s d:%s todo:%s pri:%s tags:%s
 %s
 #+EXPORT_SELECT_TAGS: %s
 #+EXPORT_EXCLUDE_TAGS: %s
@@ -2824,6 +2825,7 @@ Does include HTML export options as well as TODO and 
CATEGORY stuff."
    org-export-with-timestamps
    org-export-with-TeX-macros
    org-export-with-LaTeX-fragments
+   org-export-latex-unprettify-internal-links
    org-export-skip-text-before-1st-heading
    org-export-with-drawers
    org-export-with-todo-keywords
diff --git a/lisp/org-latex.el b/lisp/org-latex.el
index ecaf1c0..b3829da 100644
--- a/lisp/org-latex.el
+++ b/lisp/org-latex.el
@@ -309,6 +309,18 @@ the link, the second with the link description."
   :group 'org-export-latex
   :type 'string)
 
+(defcustom org-export-latex-unprettify-internal-links nil
+  "If non-nil, turn internal section links [[some heading]] into \\ref{sec}.
+
+This allows us to write \"See section [[some section]]\" and have it
+formatted as \"See section \\ref{sec-number}\" in LaTeX.  If this
+variable is nil, the references are formatted as hyperref links (see
+`org-export-latex-hyperref-format').
+
+This option can also be set with the +OPTIONS line, e.g. \"bare-ref:t\"."
+  :group 'org-export-latex
+  :type 'boolean)
+
 (defcustom org-export-latex-tables-verbatim nil
   "When non-nil, tables are exported verbatim."
   :group 'org-export-latex
@@ -2066,10 +2078,15 @@ The conversion is made depending of STRING-BEFORE and 
STRING-AFTER."
             (radiop (insert (format org-export-latex-hyperref-format
                                     (org-solidify-link-text raw-path) desc)))
             ((not type)
-             (insert (format org-export-latex-hyperref-format
-                             (org-remove-initial-hash
-                              (org-solidify-link-text raw-path))
-                             desc)))
+             (if (and (plist-get org-export-latex-options-plist 
:LaTeX-bare-refs)
+                      ;; this is an auto-generated raw-path
+                      (string-match "\\`sec-[0-9]+\\(?:_[0-9]+\\)*\\'"
+                                    raw-path))
+                 (insert (format "\\ref{%s}" raw-path))
+               (insert (format org-export-latex-hyperref-format
+                               (org-remove-initial-hash
+                                (org-solidify-link-text raw-path))
+                               desc))))
             (path
              (when (org-at-table-p)
                ;; There is a strange problem when we have a link in a table,
-- 
1.7.4.rc1.7.g2cf08




reply via email to

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