Minimal working example
% !TeX TS-program = pdflatex
% !TeX encoding = UTF-8
\documentclass{elsarticle}
\begin{document}
\begin{frontmatter}
\end{frontmatter}
\end{document}
leads to
Overfull \hbox (2.22221pt too wide) has occurred while \output is active []
The same warning occurs if I use the original template from:
- https://www.elsevier.com/authors/author-schemas/latex-instructions
- direct link: https://www.elsevier.com/__data/assets/file/0007/56842/elsarticle-template.zip
I'm using
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (MiKTeX 2.9.7200 64-bit)
and my packages are all up to date (as of 30.Oct.2019) and I have the newest version of elsarticle
: https://ctan.org/pkg/elsarticle (06.April.2019)
Best Answer
This is a bug in
elsarticle
introduced some time in 2018 (in TeXLive 2017 it's fine), caused by the usual missing%
at the end of the line. The guilty definition is:where the line marked with
% <--
should contain a%
right after the}
. (Funnily enough, most of the end of line%
in this definition are useless :-)Here are four options to fix this (all except 2 should go after
elsarticle
is loaded, or they will have no effect):Copy the definition above to your document and add a
%
right after the}
(and make sure to add\makeatletter
and\makeatother
around the definition):Make a local copy of
elsarticle.cls
and do the same.Patching with
\patchcmd
is tricky1 because the extra space is between two}
. But it's possible with some brace hacking and\romannumeral
. Adding this to your preamble should also fix the problem:LaTeX3's regex engine doesn't abide by the same rules as
\patchcmd
, so you can directly replace} }
by}}
:1 Patching that bug with
etoolbox
is tricky because the patch would need to replace the sequence} }
by}}
. The issue with this is that you can't have unbalanced braces in the argument of\patchcmd
(of any macro, in fact). Actually, the braces are not really necessary, but we need some way to distinguish the space we actually want to remove from, say, the one betweenPreprint
andsubmitted
.The end of the definition of
\ps@pprintTitle
reads:The patch I proposed above hooks at the four consecutive
\fi
in the macro and appends\afterassignment\fix@elsarticle\let\@tempa
to them:When the code execution arrives there, the four
\fi
do their thing as usual and disappear.\afterassignment
stores the token\fix@elsarticle
in a temporary memory which will be retrieved after the next assignment. The very next thing is\let\@tempa}
. This instruction stores the token}
in\@tempa
(the same as\egroup
) and as a consequence, removes it from the token stream. However now (keep this in mind) we have unbalanced TeX's brace count by removing a}
.But notice that what just happened (
\let
) was an assignment. TeX now triggers the\afterassignment
token\fix@elsarticle
, which then expands to its definition. So far, the input stream looks like this:Now the
\iffalse
expands consuming the{
. This brace removal balances out the other brace we removed before, and the very next token is a}
, which acts as that same brace we removed. Now all that's left is\romannumeral-`0 }
.\romannumeral
starts by reading in-`0
, which is some negative value. Then, as other TeX primitives which scan a number, it consumes an optional space after the number, which finally removes the pesky space. However, since the read integer is negative, the expansion of\romannumeral
is empty and the rest of the code runs fine. What a ride :-)