[Tex/LaTex] revtex4-2.cls error with an older TeX distribution

errorsrevtex

I am using the revtex4-2 class file for the first time to compile my .tex file. However, I am getting the following compilation error:

! Undefined control sequence.
<argument> \AddToHook 
                      {begindocument/before}{\document@inithook }
l.211   }

Here is a minimal working example.

\documentclass[aps,prl]{revtex4-2}
\begin{document}
This is APS RevTex 4.2 document class.
\end{document}

I have previously used revtex4-0 as well as revtex4-1 without any issue. I have recently installed revtex4.2e in my system. However, I am unable to figure out the problem I am facing with this latest RevTeX class.

Below is the log file.

This is XeTeX, Version 3.1415926-2.5-0.9999.3 (TeX Live 2013/Debian) (format=xelatex 2019.1.4)  19 DEC 2020 19:38
entering extended mode
 restricted \write18 enabled.
 %&-line parsing enabled.
**main
(./main.tex
LaTeX2e <2011/06/27>
Babel <3.9h> and hyphenation patterns for 78 languages loaded.
(./revtex4-2.cls
Document Class: revtex4-2 2020/10/03 4.2e (https://journals.aps.org/revtex/ for
 documentation)
 Copyright (c) 2019 American Physical Society.
 mailto:revtex@aps.org
 Licensed under the LPPL:
http://www.ctan.org/tex-archive/macros/latex/base/lppl.txt
 Arthur Ogawa <arthur_ogawa at sbcglobal dot net>
 Based on work by David Carlisle <david at dcarlisle.demon.co.uk>
 Version (4.2d,4.2e): Modified by Mark Doyle and Phelype Oleinik
 .
ltxutil[2020/10/03 4.2e utilities package (portions licensed from W. E. Baxter 
web at superscript.com)]
! Undefined control sequence.
<argument> \AddToHook 
                      {begindocument/before}{\document@inithook }
l.211   }
         
? x
 
Here is how much of TeX's memory you used:
 78 strings out of 493918
 768 string characters out of 6150564
 52172 words of memory out of 5000000
 3498 multiletter control sequences out of 15000+600000
 3640 words of font info for 14 fonts, out of 8000000 for 9000
 1144 hyphenation exceptions out of 8191
 14i,0n,10p,147b,10s stack positions out of 5000i,500n,10000p,200000b,80000s
No pages of output.

Best Answer

This happens because the line in RevTeX that checks your version of LaTeX:

\rvtx@ifformat@geq{2020-10-01}%
  {<code for new LaTeX>}
  {<code for old LaTeX>}

uses the date in the format yyyy-mm-dd, but this date format was only added to LaTeX in 2017, but your version is from 2013, and it only supports dates in the format yyyy/mm/dd, so the test above fails and it tries to execute the <code for new LaTeX> instead.

While RevTeX isn't updated again to use the old date format, use this patch to teach your version of LaTeX the new date format (and please update your TeX system!). The patch must be added before the \documentclass line:

% 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

% document
\documentclass[aps,prl]{revtex4-2}
\begin{document}
This is APS RevTex 4.2 document class.
\end{document}
Related Question