0

I am producing a document with different widths using the varwidth package. While writing the content, I only work with one width at the time. For final production, the content is copied and pasted into a setup like this:

\documentclass[varwidth, multi = environment]{standalone}

\begin{document}

\standaloneconfig{varwidth = 600px} \begin{environment} This is filler text. This is filler text. This is filler text. This is filler text. This is filler text. This is filler text. This is filler text. This is filler text. \end{environment}

\standaloneconfig{varwidth = 400px} \begin{environment} This is filler text. This is filler text. This is filler text. This is filler text. This is filler text. This is filler text. This is filler text. This is filler text. \end{environment}

\end{document}

I find that I sometimes want to format the content differently depending on the width. Because the content is automatically copied and pasted into the above setup, I do not want to change the content of each instance of {environment}. Instead I imagine a macro like this:

\newcommand{\wideornarrow}[2]{
    % If varwidth = 600px: Print #1.
    % If varwidth = 400px: Print #2.
}

I have not been able to correctly formulate the if statement in \wideornarrow{}{}. I found the following snippet in varwidth.sty, and thought that the test must involve\@vwid@, but that is possibly wrong:

% Choose the natural width or the declared width, whichever is smaller.
\ifdim\@vwid@<\hsize
    \hsize\@vwid@
\fi
user44413
  • 601

1 Answers1

1

Inside the varwidth block, the declared width is set as \hsize:

\documentclass[varwidth, multi = environment]{standalone}

\ExplSyntaxOn \cs_new:Npn \compareWidth { \dim_compare:nNnTF \hsize } \ExplSyntaxOff

\begin{document}

\NewDocumentCommand\myMacro{}{% \compareWidth>{500bp}{% This is a wide block. }{% This is a narrow block. }% }

\standaloneconfig{varwidth = 600bp} \begin{environment} \myMacro This is filler text. This is filler text. This is filler text. This is filler text. This is filler text. This is filler text. This is filler text. This is filler text. \end{environment}

\standaloneconfig{varwidth = 400bp} \begin{environment} \myMacro This is filler text. This is filler text. This is filler text. This is filler text. This is filler text. This is filler text. This is filler text. This is filler text. \end{environment}

\end{document}

Resulting in two pages:

enter image description here

and

enter image description here