It turned out that LyX 2.4 escaped label names for compatibility with refstyle's formatted references:
\label{sec:A B}
...
\secref{A B} % can't find the label sec:AB -- refstyle has gobbled the whitespace!
1. LaTeX, refstyle restriction
I received an answer from the refstyle maintainer (Thank you, Daniel!) as follows (emphasis is mine):
"The main command in refstyle that cycles through a list of references (and
a single reference) is:
\def\RS@ref#1[#2]#3{%
\begingroup
\RS@setkeys{RS@#1}{#2}%
\@safe@activestrue%
\edef\RS@tmpa{\zap@space#3 \@empty}%
\@safe@activesfalse%
\edef\RS@tmpa{\noexpand\RS@@ref{#1} \RS@tmpa,\relax\noexpand\@eolst}%
\RS@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@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
2. LyX, workaround
The extra brackets solution is committed into main by a LyX developer. Thank you, Jürgen!
\label{sec:A B}
...
\secref{A B} % can't find the label sec:AB -- refstyle has gobbled the whitespace!
\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... Good, I committed to master".
-- Jürgen
\label
in LaTeX are already answered in the questions you've linked. And please ask only one question per question.latex
label names as revealed in the interplay ofrefstyle
and LyX. "It is not currently accepting answers" -- fine, but it's rather because a complete answer is given and accepted. In short, we can use whitespaces as long as other packages respect them. Here we've discovered an undocumented limitation ofrefstyle
, found a workaround, and patched LyX.