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