6

Is there a command that would typeset a some text (one paragraph), and then only actually put out the first N lines as formatted. It would mean that the last word might actually only be the first part of a hyphenated word. I like to make samples of a font at different text/leading sizes, and such a command would make this easier and prettier.

I use Lualatex if that makes a difference.

\documentclass{article}
\usepackage{blindtext}

\newcommand\firstnlines[2]{%
  #2 % want to print first #1 lines of #2 here
}

\begin{document}
\begin{minipage}{3in}
  % set fontsize & baselineskip here
  \firstnlines{8}{\blindtext}
\end{minipage}
\end{document}
1

1 Answer 1

9

enter image description here

\documentclass{article}
\usepackage{blindtext}

\newcommand\firstnlines[2]{{%
  \splittopskip=\ht\strutbox
  \vbadness10000
  \setbox0\vbox{{\strut#2}}% 
  \setbox2\vsplit0 to #1\baselineskip
  \unvbox2
}}

\begin{document}

8
\begin{minipage}[t]{3in}
  % set fontsize & baselineskip here
  \firstnlines{8}{\blindtext}
\end{minipage}

1
\begin{minipage}[t]{3in}
  % set fontsize & baselineskip here
  \firstnlines{1}{\blindtext}
\end{minipage}

3
\begin{minipage}[t]{3in}
  % set fontsize & baselineskip here
  \firstnlines{3}{\blindtext}
\end{minipage}

\end{document}
1
  • Amazing. Didn't quite appreciate how much easier this makes what I'm trying to do.
    – dedded
    Mar 2 at 2:13

You must log in to answer this question.

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