Skip to main content
More comments
Source Link
egreg
  • 1.2m
  • 147
  • 2.8k
  • 4.5k

It's a timing problem. If I do

\documentclass{article}
\usepackage{microtype}
\usepackage{amsmath}

\ShowCommand\eqref

\begin{document}

\ShowCommand\eqref

\stop

I get

> \eqref=robust macro:
->\protect \eqref  .

> \eqref =\long macro:
#1->\textup {\tagform@ {\ref {#1}}}.
<argument> \eqref

l.5 \ShowCommand\eqref

?
(/usr/local/texlive/2025/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)
(./pardon.aux)
(/usr/local/texlive/2025/texmf-dist/tex/latex/microtype/mt-cmr.cfg)
> \eqref=robust macro:
->\protect \eqref  .

> \eqref =\long macro:
#1->\textup {\@nameuse {MT@patch@saved@\string \tagform@ }{\ref {#1}}}.
<argument> \eqref

l.9 \ShowCommand\eqref

?

So you see that microtype changes the definition of \eqref at begin document and you should do the redefinition (I guess you don't just want to get an alias to \eqref) at begin document.

Ensure to do

\AtBeginDocument{\NewCommandCopy{\stdeqref}{\eqref}}

in order to have an alias so you can redefine \eqref to your liking in terms of \stdeqref. Using \let on a robusted command is, to say the least, risky.

Some more details

If you do \let\stdeqref\eqref, the meaning of \stdeqref becomes \protect\eqref• (where the bullet means a space in the control sequence name). As we've seen, microtype redefines \eqref• and so, if you call

\stdeqref{a}\allowbreak\stdeqref

you get a result that's exactly the same as \eqref{a}\allowbreak\eqref{a}. Indeed, this is what happens:

\documentclass{article}
\usepackage{microtype}
\usepackage{amsmath}

\let\stdeqref\eqref

\begin{document}

\begin{equation}\label{a}
A
\end{equation}

\eqref{a}\allowbreak\eqref{a}

\stdeqref{a}\allowbreak\stdeqref{a}

\end{document}

same result

To the contrary, if you do \NewCommandCopy{\stdeqref}{\eqref}, you get

different result

Why? Because \NewCommandCopy defines \stdeqref to be \protect\stdeqref• and copies \eqref• into \stdeqref•, so the microtype patch isn't applied when you use \stdeqref{a}. Of course this is wrong and, as said, you should do

\AtBeginDocument{%
  \NewCommandCopy{\stdeqref}{\eqref}%
  % the redefinition of \eqref using \stdeqref goes here
}

It's a timing problem. If I do

\documentclass{article}
\usepackage{microtype}
\usepackage{amsmath}

\ShowCommand\eqref

\begin{document}

\ShowCommand\eqref

\stop

I get

> \eqref=robust macro:
->\protect \eqref  .

> \eqref =\long macro:
#1->\textup {\tagform@ {\ref {#1}}}.
<argument> \eqref

l.5 \ShowCommand\eqref

?
(/usr/local/texlive/2025/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)
(./pardon.aux)
(/usr/local/texlive/2025/texmf-dist/tex/latex/microtype/mt-cmr.cfg)
> \eqref=robust macro:
->\protect \eqref  .

> \eqref =\long macro:
#1->\textup {\@nameuse {MT@patch@saved@\string \tagform@ }{\ref {#1}}}.
<argument> \eqref

l.9 \ShowCommand\eqref

?

So you see that microtype changes the definition of \eqref at begin document and you should do the redefinition (I guess you don't just want to get an alias to \eqref) at begin document.

Ensure to do

\AtBeginDocument{\NewCommandCopy{\stdeqref}{\eqref}}

in order to have an alias so you can redefine \eqref to your liking in terms of \stdeqref. Using \let on a robusted command is, to say the least, risky.

It's a timing problem. If I do

\documentclass{article}
\usepackage{microtype}
\usepackage{amsmath}

\ShowCommand\eqref

\begin{document}

\ShowCommand\eqref

\stop

I get

> \eqref=robust macro:
->\protect \eqref  .

> \eqref =\long macro:
#1->\textup {\tagform@ {\ref {#1}}}.
<argument> \eqref

l.5 \ShowCommand\eqref

?
(/usr/local/texlive/2025/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)
(./pardon.aux)
(/usr/local/texlive/2025/texmf-dist/tex/latex/microtype/mt-cmr.cfg)
> \eqref=robust macro:
->\protect \eqref  .

> \eqref =\long macro:
#1->\textup {\@nameuse {MT@patch@saved@\string \tagform@ }{\ref {#1}}}.
<argument> \eqref

l.9 \ShowCommand\eqref

?

So you see that microtype changes the definition of \eqref at begin document and you should do the redefinition (I guess you don't just want to get an alias to \eqref) at begin document.

Ensure to do

\AtBeginDocument{\NewCommandCopy{\stdeqref}{\eqref}}

in order to have an alias so you can redefine \eqref to your liking in terms of \stdeqref. Using \let on a robusted command is, to say the least, risky.

Some more details

If you do \let\stdeqref\eqref, the meaning of \stdeqref becomes \protect\eqref• (where the bullet means a space in the control sequence name). As we've seen, microtype redefines \eqref• and so, if you call

\stdeqref{a}\allowbreak\stdeqref

you get a result that's exactly the same as \eqref{a}\allowbreak\eqref{a}. Indeed, this is what happens:

\documentclass{article}
\usepackage{microtype}
\usepackage{amsmath}

\let\stdeqref\eqref

\begin{document}

\begin{equation}\label{a}
A
\end{equation}

\eqref{a}\allowbreak\eqref{a}

\stdeqref{a}\allowbreak\stdeqref{a}

\end{document}

same result

To the contrary, if you do \NewCommandCopy{\stdeqref}{\eqref}, you get

different result

Why? Because \NewCommandCopy defines \stdeqref to be \protect\stdeqref• and copies \eqref• into \stdeqref•, so the microtype patch isn't applied when you use \stdeqref{a}. Of course this is wrong and, as said, you should do

\AtBeginDocument{%
  \NewCommandCopy{\stdeqref}{\eqref}%
  % the redefinition of \eqref using \stdeqref goes here
}
Source Link
egreg
  • 1.2m
  • 147
  • 2.8k
  • 4.5k

It's a timing problem. If I do

\documentclass{article}
\usepackage{microtype}
\usepackage{amsmath}

\ShowCommand\eqref

\begin{document}

\ShowCommand\eqref

\stop

I get

> \eqref=robust macro:
->\protect \eqref  .

> \eqref =\long macro:
#1->\textup {\tagform@ {\ref {#1}}}.
<argument> \eqref

l.5 \ShowCommand\eqref

?
(/usr/local/texlive/2025/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)
(./pardon.aux)
(/usr/local/texlive/2025/texmf-dist/tex/latex/microtype/mt-cmr.cfg)
> \eqref=robust macro:
->\protect \eqref  .

> \eqref =\long macro:
#1->\textup {\@nameuse {MT@patch@saved@\string \tagform@ }{\ref {#1}}}.
<argument> \eqref

l.9 \ShowCommand\eqref

?

So you see that microtype changes the definition of \eqref at begin document and you should do the redefinition (I guess you don't just want to get an alias to \eqref) at begin document.

Ensure to do

\AtBeginDocument{\NewCommandCopy{\stdeqref}{\eqref}}

in order to have an alias so you can redefine \eqref to your liking in terms of \stdeqref. Using \let on a robusted command is, to say the least, risky.