环境内的条件垂直空间命令

环境内的条件垂直空间命令

我正在尝试找到一种方法,让 LaTeX 根据特定环境中的文本量插入不同数量的垂直空间:

对于两条单行,我希望使用一种空格(比如说\smallskip),而所有较长的行使用另一种空格(例如\bigskip)。

环境就像\quote;它可以针对整个文档进行修改,但无论它包含多少文本都应该相同,即我希望 LaTeX 进行测量和计算。

无论如何,我都在使用 luaLaTeX,因此使用其特定功能的解决方案也将非常受欢迎。

为了显示:

\documentclass{article}

\newcommand{\varvspacehere}{\bigskip}

\begin{document}

Long passages of normal running text ...

\begin{quote}
Sometimes a short line.

\varvspacehere %this one should automatically only be a \smallskip
Sometimes short lines
\end{quote}

Long passages of normal running text ...

\begin{quote}
Sometimes several lines. Sometimes several lines. Sometimes several lines. Sometimes several lines.

\varvspacehere
Sometimes several lines. Sometimes several lines. Sometimes several lines. Sometimes several lines. The pairs are not always of the same length.
\end{quote}

Long passages of normal running text ...

\begin{quote}
Sometimes several lines. Sometimes several lines. Sometimes several lines. Sometimes several lines.

There can also be normal par-breaks within the text portions -- they should as they usually do.

\varvspacehere
Sometimes several lines. Sometimes several lines. Sometimes several lines. Sometimes several lines. The pairs are not always of the same length.

There can also be normal par-breaks within the text portions -- they should as they usually do and (ideally) not require aditional markup.
The environments can be quite long so pagebreaks can occur within.
\end{quote}

Long passages of normal running text ...

\end{document}

如果我把整个环境变成盒子我可以测量文本的宽度但丢失段落。

答案1

上一段中的行数是 tex 基本元素(即使在经典 tex 中也是如此),因此

\par
\ifnum\prevgraf>2 \bigskip \else \smallskip \fi

就是测试第一段所需要的全部内容。

如果您需要提前测试第二段,那么这会更加复杂,尽管一个简单的检查是在第二段之后的末尾进行相同的测试,然后如果它们不是都短或都长则发出警告。

相关内容