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

\tx@Isdigit=\count107
\tx@IsAlNum=\count108
\tx@tA=\toks31
\tx@tB=\toks32

! Undefined control sequence.
{begindocument/before}
l.305 \AtEndPreamble
{%
?
! Emergency stop.
{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.

• That's strange, because \AtEndPreamble is only defined to use \AddToHook if your version of LaTeX contains that command... Can you show the full log, please? Dec 9 '20 at 1:09
• Here's the full log: pastebin.com/Ay59208m Dec 9 '20 at 1:15
• Your LaTeX format is from 2009! (LaTeX2e <2009/09/24>), but you are trying to load a 2020 version of etoolbox: you should really not do that. Either update your system or use the old version of etoolbox. This is happening because the 2009 LaTeX doesn't understand the date separated with dashes 2020-10-01, then your new etoolbox thinks it's on a new LaTeX and uses the new definitions. Dec 9 '20 at 1:25
• Thanks for pointing that out. I discovered an old texmf root directory that had very old things in it. Time to do some spring cleaning! Dec 9 '20 at 3:48

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