Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

\lipsum word count option?

1,547 views
Skip to first unread message

Haines Brown

unread,
Sep 12, 2013, 9:21:09 AM9/12/13
to
I would like to use \lipsum while specifying the number of words it
generates. Its manual does not seem to address this option, but on-line
sites offer to generate lipsum text with number of words specified.

How do I specify word count for the \lipsum command?

Haines Brown

Enrico Gregorio

unread,
Sep 12, 2013, 11:20:09 AM9/12/13
to
There's nothing of this kind; lipsum is just a collection of
150 paragraphs and \lipsum prints those from 1 to 7, while you
can print one of them with \lipsum[42] or a range with \lipsum[7-12].

Ciao
Enrico

Haines Brown

unread,
Sep 12, 2013, 1:49:17 PM9/12/13
to
Enrico Gregorio <Facile.d...@in.rete.it> writes:

> Haines Brown <hai...@histomat.net> wrote:
>
>> I would like to use \lipsum while specifying the number of words it
>> generates.

> There's nothing of this kind

Thanks, Enrico!

No wonder I couldn't find the option. Wie schade! If my skills were up
to it I supposd I could build a macro that would terminate /lipsum
output after a specified number of words. I suppose this is what on-line
providers of lipsum text do when you specify how many words you want.

Haines

Jean-Côme Charpentier

unread,
Sep 12, 2013, 6:14:48 PM9/12/13
to
Le 12/09/2013 19:49, Haines Brown a �crit :
> Enrico Gregorio<Facile.d...@in.rete.it> writes:
>
>> Haines Brown<hai...@histomat.net> wrote:
>>
>>> I would like to use \lipsum while specifying the number of words it
>>> generates.
>
>> There's nothing of this kind
>
> Thanks, Enrico!
>
> No wonder I couldn't find the option. Wie schade! If my skills were up
> to it I supposd I could build a macro that would terminate /lipsum
> output after a specified number of words.

Like that?

\documentclass{article}
\usepackage{lipsum}

\makeatletter
\begingroup
\gdef\wholelipsum{}
\def\lips@par{ \par}%
\count@=\@ne
\@whilenum\count@<151\do{%
\xdef\wholelipsum{%
\wholelipsum
\csname lipsum@\romannumeral\count@\endcsname
}%
\advance\count@\@ne
}
\xdef\wholelipsum{%
\wholelipsum
\space
}
\endgroup
\long\def\reach@max#1 {%
\def\@arg{#1}%
\ifx\@arg\@nnil
\else
\advance\count@\@ne
\expandafter \reach@max
\fi
}
\count@=\z@
\expandafter\expandafter\expandafter\reach@max\expandafter\wholelipsum\expandafter\@nil\space
\edef\lipsum@last@word{\the\numexpr\count@-1}%

\newcommand*\lipsumword[1][]{%
\parse@arg#1-\@nil-%
\expandafter\reach@firstword\wholelipsum\@nil
}
\def\parse@arg#1-{%
\def\@arg{#1}%
\ifx\@arg\empty
\def\first@word{1}%
\def\last@word{100}%
\expandafter\parse@@@arg
\else
\def\first@word{#1}%
\ifnum\first@word>\lipsum@last@word
\PackageWarning{lipsumword}
{There are 'only' \lipsum@last@word\space words
in lipsum.}%
\edef\first@word{\lipsum@last@word}%
\fi
\expandafter\parse@@arg
\fi
}
\def\parse@@arg#1-{%
\def\@arg{#1}%
\ifx\@arg\@nnil
\edef\last@word{\the\numexpr\first@word+99}%
\ifnum\last@word>\lipsum@last@word
\PackageWarning{lipsumword}
{There are 'only' \lipsum@last@word\space words
in lipsum.}%
\edef\last@word{\lipsum@last@word}%
\fi
\else
\def\last@word{#1}%
\ifnum\last@word>\lipsum@last@word
\PackageWarning{lipsumword}
{There are 'only' \lipsum@last@word\space words
in lipsum.}%
\def\last@word{\lipsum@last@word}%
\fi
\expandafter\parse@@@arg
\fi
}
\def\parse@@@arg#1\@nil-{}
%
\def\reach@firstword{%
\count@=\z@
\reach@@firstword
}
\long\def\reach@@firstword#1 {%
\advance\count@ \@ne
\ifnum\count@=\first@word\relax
#1
\expandafter\reach@@lastword
\else
\expandafter\reach@@firstword
\fi
}
\long\def\reach@@lastword#1 {%
\advance\count@ \@ne
\ifnum\count@>\last@word\relax
\expandafter\kill@nil
\else
#1
\expandafter\reach@@lastword
\fi
}
\long\def\kill@nil#1\@nil{}

\begin{document}
\begin{flushright}
\lipsumword[1-10]\par
\lipsumword[5-10]\par
\lipsumword[8-10]\par
\lipsumword[9-10]\par
\lipsumword[10-10]\par
\end{flushright}

\lipsumword[11-20]\par
\lipsumword[11-16]\par
\lipsumword[11-13]\par
\lipsumword[11-12]\par
\lipsumword[11-11]\par
\end{document}

Jean-C�me Charpentier

Haines Brown

unread,
Sep 13, 2013, 7:08:26 AM9/13/13
to
Well, Jean-Côme, thank you for the supercharged answer to my question. I
tried the code out and it worked well without problem.

Haines
0 new messages