refstyle and amsmath

Jürgen Spitzmüller jspitzm at gmail.com
Tue Jan 30 17:17:42 UTC 2024


Am Montag, dem 29.01.2024 um 15:00 +0100 schrieb Kees Zeelenberg:
> Some time ago there was a discussion on the list about refstyle in
> combination with amsmath, leading to error messages from refstyle. It
> appears refstyle is now loaded after amsmath, but this now leads to
> messages like “LaTeX Warning: Reference `ab' on page 1 undefined on
> input line 39” from the enclosed LyX file ‘testref.lyx’. 

The loading order has not been changed, and it also doesn't matter (as
a view into refstyle.sty reveals). The warning is also in LyX 2.3.x,
although it is less prominent (the heightening of prominence was done
in purpose for 2.4, since you will want to be informed about broken
references).

> It seems that this is related to the LaTeX line
> “\AtBeginDocument{\providecommand\eqref[1]{\ref{eq:#1}}}”, which is
> added by LyX in ‘testref.tex’. This line does not have any effect, so
> that e.g. \eqref{ab}  is interpreted as \ref{ab}  instead of
> \ref{eq:ab}. 

This is by design as well. This definition gets only active in case
\eqref is undefined, hence \providecommand.

> Replacing this line with
> \AtBeginDocument{\DeclareRobustCommand{\eqref}[1]{\textup{\tagform@{\
> ref{eq:#1}}}}} (as in amsmath), the LaTeX file ‘testref_robust.tex’
> compiles without problems.

Yes, but this is not the right fix as it will break the refstyle
integration with equation references.

The problem here is that refstyle attempts to overwrite and integrate
amsmath's \eqref definition into its own \eqref definition. This does
not work anymore since \eqref has been made robust in the 2022-06-01
release of amsmath [1], and the command copying and redefinition
refstyle used (via \let) does not work with robust commands.
\NewCommandCopy needs to be used instead of \let.

Ultimately, this needs to be fixed in refstyle. I reported this to the
maintainer in March 2023 and even sent a patch [2] but never got a
response. It seems the package is factually unmaintained.

We can check for the respective amsmath version and patch into refstyle
ourselves in LyX. Long term, I think we should abandon refstyle and go
for another package (cleveref or zref-clever).

Best,
Jürgen

[1] See
https://github.com/latex3/latex2e/commit/7c1184dc800f8902f279103660f118e5a82e62b0#diff-94ab1b0d7fdf9c2f8420be553012d86a5a18e3d4ab139512d12773b6e5228efdR2697-R2699

[2] this is the fix

--- /usr/local/texlive/current/texmf-
dist/tex/latex/refstyle/refstyle.cfg
+++ /home/juergen/texmf/tex/latex/testen/refstyle.cfg
@@ -512,7 +512,8 @@
 %%-- TEMPLATE FOR EQUATIONS ---------------------
 \newcommand*{\RSeqrefform}[1]{\textup{(\ref{#1})}}
 \@ifpackageloaded{amsmath}%
-   {\let\AMSeqref\eqref
+   {\DeclareCommandCopy\AMSeqref\eqref
+    \DeclareRobustCommand\eqref{\relax}
     \let\eqref\relax}%
    {}
 \newref{eq}{%
@@ -528,8 +529,8 @@
 \let\eqref\relax
 \AtBeginDocument{%
    \@ifpackageloaded{amsmath}%
-      {\RS at ifundefined{AMSeqref}{\let\AMSeqref\eqref}{}%
-       \let\RSeqrefform\AMSeqref}%
+    
{\RS at ifundefined{AMSeqref}{\DeclareCommandCopy\AMSeqref\eqref}{}%
+       \DeclareCommandCopy\RSeqrefform\AMSeqref}%
          {}%
      \let\eqref=\RSeqref
    }




More information about the lyx-users mailing list