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.
Notes:
- Requiring multiple passses is acceptable.
- Having a solution to this would let me solve my earlier question: Determine natural width of align*: varwidth uses \linewidth even though display is correct.
- Somewhat related question: Fit text into given box by adjusting the fontsize
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}

\unskipequivalents 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 08 '17 at 20:08overfull \hboxdid or did not occurr? within a\savebox{}. – Peter Grill Oct 08 '17 at 21:06