43

The sections of text generated by lipsum are generally several lines long. Is there a simple way to generate shorter segments of random (generic) text (other than typing it, of course)?

4 Answers 4

27

This is a home brewed macro called \loremlines. Call as \loremlines{number of lines}. Note differences in multi column texts.

% Split a box into two
\documentclass{article}
\usepackage{lipsum,multicol}
\begin{document}
\newbox\one
\newbox\two
\long\def\loremlines#1{%
    \setbox\one=\vbox {%
       Test.\footnote{a footnote}%
      \lipsum\footnote{Another footnote.}%
     }
   \setbox\two=\vsplit\one to #1\baselineskip
   \unvbox\two}
\begin{multicols}{2}
\small
\loremlines{16}
\end{multicols}
\begin{multicols}{2}
\small
\loremlines{16}
\end{multicols}
\loremlines{5}
\end{document}

The code works by placing the contents of a \lipsum command in a box and then splitting it, at n\baselineskip, where n is the number of lines.

2
  • This is fantastic! When I apply this to an itemized list, it changes the alignment of the bullets. Is there any way to keep this from happening?
    – Mike L
    Jun 19, 2017 at 17:43
  • @MikeL I am sure there is a way. Don't you want to pose this as a new question, people like David Carlisle can provide a more skillful answer.
    – yannisl
    Jun 21, 2017 at 17:23
26

You could copy and paste paragraphs of the desired length from http://www.blindtextgenerator.com/. Obviously, this is no LaTeX or packaged version.


Btw, if you'd want to stick with lipsum, it seems to me that \lipsum[66] and \lipsum[75] are the shortest paragraphs, each generating almost exactly four lines with article standard settings.

Here's how I counted the lines:

\documentclass{article}

\usepackage{lipsum,lineno}

\makeatletter
\renewcommand{\lips@par}% patching lipsum's the end-of-paragraph command
        {\par\section{~~\the\c@linenumber}%extra space for ToC
        \resetlinenumber}
\makeatother

\begin{document}

\tableofcontents

\linenumbers\noindent
\lipsum[1-150]

\end{document}

And then I went through the ToC by hand, i.e. by eye. LuaTeX probably could've done it automatically.

7
  • 1
    ... and has moreorless the same functionality as lipsum.org
    – yo'
    Mar 17, 2012 at 20:58
  • 1
    @tohecz: Yes, but a cleaner interface :)
    – doncherry
    Mar 17, 2012 at 22:14
  • 3
    "...it seems to me that \lipsum[66] and \lipsum[75] are the shortest paragraphs..." and that is why I love internet. A brave soul has already gone through at least 75 paragraphs of lorem ipsum to find the shortest paragraphs. Thank you dear brother/sister.
    – Pouya
    May 8, 2019 at 10:49
  • What on earth is a "paragraph range"? Why didn't they just set it up so we can select a number of lines?
    – user32882
    Apr 27, 2022 at 3:03
  • @user32882 Where does it say paragraph range? As for your second question, lipsum always produces exactly the same text, no matter what your document is like. Outputting a certain number of lines, on the other hand, would be highly dependent on your font, font size, line width etc. and thus be a lot more complex to program.
    – doncherry
    Apr 27, 2022 at 7:14
16

The blindtext-package offers some optional settings:

\documentclass[english]{article}
\usepackage{babel}
\usepackage[pangram]{blindtext}
\begin{document}
\Blindtext[5][3]%5 paragraphs, each 3 pangrams
\end{document}

Remark: The pangram option was introduced this January 2012 with version 2.0. Maybe you need an update.

5
  • 4
    The package doesn't work as advertised: it prints whole Lorem Ipsum paragraphs regardless of options.
    – Evan Aad
    Jul 28, 2017 at 10:54
  • @EvanAad Do you use babel and define a language? (If yes: which language?) The option pangram is ignored if you determine no language. Then it uses Lorem Ipsum as a fall back.
    – knut
    Jul 28, 2017 at 11:47
  • No, I didn't use babel. Is babel a requirement for using blindtext?
    – Evan Aad
    Jul 28, 2017 at 12:31
  • 1
    blindtext is language sensitive. Without a defined language some feature use default texts. In your case, pangram has no short texts and so you get a long text.
    – knut
    Jul 28, 2017 at 16:34
  • OK, now it works, but every time I use it I get a different paragraph, even if the option is the same.
    – Evan Aad
    Jul 28, 2017 at 17:24
5

Building upon the answer of @YiannisLazarides - if you want to use a shorter lipsum text in, say, a caption: you can "expand" the lipsum text, and then you can use the xstring package to obtain a substring for a given length of characters from that; called it \loremnchars, where \loremnchars[5]{255} will return first 255 characters of the 5th paragraph (\lipsum[5]):

\documentclass{article}

\usepackage[nopar]{lipsum}
\usepackage{xstring}
% https://tex.stackexchange.com/a/26808/2595
\makeatletter
\def\unpacklipsum#1#2#3{%
  \count@=#1\relax
  \advance\count@\m@ne
  \def#3{}%
  \loop\ifnum\count@<#2\relax
    \advance\count@\@ne
    \edef#3{#3\csname lipsum@\romannumeral\count@\endcsname}%
  \repeat}
\makeatother

\def\loremnchars[#1]#2{%
  \unpacklipsum{#1}{#1}{\myunpacked}%
  \StrMid{\myunpacked}{1}{#2}% same as \StrLeft{\myunpacked}{#2}
}

\usepackage{caption}

\begin{document}

\begin{center}
\captionof{figure}[justmy]{Just my image; \loremnchars[5]{255} ...}
\end{center}

\end{document}
1
  • 1
    Good solution. It might need a \protect in the caption though.
    – yannisl
    Mar 31, 2014 at 18:41

You must log in to answer this question.

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