ho-tex / zref

zref packages for LaTeX
LaTeX Project Public License v1.3c
6 stars 2 forks source link

\zlabel is ignored inside multline environment #4

Open kia999 opened 4 years ago

kia999 commented 4 years ago

I noted that \zlabel is ignored inside multline environment, it does not write \zref@newlabel to aux file. Here is MWE:

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage[user]{zref}

\begin{document}

\begin{equation}
\zlabel{eq:01}
E=mc^{2}
\end{equation}

\begin{multline}
\zlabel{eq:02}
  W = \int \vec{\xi}\cdot \vec{F}(\vec{\xi}) \,d^{3}x 
    =
   \\
   \iint \ldots 
\end{multline}

First Eq.~\zref{eq:01}, second Eq.~\zref{eq:02}.
\end{document}
u-fischer commented 4 years ago

Yes. But I don't think that zref can do much here. The amsmath environments take a lot trouble to save and restore \label when processing the content but ignore \zlabel. So amsmath would need a change.

You can get your example more or less working with the following. But it could have bad side effects if you have \label commands in other places:

\documentclass[a4paper]{article}

\usepackage[user]{zref}

\makeatletter \def\label{\zref@wrapper@babel\zref@label}\makeatother
\usepackage{amsmath}

\begin{document}

\begin{equation}
\zlabel{eq:01}
E=mc^{2}
\end{equation}

\begin{multline}
\label{eq:02}
  W = \int \vec{\xi}\cdot \vec{F}(\vec{\xi}) \,d^{3}x
    =
   \\
   \iint \ldots
\end{multline}

First Eq.~\zref{eq:01}, second Eq.~\zref{eq:02}.
\end{document}
kia999 commented 4 years ago

@u-fischer : No, it does not work.

u-fischer commented 4 years ago

Yes, it does. I tested it on a current texlive.

davidcarlisle commented 4 years ago

@kia999 your last comment appears scrambled (it just shows as CSS?) could you clarify your "not work" comment by showing the log, or saying what happens?

u-fischer commented 4 years ago

@kia999 Works fine for me on miktex too.

kia999 commented 4 years ago

In my example zref is loaded after amsmath, and \zref prints ?? if \zlabel is inside multline. Log file reports that label is not found.

In example given bu Ulrike Fischer zref goes before amsmath and \zref works fine.

davidcarlisle commented 4 years ago

@u-fischer I suppose it might be possible for \zlabel to check if \label is \label@in@display (that is check if it's in the scope of a local amsmath alignment redefinition of \label) and if so adapt itself accordingly, perhaps...

u-fischer commented 4 years ago

@davidcarlisle the problem isn't so much that zlabel isn't executed, but that even if one force the execution it doesn't get the right values to save them to the aux file. E.g.

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage[user]{zref}

\begin{document}

\makeatletter
\renewcommand*\zlabel{%
  \zref@wrapper@babel\zref@label
}%

\begin{multline}
%\def\@currentlabel{\theequation}
\zlabel{eq:02}
  W
\end{multline}

Eq.~\zref{eq:02}.
\end{document}

without the \@currentlabel definition the default is empty \default{}, and with it it is 0.