[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Internal Links with Spaces
From: |
Jacob Gerlach |
Subject: |
Re: [O] Internal Links with Spaces |
Date: |
Tue, 10 Mar 2015 15:47:44 -0400 |
On Tue, Mar 10, 2015 at 12:12 PM, John Kitchin <address@hidden> wrote:
> As far as I know you have only two options to use refs to a headline in
> Latex export.
>
> 1) Use a CUSTOM_ID property on a heading and then use [[#your-custom-id]] as
> your link. You have to put relevant text in like: see section
> [[#your-custom-id]]. If you want readable custom-ids you should make
> them yourself, e.g. C-c C-x p CUSTOM_ID your-custom-id, or craft an
> elisp function that prompts you for the custom-id and sets it for you,
> maybe even copying it to the kill-ring so it is easy to insert later.
>
> 2) Put \label{some-name} in the heading (yes, it is not pretty), e.g.
>
> * Results \label{sec-results}
>
> and use \ref{some-name} where you want the link to export to (or, if you
> use org-ref you can use ref:some-name which will be a clickable link,
> and also label:sec-results which is also a functional link). You still
> have to put relevant text in, e.g. see section ref:some-label.
Thanks to John for the recommendations, but given these options, I'm
more attracted to solving the original problem with the % escaped
spaces.
I came up with the following wrapper function - it successfully
replaces the hex encoded spaces (elisp feedback welcome):
(defun jg/insert-link-unescape-spaces ()
(interactive)
(org-insert-link)
(save-excursion
(let ((beg (point)))
(org-previous-link)
(let ((end (point)))
(replace-string "%20" " " nil beg end)))))
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{}.
Any (of several) attempts to insert a link so that it has no
description is foiled. I think this is done by org-make-link-string,
which just re-uses the link text for the description when none is
given.
In any case, here's an ugly hack to manually remove the description.
This works for me, but I'd love to find a more elegant approach:
(defun jg/insert-link-unescape-spaces ()
(interactive)
(org-insert-link)
(save-excursion
(let ((beg (point)))
(org-previous-link)
(let ((end (point)))
(replace-string "%20" " " nil beg end))))
;expose the link so that search can see brackets
(delete-char -1)
(let ((end (point))
(beg (search-backward "[")))
(delete-region beg end)
(insert "]")))
Alternatively, if someone has a latex export hack that forces links to
reference labels instead of headline text (even when the org link has
a description), I'd be interested in that. It seems like this would be
a common request for exporting scientific writing to latex (unless
those users prefer one of the approaches John suggested above).
Regards,
Jake