0

I have this command \loremlines{n} which makes n lines of lipsum text. However, it does not work well with \lettrine (as seen below). I also want to be able to use the command in other environments as well, and thus want a more "general" command \loremlines that can be used in a lot of situations, not just with lettrine.

MWE:

\documentclass{article}

\usepackage{lettrine}
\usepackage{lipsum,multicol}

% This is from a .sty file:
\RequirePackage{parskip}

\newbox\one
\newbox\two
\long\def\loremlines#1{%
    \setbox\one=\vbox {%
      \lipsum%
     }
   \setbox\two=\vsplit\one to #1\baselineskip
   \unvbox\two}

\begin{document}

\lettrine{1}{} \textbf{Step 1} \loremlines{3}

\section{\loremlines{1}}

\begin{center}
\begin{tabular}{|p{0.47\textwidth}|p{0.47\textwidth}|}
    \hline
    {\loremlines{2} } & {\loremlines{3} } \\
    \hline
\end{tabular}
\end{center}

\loremlines{2}

\end{document}

Result:

enter image description here

Result without parskip (almost desired output):

enter image description here

I would like for the text to continue on the same line as "step 1".

Alternativley, I can live with a command that prints n words of lipsum.

To be clear: I just want the command to print words from lipsum, that is approximatley n lines long. Is there some way of counting LaTeX line breaks and just keep printing words untill n line breaks have been reached? I want it to follow whatever formatting it currently is in. If it is called in the middle of a paragraph, it should just keep going inside that paragraph without starting a new one.

4
  • you can't usefully have a dropped capital with unboxed lines as the paragraph will never reflow to make a cut-out. In the second example, as you only cut one line and have a paragraph indent, it sort of almost accidentally seems to work. What is the intention for the boxing/unboxing? Oct 29, 2022 at 20:00
  • @DavidCarlisle I found the command here: tex.stackexchange.com/a/48404/199568
    – Vebjorn
    Oct 29, 2022 at 20:32
  • 1
    but there he's generating specific junk lipsum lines with fixed text for a test file, not some formatting macro designed to take arbitrary text, and definitely not to generate text that must be reformatted Oct 29, 2022 at 20:37
  • following your edit note tex breaks paragraphs by a least cost optimization over the whole paragraph it does not break line by line so you can not "stop after n lines" which is why your lines macro in the question takes an entire paragraph and splits off 3 lines Oct 30, 2022 at 8:12

2 Answers 2

2

I don't see any relevance with the parskip package.

You have to include the start of the paragraph designed by "letrine" to the splitted box. I suggest to set second parameter of the macro \loremlines which grabs the start of the paragraph:

\documentclass{article}
\usepackage{lettrine}
\usepackage{lipsum,multicol}
% This is from a .sty file:
\RequirePackage{parskip}

\def\afterfi#1#2\fi{\fi#1}
\def\loremlines{\futurelet\next\loremlinesA}
\def\loremlinesA{\ifx\next[\afterfi{\loremlinesB}\else\afterfi{\loremlinesB[]}\fi}

\long\def\loremlinesB[#1]#2{%
    \setbox0=\vbox {%
      \penalty0
      \ifx^#1^\else #1\hfil\break \fi
      \lipsum%
     }
   \setbox2=\vsplit0 to0pt
   \setbox0=\vsplit0 to \numexpr#2\ifx^#1^\else+1\fi\baselineskip
   \unvbox0 
}

\begin{document}

\loremlines [\lettrine{1}{} \textbf{Step 1}] {4} 

\bigskip
\loremlines {4}

\end{document}
4
  • Is it possible to make the second argument optional and also have the text continue after step 1?
    – Vebjorn
    Oct 29, 2022 at 21:18
  • The "step 1" text is part of the lettrine composition and the "lettrine" must be started after \setbox0=\vbox{. So, you cannot have the text "step 1" after \setbox0=\vbox{. I created a new version of your \loremlines with optional parameter.
    – wipet
    Oct 30, 2022 at 6:23
  • I removed \hfill\break from your command and somehow it worked.
    – Vebjorn
    Oct 30, 2022 at 9:59
  • 1
    Maybe, you don't want to print next line after the text "Step 1".
    – wipet
    Oct 30, 2022 at 10:15
1

You can not reflow a boxed paragraph, so invert the order of operations:

enter image description here

\documentclass{article}

\usepackage{lettrine}
\usepackage{lipsum,multicol}

% This is from a .sty file:
\RequirePackage{parskip}

\newbox\one
\newbox\two
\newcommand\loremlines[3]{%
    \setbox\one=\vbox {%
      \lettrine{#1}{} \textbf{#2} \lipsum%
     }
   \setbox\two=\vsplit\one to #3\baselineskip
   \unvbox\two}

\begin{document}

\loremlines{1}{Step 1}{3}

\end{document}
6
  • I would like to use this command for other dummy text as well, is that possible? The command does not have to be formatted that way, as long as it achives what I want.
    – Vebjorn
    Oct 29, 2022 at 20:37
  • well obviously you can replace \lipsum by #4 and pass in whatever text you want as a fourth argument @Vebjorn Oct 29, 2022 at 20:39
  • not quite what I meant. I mean I want to use it in a similar way you use the \lipsum command.
    – Vebjorn
    Oct 29, 2022 at 21:08
  • @Vebjorn lipsum is not used in any essential way here, replace it by whatever text you want Oct 29, 2022 at 21:11
  • You misunderstood. I want to be able to use it without \lettrine as well: \loremlines{3} I want a "more general" command that I can apply in different situations.
    – Vebjorn
    Oct 29, 2022 at 21:14

You must log in to answer this question.

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