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.

4
  • do you want to decide based on the paragraph before? (easy) or after? (a bit harder) or both? (same as after) Commented Aug 9, 2021 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
    Commented Aug 9, 2021 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. Commented Aug 9, 2021 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
    Commented Aug 10, 2021 at 9:19

1 Answer 1

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.

2
  • 2
    Would this approach work if the "previous" paragraph were set in a \vbox? That is to say, can this technique be used to count paragraph lines before actually setting the paragraph onto paper? Commented Aug 10, 2021 at 9:45
  • 1
    @StevenB.Segletes so long as you do it inside the vbox yes Commented Aug 10, 2021 at 9:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .