emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Re: [PATCH] Internal Links with Spaces
@ 2015-03-11 13:34 Jacob Gerlach
  2015-03-11 13:41 ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Jacob Gerlach @ 2015-03-11 13:34 UTC (permalink / raw)
  To: Org-mode

[-- Attachment #1: Type: text/plain, Size: 771 bytes --]

On Tue, Mar 10, 2015 at 3:47 PM, Jacob Gerlach <jacobgerlach@gmail.com> wrote:
> After finally getting this function to work, I discovered that I had
> the same problem as when I used org-id: the link description causes
> exported latex references to use the headline text instead of the
> \label{}.
...
> This works for me, but I'd love to find a more elegant approach:

I had been waffling on whether to switch to the git version of org.
This was motivation to make the switch, so I decided to give a shot at
patching this.

Attached patch introduces `org-latex-prefer-section-references'. If
non-nil, links will use the generated \label even if the link has a
description.

I believe I did everything right - commit message, no failures on make test...

Regards,
Jake

[-- Attachment #2: 0001-ox-latex.el-Customize-link-export-behavior.patch --]
[-- Type: text/x-patch, Size: 1984 bytes --]

From 50829ce7891bd9cd5c654da346ae1981fe6339f7 Mon Sep 17 00:00:00 2001
From: Jacob Gerlach <jacobgerlach@gmail.com>
Date: Wed, 11 Mar 2015 09:15:46 -0400
Subject: [PATCH] ox-latex.el: Customize link export behavior

* lisp/ox-latex.el (org-latex-prefer-section-references): Add new
  defcustom.
  (org-latex-link): Use customization when resolving links to
  headlines.

  TINYCHANGE
---
 lisp/ox-latex.el | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 6cec8a1..e1b2647 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -510,6 +510,17 @@ and resolve links into section references."
   :version "25.1"
   :package-version '(Org . "8.3"))
 
+(defcustom org-latex-prefer-section-references nil
+   "Toggle use of link descriptions for generating section labels.
+
+When this variable is non-nil, Org will resolve links into
+section references even when the link has a description."
+
+  :group 'org-export-latex
+  :version "25.1"
+  :package-version '(Org . "8.3")
+  :type 'boolean)
+
 ;;;; Footnotes
 
 (defcustom org-latex-footnote-separator "\\textsuperscript{,}\\,"
@@ -2075,14 +2086,15 @@ INFO is a plist holding contextual information.  See
 	  ;; LINK points to a headline.  If headlines are numbered
 	  ;; and the link has no description, display headline's
 	  ;; number.  Otherwise, display description or headline's
-	  ;; title.
+	  ;; title depending on the value of 
+	  ;; org-latex-prefer-section-references
 	  (headline
 	   (let* ((custom-label
 		   (and (plist-get info :latex-custom-id-labels)
 			(org-element-property :CUSTOM_ID destination)))
 		  (label (or custom-label
 			     (org-export-get-headline-id destination info))))
-	     (if (and (not desc)
+	     (if (and (or (not desc) org-latex-prefer-section-references)
 		      (org-export-numbered-headline-p destination info))
 		 (format "\\ref{%s}" label)
 	       (format "\\hyperref[%s]{%s}" label
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] Internal Links with Spaces
  2015-03-11 13:34 Jacob Gerlach
@ 2015-03-11 13:41 ` Nicolas Goaziou
  0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2015-03-11 13:41 UTC (permalink / raw)
  To: Jacob Gerlach; +Cc: Org-mode

Hello,

Jacob Gerlach <jacobgerlach@gmail.com> writes:

> I had been waffling on whether to switch to the git version of org.
> This was motivation to make the switch, so I decided to give a shot at
> patching this.
>
> Attached patch introduces `org-latex-prefer-section-references'. If
> non-nil, links will use the generated \label even if the link has a
> description.

I'm not sure to understand the problem you're trying to solve. Would you
mind giving a simple example and motivation?


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Internal Links with Spaces
@ 2015-03-11 13:58 Jacob Gerlach
  2015-03-11 14:17 ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Jacob Gerlach @ 2015-03-11 13:58 UTC (permalink / raw)
  To: Org-mode

Hi,

On Wed, Mar 11, 2015 at 9:41 AM, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
> I'm not sure to understand the problem you're trying to solve. Would you
> mind giving a simple example and motivation?
(Did I break the thread by adding "[PATCH]" to the subject? Apologies
if so, original thread was [1])

The motivation is to allow generating standard "see section
\ref{some-label}" references using org-store/insert-link.

In more detail (repeating/summarizing the prior messages on original thread):

Internal Links stored with org-store-link and inserted with
org-insert-link fail on export for headlines with spaces because of %
encoding the spaces. (This is orthogonal to the patch, just the
original motivation that led to it).

One solution is to use org-id. I also came up with a hack to unhex the
link after it is inserted.

In either case, the links inserted have descriptions. Links with
descriptions always export as hyperref's using the headline text
(instead of regular \ref's using the label).

There is no (?) way to force links with descriptions to export using
regular latex \ref{}'s. John Kitchin offered two workarounds (using a
custom id for every headline or manually \label'ing the headlines and
\ref'ing them instead of using org links).

Regards,
Jake

[1] https://lists.gnu.org/archive/html/emacs-orgmode/2015-03/msg00348.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Internal Links with Spaces
  2015-03-11 13:58 [PATCH] Internal Links with Spaces Jacob Gerlach
@ 2015-03-11 14:17 ` Nicolas Goaziou
  2015-03-11 14:36   ` Jacob Gerlach
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2015-03-11 14:17 UTC (permalink / raw)
  To: Jacob Gerlach; +Cc: Org-mode

Jacob Gerlach <jacobgerlach@gmail.com> writes:

> (Did I break the thread by adding "[PATCH]" to the subject? Apologies
> if so, original thread was [1])

I read the thread before asking the question.

> In more detail (repeating/summarizing the prior messages on original thread):
>
> Internal Links stored with org-store-link and inserted with
> org-insert-link fail on export for headlines with spaces because of %
> encoding the spaces. (This is orthogonal to the patch, just the
> original motivation that led to it).
>
> One solution is to use org-id. I also came up with a hack to unhex the
> link after it is inserted.
>
> In either case, the links inserted have descriptions.

This is where I don't follow you. You can insert links without
description, using `org-insert-link'. What makes you think you cannot?

> Links with descriptions always export as hyperref's using the headline
> text (instead of regular \ref's using the label).

That's intended, indeed. If you added a description to a link, Org
should use it.


Regards,

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Internal Links with Spaces
  2015-03-11 14:17 ` Nicolas Goaziou
@ 2015-03-11 14:36   ` Jacob Gerlach
  2015-03-11 14:52     ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Jacob Gerlach @ 2015-03-11 14:36 UTC (permalink / raw)
  To: Jacob Gerlach, Org-mode

On Wed, Mar 11, 2015 at 10:17 AM, Nicolas Goaziou
<mail@nicolasgoaziou.fr> wrote:
> This is where I don't follow you. You can insert links without
> description, using `org-insert-link'. What makes you think you cannot?

I thought that I had tested `(org-insert-link nil nil "")' and found
that a description (repeating the headline text) was still inserted,
but I just tried again and it does in fact insert a link with no
description. (In the meantime I switched from ELPA to git, so perhaps
this behavior has changed?). This solves my problem, so sorry if this
was all noise.

> That's intended, indeed. If you added a description to a link, Org
> should use it.

At least in the case of org-id, I can imagine that the description
might only be used to control appearance in the org buffer, not to
express desired export behavior.
A link that uses org-id really begs for a description for readability,
but then you can't get \ref{label} on export. Perhaps this is a corner
case that doesn't justify another customization.

Regards,
Jake


[1] https://lists.gnu.org/archive/html/emacs-orgmode/2015-03/msg00350.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Internal Links with Spaces
  2015-03-11 14:36   ` Jacob Gerlach
@ 2015-03-11 14:52     ` Nicolas Goaziou
  0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2015-03-11 14:52 UTC (permalink / raw)
  To: Jacob Gerlach; +Cc: Org-mode

Jacob Gerlach <jacobgerlach@gmail.com> writes:

> At least in the case of org-id, I can imagine that the description
> might only be used to control appearance in the org buffer, not to
> express desired export behavior.
> A link that uses org-id really begs for a description for readability,
> but then you can't get \ref{label} on export. Perhaps this is a corner
> case that doesn't justify another customization.

You may use custom-id links for better readability. Another option is to
use a filter on links (e.g., turn "hyperref" into "ref" for all links
whose _description_ start with "id:").

In any case, it doesn't justify another customization, which would break
consistency for id links.

Regards,

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-03-11 14:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-11 13:58 [PATCH] Internal Links with Spaces Jacob Gerlach
2015-03-11 14:17 ` Nicolas Goaziou
2015-03-11 14:36   ` Jacob Gerlach
2015-03-11 14:52     ` Nicolas Goaziou
  -- strict thread matches above, loose matches on Subject: below --
2015-03-11 13:34 Jacob Gerlach
2015-03-11 13:41 ` Nicolas Goaziou

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