1

I am trying to find a way to get LaTeX to insert a different amount of vertical space depending on how much text there is in a specific environment:

For two single lines I'd like one kind of space (say \smallskip) for everything longer another one (e.g. \bigskip).

The environment is like \quote; it can be modified for the whole document but should be the same regardless of how much text it contains, i.e. I would like LaTeX to do the measuring and calculating.

I am using luaLaTeX anyway, so a solution using its specific abilities would also be very welcome.

To illustrate:

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

If I put the whole environment into a box I could measure the width of the text but loose the paragraphs.

Florian
  • 2,919
  • do you want to decide based on the paragraph before? (easy) or after? (a bit harder) or both? (same as after) – David Carlisle Aug 09 '21 at 13:10
  • I'd prefer a solution that counts the total lines in the environment. But in nearly all cases counting the lines before the command would be sufficient as the part after the command is the translation of the first part and therefor nearly always ca. of the same length. – Florian Aug 09 '21 at 14:54
  • 1
    number of lines in the previous paragraph is a tex primitive (even in classic tex) so \par\ifnum\prevgraf>2 \bigskip \else \smallskip\fi is all you need. – David Carlisle Aug 09 '21 at 15:12
  • Thanks a lot @DavidCarlisle ! If you care about reputation I am happy to accept that if you turn it into an answer. Note to self -- again: study plain TeX... – Florian Aug 10 '21 at 09:19

1 Answers1

3

The number of lines in the previous paragraph is a tex primitive (even in classic tex) so

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

is all you need to test the first paragraph.

If you need to look ahead to test the second paragraph it's rather more complicated although a simple check would be to have the same test at the end, after the second paragraph, and then warn if they are not both short or both long.

David Carlisle
  • 757,742