* [PATCH 0/2] References auto-generated labels with \ref in LaTeX export
@ 2011-01-20 13:23 Lawrence Mitchell
2011-01-20 13:23 ` [PATCH 1/2] Only match complete words in org-export-add-options-to-plist Lawrence Mitchell
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Lawrence Mitchell @ 2011-01-20 13:23 UTC (permalink / raw)
To: emacs-orgmode; +Cc: Lawrence Mitchell
when writing latex, I prefer referring to previous sections by
saying "As we saw earlier in section \ref{some-section}". When
writing with Org and then exporting to latex, there doesn't
appear to be any way to reproduce this. Using "As we saw earlier
in section [[section header]]" produces a hyperref, rather than a
plain ref.
This patch set introduces a new option
`org-latex-unprettify-internal-links' which, if non-nil, converts
"bare" references to auto-generated section labels into a \ref
rather than a \hyperref.
The first patch fixes up treatment of the options plist, so that
options that are the suffix of another option do not
inadvertantly match both. This should probably be applied either
way, since the current behaviour seems like a bug.
The second patch introduces the new functionality and attempts to
document it in the most obvious place I could find in the manual.
Cheers,
Lawrence
Lawrence Mitchell (2):
Only match complete words in org-export-add-options-to-plist
Allow option of using bare \ref links in LaTeX export
doc/org.texi | 37 +++++++++++++++++++++++++++++++++++++
lisp/org-exp.el | 6 ++++--
lisp/org-latex.el | 25 +++++++++++++++++++++----
3 files changed, 62 insertions(+), 6 deletions(-)
--
1.7.4.rc1.7.g2cf08
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] Only match complete words in org-export-add-options-to-plist
2011-01-20 13:23 [PATCH 0/2] References auto-generated labels with \ref in LaTeX export Lawrence Mitchell
@ 2011-01-20 13:23 ` Lawrence Mitchell
2011-02-12 23:49 ` [Accepted] [Orgmode, " Bastien Guerry
2011-01-20 13:23 ` [PATCH 2/2] Allow option of using bare \ref links in LaTeX export Lawrence Mitchell
2011-02-12 23:46 ` [PATCH 0/2] References auto-generated labels with \ref " Bastien
2 siblings, 1 reply; 5+ messages in thread
From: Lawrence Mitchell @ 2011-01-20 13:23 UTC (permalink / raw)
To: emacs-orgmode; +Cc: Lawrence Mitchell
* org-exp.el (org-export-add-options-to-plist): Require match to start
at a word-boundary.
Previously, if an option was the suffix of another option (such as TeX
and LaTeX) the setting for the former would propagator to the latter.
This seems like an unintended consequence of a lax regexp in
org-export-add-options-to-plist. This patch allows options to share a
suffix with another option by requiring that the match against an
option starts at a word-boundary.
---
lisp/org-exp.el | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index 9954227..d099c82 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -824,7 +824,7 @@ security risks."
(let ((op org-export-plist-vars))
(while (setq o (pop op))
(if (and (nth 1 o)
- (string-match (concat (regexp-quote (nth 1 o))
+ (string-match (concat "\\<" (regexp-quote (nth 1 o))
":\\([^ \t\n\r;,.]*\\)")
options))
(setq p (plist-put p (car o)
--
1.7.4.rc1.7.g2cf08
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] Allow option of using bare \ref links in LaTeX export
2011-01-20 13:23 [PATCH 0/2] References auto-generated labels with \ref in LaTeX export Lawrence Mitchell
2011-01-20 13:23 ` [PATCH 1/2] Only match complete words in org-export-add-options-to-plist Lawrence Mitchell
@ 2011-01-20 13:23 ` Lawrence Mitchell
2011-02-12 23:46 ` [PATCH 0/2] References auto-generated labels with \ref " Bastien
2 siblings, 0 replies; 5+ messages in thread
From: Lawrence Mitchell @ 2011-01-20 13:23 UTC (permalink / raw)
To: emacs-orgmode; +Cc: Lawrence Mitchell
* 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
+@cindex 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: \usepackage@{xyz@}} 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
+@samp{\hyperref} 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
+
+@cindex org-export-latex-unprettify-internal-links
+@cindex section labels, for LaTeX
+@example
+* A header
+Here is some text referring to [[A header]]
+@end example
+
+When @code{org-export-latex-unprettify-internal-links} is @code{nil} (the
+default), this is exported as
+
+@example
+\section@{A header@}
+\label@{sec-1@}
+
+Here is some text referring to \hyperref[sec-1]@{A header@}
+@end example
+
+When @code{org-export-latex-unprettify-internal-links} is @code{t}, the
+export is
+@example
+\section@{A header@}
+\label@{sec-1@}
+
+Here is some text referring to \ref@{sec-1@}
+@end 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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] References auto-generated labels with \ref in LaTeX export
2011-01-20 13:23 [PATCH 0/2] References auto-generated labels with \ref in LaTeX export Lawrence Mitchell
2011-01-20 13:23 ` [PATCH 1/2] Only match complete words in org-export-add-options-to-plist Lawrence Mitchell
2011-01-20 13:23 ` [PATCH 2/2] Allow option of using bare \ref links in LaTeX export Lawrence Mitchell
@ 2011-02-12 23:46 ` Bastien
2 siblings, 0 replies; 5+ messages in thread
From: Bastien @ 2011-02-12 23:46 UTC (permalink / raw)
To: Lawrence Mitchell; +Cc: emacs-orgmode
Hi Lawrence,
Lawrence Mitchell <wence@gmx.li> writes:
> This patch set introduces a new option
> `org-latex-unprettify-internal-links' which, if non-nil, converts
> "bare" references to auto-generated section labels into a \ref
> rather than a \hyperref.
Thanks for the patch and the explanations.
What about using org-export-latex-hyperref-format directly?
(setq org-export-latex-hyperref-format "\\ref{%s}")
and you're set. I updated the docstring to make clear there is no real
problem in having less than two "%s" in here -- the format function will
just ignore the second one.
Best,
--
Bastien
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Accepted] [Orgmode, 1/2] Only match complete words in org-export-add-options-to-plist
2011-01-20 13:23 ` [PATCH 1/2] Only match complete words in org-export-add-options-to-plist Lawrence Mitchell
@ 2011-02-12 23:49 ` Bastien Guerry
0 siblings, 0 replies; 5+ messages in thread
From: Bastien Guerry @ 2011-02-12 23:49 UTC (permalink / raw)
To: emacs-orgmode
Patch 551 (http://patchwork.newartisans.com/patch/551/) is now "Accepted".
Maintainer comment: none
This relates to the following submission:
http://mid.gmane.org/%3C1c07dac7fa0dd036dec6a1147fde83c5cddf8639.1295529378.git.wence%40gmx.li%3E
Here is the original message containing the patch:
> Content-Type: text/plain; charset="utf-8"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Subject: [Orgmode,
> 1/2] Only match complete words in org-export-add-options-to-plist
> Date: Thu, 20 Jan 2011 18:23:22 -0000
> From: Lawrence Mitchell <wence@gmx.li>
> X-Patchwork-Id: 551
> Message-Id: <1c07dac7fa0dd036dec6a1147fde83c5cddf8639.1295529378.git.wence@gmx.li>
> To: emacs-orgmode@gnu.org
> Cc: Lawrence Mitchell <wence@gmx.li>
>
> * org-exp.el (org-export-add-options-to-plist): Require match to start
> at a word-boundary.
>
> Previously, if an option was the suffix of another option (such as TeX
> and LaTeX) the setting for the former would propagator to the latter.
> This seems like an unintended consequence of a lax regexp in
> org-export-add-options-to-plist. This patch allows options to share a
> suffix with another option by requiring that the match against an
> option starts at a word-boundary.
>
> ---
> lisp/org-exp.el | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/lisp/org-exp.el b/lisp/org-exp.el
> index 9954227..d099c82 100644
> --- a/lisp/org-exp.el
> +++ b/lisp/org-exp.el
> @@ -824,7 +824,7 @@ security risks."
> (let ((op org-export-plist-vars))
> (while (setq o (pop op))
> (if (and (nth 1 o)
> - (string-match (concat (regexp-quote (nth 1 o))
> + (string-match (concat "\\<" (regexp-quote (nth 1 o))
> ":\\([^ \t\n\r;,.]*\\)")
> options))
> (setq p (plist-put p (car o)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-02-12 23:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-20 13:23 [PATCH 0/2] References auto-generated labels with \ref in LaTeX export Lawrence Mitchell
2011-01-20 13:23 ` [PATCH 1/2] Only match complete words in org-export-add-options-to-plist Lawrence Mitchell
2011-02-12 23:49 ` [Accepted] [Orgmode, " Bastien Guerry
2011-01-20 13:23 ` [PATCH 2/2] Allow option of using bare \ref links in LaTeX export Lawrence Mitchell
2011-02-12 23:46 ` [PATCH 0/2] References auto-generated labels with \ref " Bastien
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).