基于 varwidth 的 If 语句

基于 varwidth 的 If 语句

我正在使用该软件包制作具有不同宽度的文档varwidth。在编写内容时,我一次只使用一种宽度。对于最终制作,将内容复制并粘贴到如下设置中:

\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}

我发现有时我想根据宽度以不同的方式格式化内容。由于内容会自动复制并粘贴到上述设置中,因此我不想更改每个实例的内容{environment}。相反,我设想了一个这样的宏:

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

我无法正确地制定中的 if 语句\wideornarrow{}{}。我在中找到了以下代码片段varwidth.sty,并认为测试必须涉及\@vwid@,但这可能是错误的:

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

答案1

在块内部varwidth,声明的宽度设置为\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}

生成两页:

在此处输入图片描述

在此处输入图片描述

相关内容