On Fri, 22 Sep 2023, Arash Esbati <ar...@gnu.org> wrote:

> J. Xu <x...@stat.wisc.edu> writes:
>> reftex-view-crossref currently only finds reference to the current space
>> delineated word.  For example, if I'm at (* being the point)
>> \ref{foo *bar}
>> and run reftex-view-crossref, it would find the definition of "bar"
>> instead of "foo bar".
>> I wonder if this behaviour is intended?
> Yes, this is the intended behavior in terms of "this is what the code
> does": `reftex-view-crossref' starts like this:
> (defun reftex-view-crossref (&optional arg auto-how fail-quietly)
>   (interactive "P")
>   ;; See where we are.
>   (let* ((macro (car (reftex-what-macro-safe 1)))
>          (key (reftex-this-word "^{}%\n\r, \t"))
>     ...
> The label key is extracted by `reftex-this-word' which is asked to
> ignore spaces with "^{}%\n\r, \t".  I'm not sure if spaces were always
> allowed in labels, but they are by now (also other characters besides
> ASCII, IIRC).  So we probably should fix this and allow spaces.  But
> then we have to know what LaTeX does with linebreaks inside the \label
> argument, i.e.:
> \label{foo
>   bar}
> I haven't tested this.  Is LaTeX's behavior in this regard documented
> somewhere?

I couldn't find related documentation.  I did a quick test and it looks
like a linebreak, carriage return, or tab is essentially converted to a
space.  Specifically, the following pair works:

\ref{foo bar}

> And if we touch this, we should also change `reftex-label-illegal-re'.
> Personally, I recommend to use only this range [-a-zA-Z0-9_+=:;,.] for
> label names and be done with it.

Agreed.  This issue only came up because I'm working on someone else's
manuscript.  Oof, much pain.

> Best, Arash

Reply via email to