From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jacob Gerlach Subject: Re: Internal Links with Spaces Date: Tue, 10 Mar 2015 15:47:44 -0400 Message-ID: References: <1825534239.18268273.1425911896744.JavaMail.zimbra@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVQ82-00027c-9O for emacs-orgmode@gnu.org; Tue, 10 Mar 2015 15:47:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YVQ81-0002Nb-6q for emacs-orgmode@gnu.org; Tue, 10 Mar 2015 15:47:46 -0400 Received: from mail-qc0-x230.google.com ([2607:f8b0:400d:c01::230]:41322) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YVQ81-0002NX-1m for emacs-orgmode@gnu.org; Tue, 10 Mar 2015 15:47:45 -0400 Received: by qcrw7 with SMTP id w7so4785939qcr.8 for ; Tue, 10 Mar 2015 12:47:44 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: John Kitchin , Org-mode On Tue, Mar 10, 2015 at 12:12 PM, John Kitchin 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