1

Can you please help me identify what is wrong with my coding? I've searched online for solutions but I couldn't find a working one. Before, I used article for my \documentclass to complete my thesis. Now, they required me to use revtex4-2 as the \documentclass. So, I modified some of the lines from the coding but it keeps on giving me errors probably because some of the packages don't work in the revtex4-2 class but I couldn't figure out what.

Here is my preamble for the coding:

\documentclass[%  
 aip,  
% jmp,  
% bmf,  
% sd,  
% rsi,  
cp,  % Conference Proceedings  
 amsmath,amssymb,%nobibnotes,  
% preprint,%  
 reprint,%  
%author-year,%  
%author-numerical,%  
]{revtex4-2}  

\usepackage{graphicx}% Include figure files  
\usepackage{dcolumn}% Align table columns on decimal point  
\usepackage{bm}% bold math  
%\usepackage[mathlines]{lineno}% Enable numbering of text and display math  
%\linenumbers\relax % Commence numbering lines  

\usepackage[utf8]{inputenc}  
\usepackage[T1]{fontenc}  
%% Loads a Times-like font. You can also load  
%% {newtxtext,newtxtmath}, but not {times},   
%% {txfonts} nor {mathtpm} as these packages  
%% are obsolete and have been known to cause problems.  
\usepackage{mathptmx}   

\usepackage{paralist}  
\usepackage{natbib}  
\usepackage[figuresright]{rotating}  
\usepackage{lscape}  
\usepackage{graphicx}  
\usepackage{longtable}  
\usepackage{calc}  
\usepackage{slashbox}  
\usepackage{amsmath}  
\usepackage{amsfonts}  
\usepackage{amssymb}  
\usepackage{setspace}  
\usepackage{color}  
\usepackage[hmarginratio=2:3]{geometry}  
\usepackage{epstopdf}  
\usepackage{afterpage}  
\usepackage{changepage}  
\usepackage[table]{xcolor}  
\usepackage{makecell}  
\usepackage{mathtools}  
\usepackage{algorithmic}  
\usepackage[section]{algorithm}  
\usepackage{float}  
\usepackage{placeins}  
\usepackage{afterpage}  
\usepackage{url}  
\allowdisplaybreaks  
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}  
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}  
\newcommand{\dv}{\mid}  
\newcommand{\ndv}{\nmid}  
\citestyle{apa}  
\renewcommand{\baselinestretch}{1.5}  

\begin{document}  

Here's the error notification:

! Extra \endgroup.
\document -> \endgroup
\document@inithook \true@sw {}\UseOneTimeHook {begindo...

Sorry if my information isn't enough because I'm still new here. I don't know what else to provide you with. Thank you so much in advance for your help.

26
  • probably mixed version dates of latex/packages. Ensure that everything is up-to-date. If you use miktex update in user and admin mode in the miktex console. Commented Nov 14, 2021 at 11:13
  • I already updated it from the MiKTeX Console but the error is still there.
    – Azmadi M
    Commented Nov 14, 2021 at 12:00
  • Run a small document which loads only the class. It the errors show the complete log file Commented Nov 14, 2021 at 14:40
  • Welcome, @AzmadiM! I'd like to iterate upon @UlrikeFischer's comment: at the very top of your document, try adding the \listfiles command. When compiling the document, it will display the versions of all the used packages, along with the version of the document class. In that console output, what version is mentioned for revtex4-2.cls? Is it anything other than 4.2e? On my device, it says revtex4-2.cls 2020/10/03 4.2e (https://journals.aps.org/revtex/ for documentation). The answer at tex.stackexchange.com/a/565864/256551 is the reason I ask about this version. Commented Nov 14, 2021 at 14:59
  • 1
    Hello @MiriamBriskman you're a lifesaver! I've fixed it thank you so much! Yes, the revtex4-2.cls is the reason for the error. I've removed it from the folder I'm working with & it works wonder after that. I didn't realize the compiler uses the revtex4-2.cls in that folder. Maybe it is outdated since I downloaded it from the website. Thank you so much again for a very helpful guidance for the past few days. Sorry if I wasn't replying fast enough.
    – Azmadi M
    Commented Nov 18, 2021 at 5:21

1 Answer 1

2

First, we describe what action eliminated the error and then explain how we discovered the source of the error.


Solution

The folder where the TeX document was located contained a copy of an old version of the revtex class document, revtex4-2.cls. During compilation, this old package was loaded by pdfLaTeX, which caused the ! Extra \endgroup. error to appear.

Removing the local copy of revtex4-2.cls away from the folder eliminated the error and let the document compile smoothly after the removal.


Diagnosing the Issue

The TeX document uses revtex4-2 as the \documentclass.

The error

! Extra \endgroup.
\document -> \endgroup
\document@inithook \true@sw {}\UseOneTimeHook {begindo...

which was generated during compilation, is produced when a revtex4-2 version older than 4.2e is loaded. This error is asked upon and answered by my2cts at Extra \endgroup error with RevTeX after update.

In general, to remove the error, one should proceed to update the package version. In MiKTeX, for example, the update should be done both at the user level and at the administrator level, as the answer by Ulrike Fischer to How should one maintain and update a MiKTeX installation? thoroughly explains.

However, the solution was not as easy as updating the package.

The MiKTeX Console showed that the currently installed version was 4.2e, the most recent version of the package and that there are no pending updates for the package.

Nonetheless, including the command \listfiles at the top of the document, led to the following metadata output about the package:

\revtex4-2.cls Document Class: revtex4-2 2018/12/26/16:06:17 4.2b (journals.aps.org/revtex/ for documentation)

The loading of this older version (4.2b) of the revtex package into pdfLaTeX, given the verified installation of the newest version, indicated the presence of an older class document file elsewhere on the device.


Searching for the old-version class document file

The log file showed that the majority of the loaded packages during compilation are in

C:\Users\madie\AppData\Local\Programs\MiKTeX\tex/latex

It was confirmed via the MiKTeX Console (under Settings > Directories) that MiKTeX installs user packages at the above directory.

However, the document class revtex4-2.cls was loaded from the external-to-the-installation directory

C:\Users\madie\Dropbox/PC/Downloads/FYP/TO BE PUBLISHED/ConfTemplate-20211114T010429X-001

It turned out this is the directory where the TeX file under question is placed.

pdfLaTeX used this local, old-version copy of revtex4-2.cls instead of the MiKTeX-installed version, because a copy of a .tex, .sty, .cls, etc. file that is located in the same folder as the TeX document overshadows the 'official' file in the installation path.


Thanks

I would like to thank Azmadi, the writer of the question, for the responsiveness and the provision of the details that were crucial for detecting the issue.

The precious advice of Ulrike Fischer on confirming that the package was updated on MiKTeX, on the correct manner to execute updates, and on the great suggestion of reducing the TeX file to a minimal working example aided significantly in the error-finding process.

The recommendation of Máté Wierdl to replace the outdated slashbox package with diagmac2 will undoubtedly eliminate errors and warnings related to the former package. Thank you very much for your input.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .