label whitespaces no more
Igor
rychphd at gmail.com
Sun May 18 07:47:09 UTC 2025
Thank you, Daniel: indeed even a simple
\newref{sss}{}
in the LaTeX preamble for my .lyx document solves the problem by
replacing the automatically LyX-generated definition:
\AtBeginDocument{\providecommand\sssref[1]{\ref{sss:#1}}}
On Sun, May 18, 2025 at 3:01 AM Daniel Els <dnjels at gmail.com> wrote:
>
> Igor
>
> Please note that refstyle has its own definitions for all the different types of references such as lists \xxxref{lbl1, lbl2, lbl3, ...}, ranges. Your command \sssref{} is just a standard latex definition. In refstyle the argument is processed further. Please read the documentation- refstyle.pdf, refconfig.pdf. This is where the original problem with spaces in labels originates. The algorithm removes all unbracked spaces to parse a comma separated list.
>
> To define a new reftype, for example a new reference for theorems:
>
> \newref{thm}{
> name = {theorem~},
> names = {theorems~},
> Name = {Theorem~},
> Names = {Theorems~},
> rngtxt = \RSrngtxt,
> lsttwotxt = \RSlsttxt,
> lsttxt = \RSlsttxt}
>
> Then you can use (without custom labels)
>
> \thmref{}
> \Thmref{}
> \thmrangeref{}{}
> \Thmrangeref{}{}
> \thmpageref{}
>
> You need to define the same for your sss references. If you have multilingual documents you must add the different texts for example:
>
> \RSaddto{\RSnorwegian}{%
> \def\RSthmtxt{teorem~}%
> \def\RSthmstxt{teorem~}%
> \def\RSThmtxt{Teorem~}%
> \def\RSThmstxt{Teorem~}}
>
> \RSaddto{\RSenglish}{%
> \def\RSthmtxt{theorem~}%
> \def\RSthmstxt{theorems~}%
> \def\RSThmtxt{Theorem~}%
> \def\RSThmstxt{Theorems~}}
>
> \newref{thm}{
> name = \RSthmtxt,
> names = \RSthmstxt,
> Name = \RSThmtxt,
> Names = \RSThmstxt,
> rngtxt = \RSrngtxt,
> lsttwotxt = \RSlsttxt,
> lsttxt = \RSlsttwotxt}
>
>
>
>
>
>
>
> On Sat, 17 May 2025 at 14:24, Igor <rychphd at gmail.com> wrote:
>>
>> While it worked for some *predefined* refs, such as secret and even
>> subsecref, for automatically generated custom refs, the brackets
>> method for dealing with whitespaces doesn't work:
>>
>> \label{sec:A B}
>> \secref{{A B}} -- works!
>>
>> \label{sss:A B}
>> \sssref{{A B}} -- doesn't work:
>> LaTeX Warning: Reference `sss:{A B}' on page 1 undefined on input
>>
>> I notice that LyX adds these lines to the tex file:
>> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
>>
>> \AtBeginDocument{\providecommand\secref[1]{\ref{sec:#1}}}
>> \AtBeginDocument{\providecommand\sssref[1]{\ref{sss:#1}}}
>>
>> I think secref has been already pre-defined by refstyle, but sssref
>> wasn't, hence the above definition is used and leads to the error.
>>
>>
>> On Tue, Sep 10, 2024 at 4:14 AM Igor <rychphd at gmail.com> wrote:
>> >
>> > (Sorry, bringing this back under the right Subject Line)
>> >
>> > Thank you Daniel. Interesting. I'm glad we may still use brackets to
>> > preserve whitespaces when referencing through refstyle's commands,
>> > hope it won't create new problems, but at least label names are
>> > allowed to have whitespaces after all :)
>> > > \label{sec:A B}
>> > > \secref{{A B}} -- works!
>> >
>> >
>> > On Tue, Sep 10, 2024 at 2:39 AM Daniel Els <dnjels at gmail.com> wrote:
>> > >
>> > > Igor
>> > >
>> > > The main command in refstyle that cycles through a list of references (and a single reference) is:
>> > >
>> > > \def\RS at ref#1[#2]#3{%
>> > > \begingroup
>> > > \RS at setkeys{RS@#1}{#2}%
>> > > \@safe at activestrue%
>> > > \edef\RS at tmpa{\zap at space#3 \@empty}%
>> > > \@safe at activesfalse%
>> > > \edef\RS at tmpa{\noexpand\RS@@ref{#1} \RS at tmpa,\relax\noexpand\@eolst}%
>> > > \RS at tmpa%
>> > > \endgroup}
>> > >
>> > > It removes spaces and was intended for the following scenario, and that is how many people write a list of references with spaces in between
>> > >
>> > > \secref(aaa, bbb, ccc) -> \ref{sec:aaa}, \ref{sec:bbb}, \ref{sec:ccc}
>> > >
>> > > If the \zap at space part is removed then we have the wrong reference:
>> > >
>> > > \secref(aaa, bbb, ccc) -> \ref{sec:aaa}, \ref{sec: bbb}, \ref{sec: ccc}
>> > >
>> > > The refstyle package cannot distinguish between a space in a list and a space in a reference. If I change that it will break a lot of old documents. The second point is that in standard latex, spaces in labels is a newish thing. It was not always there. Also note even if you put 10 spaces in a row in a label, latex only passes one through to the definition - see the .aux file. I think it is better to use an underscore _ or include your label in brackets {aaa}.
>> > >
>> > > Danie Els
>> > >
>> > >
>> > >
>> > >
>> > >
>> > > On Mon, 9 Sept 2024 at 11:21, Igor <rychphd at gmail.com> wrote:
>> > >>
>> > >> ==========
>> > >> Cc: Danie Els
>> > >> Hi Dannie,
>> > >> Seeing that you've updated the refstyle packages quite recently, on
>> > >> 2024/02/01, could you comment on the issue below? Full discussion
>> > >> starts from https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg222793.html.
>> > >> Basically, due to a refstyle bug (?) of eating up the whitespaces from
>> > >> label names aka " refstyle does not support spaces in references", the
>> > >> LyX developers have to either escape ALL label names or as suggested
>> > >> in the patch below, to enclose the label's name within additional {}
>> > >> just for refstyle's formatted references uses...
>> > >>
>> > >> I was wondering if you could rather fix it inside refstyle.sty?!
>> > >> Thanks,
>> > >> Igor
>> > >> ==========
>> > >>
>> > >>
>> > >>
>> > >> > > Seems like a refstyle's bug.
>> > >> > > \label{sec:A B}
>> > >> > > ...
>> > >> > > \secref{A B} -- can't find the label sec:AB -- refstyle has eaten up
>> > >> > > my whitespace!
>> > >> > >
>> > >> > > \secref{{A B}} -- works!
>> > >> >
>> > >> > Maybe, but as long as refstyle is not fixed (and I believe it is not
>> > >> > maintained any longer), escaping whitespace seems better than such
>> > >> > extra-grouping.
>> > >> >
>> > >> > > > \secref{{A B}} -- works!
>> > >> > >
>> > >> > > Actually, considering all eventualities, this might be the best
>> > >> > > solution, as the problem only concerns refstyle's formatted ref
>> > >> > > commands. All other solutions that I could think of add unnecessary
>> > >> > > complication.
>> > >>
>> > >> > > Does tex2lyx need some adaptation to avoid {{{{labels}}}} on
>> > >> > > roundtrips?
>> > >> >
>> > >> > Yes, you're right.
>> > >>
>> > >> Jürgen, thank you for the patch and the others for the discussion. Let
>> > >> me answer this question of yours:
>> > >> > Would it work for you if we limited the space escaping to the case only
>> > >> > where refstyle is used? I.e., could you uncheck "Use refstyle"?
>> > >>
>> > >> -- refstyle gets loaded automatically when I choose Formatted
>> > >> reference through LyX GUI. Ironically I redefine most of the
>> > >> refstyle's formatted commands underneath :) I'm going to test to see
>> > >> how I can implement this with "Use refstyle" unchecked in the future
>> > >> documents.
>> > >>
>> > >> Thanks,
>> > >> Igor
More information about the lyx-devel
mailing list