[Tex/LaTex] Upgrading MiKTeX causes issues with AddToHook

miktex

I have a set of pretty simple LaTeX documents that can compile on one Windows 10 machine and not on another. The same MiKTeX packages are installed on both and both have similar settings. The version of latex seems to be the difference.

One the machine where compilation fails, "latex –version" gives

MiKTeX-pdfTeX 4.1 (MiKTeX 20.11)

Whereas on the machine where compilation works, I get

MiKTeX-pdfTeX 4.0.1 (MiKTeX 20.7)

And here is the last snippet of the compilation log:

("C:\Users\username\AppData\Local\Programs\MiKTeX\tex/latex/etoolbox\etoolbox.sty"
Package: etoolbox 2020/10/05 v2.5k e-TeX tools for LaTeX (JAW)
 (C:/texmf\tex/latex/misc\etex.sty
Package: etex 1998/03/26 v2.0 eTeX basic definition package (PEB)
\et@xins=\count104
)
\etb@tempcnta=\count105
)
(C:/texmf\tex/latex/oberdiek\centernot.sty
Package: centernot 2010/03/29 v1.2 Centers the not symbol horizontally (HO)
)
\tx@cntz=\count106

("C:\Users\username\AppData\Local\Programs\MiKTeX\tex/generic/binhex\binhex.tex")
\tx@Isdigit=\count107
\tx@IsAlNum=\count108
\tx@tA=\toks31
\tx@tB=\toks32
\tx@su=\read2

! Undefined control sequence.
\AtEndPreamble ->\AddToHook 
                            {begindocument/before}
l.305 \AtEndPreamble
                    {%
? 
! Emergency stop.
\AtEndPreamble ->\AddToHook 
                            {begindocument/before}
l.305 \AtEndPreamble
                    {%

Based on what I can surmise, newtxmath.sty contains a \AtEndPreamble command, which is where the error gets triggered because \AddToHook is not defined. I believe \AddToHook is a newish LaTeX command included in the 2020 Fall release. Why is that undefined on the system with MiKTeX 20.11 but the document compiles just fine with the older version?

How do I go about troubleshooting where things might have gone wrong?

I've tried uninstalling and reinstalling a fresh version of MiKTeX, but that doesn't seem to help. I'm not sure how to install previous versions of MiKTeX so for now the only way I can compile this document is to use the older computer.

Best Answer

copy the patch code in the very beginning of your texfile. It fits for me!

% Patch to make old LaTeX understand dates in yyyy-mm-dd format
\makeatletter
\@ifundefined{@parse@version@dash}{%
\def\@parse@version#1{\@parse@version@0#1}
\def\@parse@version@#1/#2/#3#4#5\@nil{%
\@parse@version@dash#1-#2-#3#4\@nil}
\def\@parse@version@dash#1-#2-#3#4#5\@nil{%
  \if\relax#2\relax\else#1\fi#2#3#4 }
}{}
\makeatother

the reference: revtex4-2.cls error with an older TeX distribution