emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Internal Links with Spaces
@ 2015-03-09 13:05 Jacob Gerlach
  2015-03-09 14:38 ` Leo Ufimtsev
  0 siblings, 1 reply; 7+ messages in thread
From: Jacob Gerlach @ 2015-03-09 13:05 UTC (permalink / raw)
  To: Org-mode

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

Hi List,

I'd like to re-raise the issue discussed here
<http://comments.gmane.org/gmane.emacs.orgmode/79902>. In short, storing
and inserting an internal link to a headline containing spaces using
org-store-link and org-insert-link causes export to fail because the space
is "hexified" into %20.

It seems like the thread died because hexifying links to support external
URL's conflicted with internal links containing spaces with no clear path
forward.

Am I missing further discussion where this was resolved?

If not, is a fix still possible or is this a "won't fix" because of the
clash with external links?

If it's "won't fix", is it possible for me to advise org-insert-link (or
some other function) or configure some other individual hack to work around
the problem? I never use org-insert-link for URL's, so I'd be glad to
blindly stop hexifying even if it breaks that functionality.

Regards,
Jake

[-- Attachment #2: Type: text/html, Size: 1171 bytes --]

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

* Re: Internal Links with Spaces
  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
  0 siblings, 1 reply; 7+ messages in thread
From: Leo Ufimtsev @ 2015-03-09 14:38 UTC (permalink / raw)
  To: Jacob Gerlach; +Cc: Org-mode

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

On the side, if of any help: 

I generally use ID's for linking to headings. 
The benefit is that headings can be re-named safley and links still work. 

There is an org-module called 'org-id', which when enabled in conjunction with the variable 
below allows you to automatically generate a unique id for the heading when you press C-c l and link to it with C-c C-l. 

This exports nicley also. E.g here is a unique anchor link to one of those unique ID's: 
http://leoufimtsev.github.io./org/swt-dev.html#ID-a636a35d-6100-4f6a-974c-6bbeedc0f2a2 

(org-id-link-to-org-use-id (quote create-if-interactive-and-no-custom-id)) 

'(org-modules 
(quote 
(org-id ... 

Leo Ufimtsev | Intern Software Engineer @ Eclipse Team 


----- Original Message -----

From: "Jacob Gerlach" <jacobgerlach@gmail.com> 
To: "Org-mode" <emacs-orgmode@gnu.org> 
Sent: Monday, March 9, 2015 9:05:40 AM 
Subject: [O] Internal Links with Spaces 

Hi List, 

I'd like to re-raise the issue discussed here . In short, storing and inserting an internal link to a headline containing spaces using org-store-link and org-insert-link causes export to fail because the space is "hexified" into %20. 

It seems like the thread died because hexifying links to support external URL's conflicted with internal links containing spaces with no clear path forward. 

Am I missing further discussion where this was resolved? 

If not, is a fix still possible or is this a "won't fix" because of the clash with external links? 

If it's "won't fix", is it possible for me to advise org-insert-link (or some other function) or configure some other individual hack to work around the problem? I never use org-insert-link for URL's, so I'd be glad to blindly stop hexifying even if it breaks that functionality. 

Regards, 
Jake 


[-- Attachment #2: Type: text/html, Size: 2566 bytes --]

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

* Re: Internal Links with Spaces
  2015-03-09 14:38 ` Leo Ufimtsev
@ 2015-03-09 20:50   ` Jacob Gerlach
  2015-03-09 23:28     ` John Kitchin
  0 siblings, 1 reply; 7+ messages in thread
From: Jacob Gerlach @ 2015-03-09 20:50 UTC (permalink / raw)
  To: Leo Ufimtsev; +Cc: Org-mode

On Mon, Mar 9, 2015 at 10:38 AM, Leo Ufimtsev <lufimtse@redhat.com> wrote:
> On the side, if of any help:
>
> I generally use ID's for linking to headings.
> The benefit is that headings can be re-named safley and links still work.

A great suggestion. I wasn't aware of the feature, and renaming safety
is a great benefit while also solving my space problem.

I don't suppose there's a trick to automatically update descriptions
for links whose target has been renamed?

When exploring this, I found the function org-id-store-link. This
seemed like what I wanted - it creates a custom ID if one doesn't
exist, but it doesn't actually store a link (or at least, it wasn't
available when I then ran org-insert-link). The docstring is pretty
light, but it seems like this might be a bug. Is this the expected
behavior?

Thanks for the pointer in any case.

Regards,
Jake

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

* Re: Internal Links with Spaces
  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:39       ` Jacob Gerlach
  0 siblings, 2 replies; 7+ messages in thread
From: John Kitchin @ 2015-03-09 23:28 UTC (permalink / raw)
  To: Jacob Gerlach; +Cc: Leo Ufimtsev, Org-mode

I think you need to set

(setq org-id-link-to-org-use-id 'create-if-interactive)

Then the usual C-c l and C-c C-l should work to store links and insert
them.

It might be worth noting though, that in my experience, this is most
useful for links within a file, or to files in your agenda list. org does not
have a good way to find an id in a non-agenda file if that file is not
already open. Although there should be a .org-id-locations file
somewhere that stores this mapping of id to file. I have not experienced
100% success with this.

Also, you have to be a little cautious about copying a headline to
another place, because then you have two ids in different places.

anyway, the point is try it out and see if it works for you ;)

Jacob Gerlach writes:

> On Mon, Mar 9, 2015 at 10:38 AM, Leo Ufimtsev <lufimtse@redhat.com> wrote:
>> On the side, if of any help:
>>
>> I generally use ID's for linking to headings.
>> The benefit is that headings can be re-named safley and links still work.
>
> A great suggestion. I wasn't aware of the feature, and renaming safety
> is a great benefit while also solving my space problem.
>
> I don't suppose there's a trick to automatically update descriptions
> for links whose target has been renamed?
>
> When exploring this, I found the function org-id-store-link. This
> seemed like what I wanted - it creates a custom ID if one doesn't
> exist, but it doesn't actually store a link (or at least, it wasn't
> available when I then ran org-insert-link). The docstring is pretty
> light, but it seems like this might be a bug. Is this the expected
> behavior?
>
> Thanks for the pointer in any case.
>
> Regards,
> Jake

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

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

* Re: Internal Links with Spaces
       [not found]       ` <CAA6UvuEG_9b0+b=boXMSsi+8yZWZORBkMAfgKj+9rhPpuevsgQ@mail.gmail.com>
@ 2015-03-10 14:30         ` John Kitchin
  0 siblings, 0 replies; 7+ messages in thread
From: John Kitchin @ 2015-03-10 14:30 UTC (permalink / raw)
  To: Jacob Gerlach, emacs-orgmode@gnu.org

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

I am not sure what the convention there is.

John

-----------------------------------
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu


On Tue, Mar 10, 2015 at 10:05 AM, Jacob Gerlach <jacobgerlach@gmail.com>
wrote:

> On Mon, Mar 9, 2015 at 7:28 PM John Kitchin <jkitchin@andrew.cmu.edu>
> wrote:
> >
> > I think you need to set
> >
> > (setq org-id-link-to-org-use-id 'create-if-interactive)
>
> Indeed, this is a variation of what Leo suggested and customizing
> org-id-link-to-org-use-id is working well for me.
>
> After perusing the source code further, I think that my confusion
> about org-id-store-link arose because this function isn't intended to
> be called on it's own (it's called by org-store-link when appropriate
> based on the value of org-id-link-to-org-use-id).
>
> I've seen a double hyphen in function names to sometimes indicate
> internal functions. Would this function be more appropriately named
> org-id--store-link or am I misunderstanding the convention?
>
> Regards,
> Jake
>

[-- Attachment #2: Type: text/html, Size: 1841 bytes --]

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

* Re: Internal Links with Spaces
  2015-03-09 23:28     ` John Kitchin
       [not found]       ` <CAA6UvuEG_9b0+b=boXMSsi+8yZWZORBkMAfgKj+9rhPpuevsgQ@mail.gmail.com>
@ 2015-03-10 14:39       ` Jacob Gerlach
       [not found]         ` <m2egowj0h7.fsf@andrew.cmu.edu>
  1 sibling, 1 reply; 7+ messages in thread
From: Jacob Gerlach @ 2015-03-10 14:39 UTC (permalink / raw)
  To: John Kitchin; +Cc: Leo Ufimtsev, Org-mode

On Mon, Mar 9, 2015 at 7:28 PM, John Kitchin <jkitchin@andrew.cmu.edu> wrote:
> I think you need to set
>
> (setq org-id-link-to-org-use-id 'create-if-interactive)

Indeed, this is a variation of what Leo suggested and customizing
org-id-link-to-org-use-id is almost working for me...

Unfortunately, I want the links to export to latex using latex
\ref{}'s and section labels. A link stored with a custom id has to
have a description to have a reasonably readable org buffer, but links
with descriptions are exported using the headline text instead of the
section number. Is there a workaround for this?

On Mon, Mar 9, 2015 at 4:50 PM, Jacob Gerlach <jacobgerlach@gmail.com> wrote:
> When exploring this, I found the function org-id-store-link. This
> seemed like what I wanted - it creates a custom ID if one doesn't
> exist, but it doesn't actually store a link (or at least, it wasn't
> available when I then ran org-insert-link). The docstring is pretty
> light, but it seems like this might be a bug. Is this the expected
> behavior?

After perusing the source code further, I think that my confusion
about org-id-store-link arose because this function isn't intended to
be called on it's own (it's called by org-store-link when appropriate
based on the value of org-id-link-to-org-use-id).

I've seen a double hyphen in function names to sometimes indicate
internal functions. Would this function be more appropriately named
org-id--store-link or am I misunderstanding the convention?



Regards,
Jake

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

* Re: Internal Links with Spaces
       [not found]         ` <m2egowj0h7.fsf@andrew.cmu.edu>
@ 2015-03-10 19:47           ` Jacob Gerlach
  0 siblings, 0 replies; 7+ messages in thread
From: Jacob Gerlach @ 2015-03-10 19:47 UTC (permalink / raw)
  To: John Kitchin, Org-mode

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

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

end of thread, other threads:[~2015-03-10 19:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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

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