emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jacob Gerlach <jacobgerlach@gmail.com>
To: John Kitchin <jkitchin@andrew.cmu.edu>, Org-mode <emacs-orgmode@gnu.org>
Subject: Re: Internal Links with Spaces
Date: Tue, 10 Mar 2015 15:47:44 -0400	[thread overview]
Message-ID: <CAA6UvuGYpUVhkuUufkekzixYqa_4y5Qq75MwRbuBhP9_ocEEHQ@mail.gmail.com> (raw)
In-Reply-To: <m2egowj0h7.fsf@andrew.cmu.edu>

On Tue, Mar 10, 2015 at 12:12 PM, John Kitchin <jkitchin@andrew.cmu.edu> 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

      parent reply	other threads:[~2015-03-10 19:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-09 13:05 Internal Links with Spaces Jacob Gerlach
2015-03-09 14:38 ` Leo Ufimtsev
2015-03-09 20:50   ` Jacob Gerlach
2015-03-09 23:28     ` John Kitchin
     [not found]       ` <CAA6UvuEG_9b0+b=boXMSsi+8yZWZORBkMAfgKj+9rhPpuevsgQ@mail.gmail.com>
2015-03-10 14:30         ` John Kitchin
2015-03-10 14:39       ` Jacob Gerlach
     [not found]         ` <m2egowj0h7.fsf@andrew.cmu.edu>
2015-03-10 19:47           ` Jacob Gerlach [this message]

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=CAA6UvuGYpUVhkuUufkekzixYqa_4y5Qq75MwRbuBhP9_ocEEHQ@mail.gmail.com \
    --to=jacobgerlach@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=jkitchin@andrew.cmu.edu \
    /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).