1

If I set content into a box that is not wide enough (0pt in the MWE below), I get an overfull mesage displayed in the console. Can I obtain the maximum value reported in the messages

Overfull \hbox (XXXXX too wide)

after typsetting the contents into a \savebox?

Below, I am manually setting

\setlength{\OverfullSize}{77.16191pt}

and am looking for a way to get the actual value reported as XXXXX.

enter image description here

Notes:

Code:

\documentclass[fleqn]{article}
\usepackage{mathtools}

\usepackage{printlen}
\uselengthunit{pt}

\usepackage{varwidth}
%% https://tex.stackexchange.com/questions/394778/align-in-varwidth-seems-to-ignore-fleqn-option
\makeatletter\let\@vwid@eqmodetrue\@vwid@eqmodefalse\makeatother


\newsavebox{\TempSavebox}
\newcommand*{\DetermineOverfullSize}[2]{%
    \savebox\TempSavebox{%
        \begin{varwidth}{0pt}%
            #2%
        \end{varwidth}%
     }%
     \setlength{\OverfullSize}{77.16191pt}% <-- How to determine the max overfull \hbox?
     \usebox{\TempSavebox}\par%
}

\newcommand*{\MyContentA}{%
\begin{align*}
    y &= mx + b \\
    F &=ma
\end{align*}%
}

\newcommand*{\MyContentB}{%
\begin{align*}
    y &= mx + b \\
    \shortintertext{and}
    F &=ma
\end{align*}%
}


\newlength{\OverfullSize}
\begin{document}
\DetermineOverfullSize{\OverfullSize}{\MyContentA}
\hrule
Above box is overfull by: \printlength{\OverfullSize},

\DetermineOverfullSize{\OverfullSize}{\MyContentB}
\hrule
Above box is overfull by: \printlength{\OverfullSize}
\end{document}
  • 1
    similar to your last question. In classic tex you can't take the box apart (as the mathon.mathoff nodes do not have \unskip equivalents so the only way "from the outside" is to parse the log file. If you know it is an ams alignment and you change the code of align to record all the widths it sees in some global place then perhaps... So not necessarily impossible but not that easy. (luatex would be easier) – David Carlisle Oct 8 '17 at 20:08
  • @DavidCarlisle: If I can't easily get theactual value, is it possible to at least detect if an overfull \hbox did or did not occurr? within a \savebox{}. – Peter Grill Oct 8 '17 at 21:06
  • Short answer no. Longer answer tex is turing complete so if you are prepared to throw enough code at it, probably yes. (this question is I suspect harder than you think it should be:-) – David Carlisle Oct 8 '17 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.