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
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.
- 117,160
-
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 '17 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 '17 at 17:23
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.
- 54,637
-
1
-
1
-
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 08 '19 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 '22 at 03:03
-
@user32882 Where does it say paragraph range? As for your second question,
lipsumalways 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 '22 at 07:14 -
@doncherry I'd argue that a correct and user friendly implementation of a lorem-ipsum package should take that into consideration. Extremely counterintuitive for a package user to think in terms of "paragraph ranges" – user32882 Apr 27 '22 at 07:18
-
@user32882 As for user-friendliness – I don't disagree with that, and you're welcome to implement such a package. Don't forget that LaTeX packages are typically programmed by volunteers in their spare time! – doncherry Apr 27 '22 at 15:45
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.
- 8,838
-
4The package doesn't work as advertised: it prints whole Lorem Ipsum paragraphs regardless of options. – Evan Aad Jul 28 '17 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 '17 at 11:47
-
-
1blindtext 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 '17 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 '17 at 17:24
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}