In an earlier question, align* in varwidth seems to ignore fleqn option, it appeared as if align* was not being properly handled by the varwidth environment. A "fix" was provided which results in the correct visual display. But, measuring the result still reports that the box is of \linewidth.
Note that the two varwidths report that same width of the box:
Question:
- How do I measure the natural width of content that contains the use of
align*?
Notes:
- This is a followup to align* in varwidth seems to ignore fleqn option.
Related Questions:
- Make box with minimum width (in math mode).
- [Determine value of overfull amount(Determine value of overfull amount).
- Fit text into given box by adjusting the fontsize.
Code:
\documentclass[fleqn]{article}
\usepackage{showframe}
\usepackage{varwidth}
\usepackage{mathtools}
\usepackage{printlen}
\uselengthunit{cm}
\newcommand*{\MyContent}{%
Using align*:
\begin{align*}
E &= mc^2
\shortintertext{and}
F &= ma
\end{align*}%
}%
\newsavebox{\MySaveBox}
\newlength{\WidthOfSaveBox}
\newcommand{\ShowWidth}[1]{%
\savebox{\MySaveBox}{#1}%
\settowidth{\WidthOfSaveBox}{\usebox{\MySaveBox}}%
\par\usebox{\MySaveBox}\par
WidthOfSaveBox=\printlength{\WidthOfSaveBox}%
\par\hrule
}%
\begin{document}
linewidth=\printlength{\linewidth}\hrule
\medskip
Inside of \verb|\parbox{0.5\linewidth}|:
\ShowWidth{%
\parbox{0.5\linewidth}{%
\MyContent%
}%
}
\medskip
Inside \verb|varwidth| (without patch):
\ShowWidth{%
\begin{varwidth}{\linewidth}
\MyContent
\end{varwidth}%
}
\medskip% Works visually, but still uses full width
%% https://tex.stackexchange.com/questions/394778/align-in-varwidth-seems-to-ignore-fleqn-option
\makeatletter\let\@vwid@eqmodetrue\@vwid@eqmodefalse\makeatother
Inside \verb|varwidth| (with patch):
\ShowWidth{%
\begin{varwidth}{\linewidth}
\MyContent
\end{varwidth}%
}
\medskip%% This works fine.
Inside \verb|varwidth| with non-display content:
\ShowWidth{Some text}
\end{document}


\intertextor just the math? Also, is supporting\intertexta required part of any solution? – Steven B. Segletes Oct 07 '17 at 01:27\intertextand do need\intertextsupport. – Peter Grill Oct 07 '17 at 01:39\intertextthen it really is full width as that is a paragraph set with lines the current\hsizewithout that you could dump the column width data saved by the first\@measuringtruepass of the alignment which will give you the max width of each column so you could in theory work something out, perhaps. – David Carlisle Oct 07 '17 at 07:42\intertextbe measured using\varwidthand then use the maximum of that and the displaymath to deternine the actual "natural" width? – Peter Grill Oct 07 '17 at 08:21\intertext{}then? – Peter Grill Oct 08 '17 at 05:08