[Tex/LaTex] elsarticle frontmatter: Overfull \hbox has occurred while \output is active

elsarticlefront-mattertemplateswarnings

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:

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:

\def\ps@pprintTitle{%
     \let\@oddhead\@empty
     \let\@evenhead\@empty
     \def\@oddfoot
       {\hbox to \textwidth%
        {\ifnopreprintline\relax\else
        \@myfooterfont%
         \ifx\@elsarticlemyfooteralign\@elsarticlemyfooteraligncenter%
           \hfil\@elsarticlemyfooter\hfil%
         \else%
         \ifx\@elsarticlemyfooteralign\@elsarticlemyfooteralignleft%
           \@elsarticlemyfooter\hfill{}%
         \else%
         \ifx\@elsarticlemyfooteralign\@elsarticlemyfooteralignright%
           {}\hfill\@elsarticlemyfooter%
         \else%
               Preprint submitted to \ifx\@journal\@empty%
                 Elsevier%
            \else\@journal\fi\hfill\@date\fi%
         \fi%
         \fi%
         \fi%
         }                     % <------------
       }%
     \let\@evenfoot\@oddfoot}

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):

  1. Copy the definition above to your document and add a % right after the } (and make sure to add \makeatletter and \makeatother around the definition):

             \fi%
             \fi%
             }% <--- Here
           }%
         \let\@evenfoot\@oddfoot}
    
  2. Make a local copy of elsarticle.cls and do the same.

  3. 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:

    \usepackage{etoolbox}
    \makeatletter
    \patchcmd\ps@pprintTitle
      {\fi\fi\fi\fi}
      {\fi\fi\fi\fi
       \afterassignment\fix@elsarticle\let\@tempa}
      {}{\FailedToPatch}
    \def\fix@elsarticle{\iffalse{\fi}\romannumeral-`0}
    \makeatother
    
  4. LaTeX3's regex engine doesn't abide by the same rules as \patchcmd, so you can directly replace } } by }}:

    \usepackage{regexpatch}
    \makeatletter
    \regexpatchcmd\ps@pprintTitle
      {\cE\}\ \cE\}}{\cE\}\cE\}}
      {}{\FailedToPatch}
    \makeatother
    

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 between Preprint and submitted.

The end of the definition of \ps@pprintTitle reads:

%            V space we want to remove
\fi\fi\fi\fi} }\let\@evenfoot\@oddfoot

The patch I proposed above hooks at the four consecutive \fi in the macro and appends \afterassignment\fix@elsarticle\let\@tempa to them:

%                              space we want to remove V
\fi\fi\fi\fi\afterassignment\fix@elsarticle\let\@tempa} }

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:

%                            V space we want to remove
\iffalse{\fi}\romannumeral-`0 }

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 :-)