Views
8 months ago

sample

Code 1 % 2

Code 1 % 2 〈∗package〉 3 \newcounter{lips@count} 4 \setcounter{lips@count}{0} 5 6 \def\lips@par{\par}% 7 8 \DeclareOption{nopar}{\let\lips@par\relax} 9 \ProcessOptions 10 11 \newcommand\lips@default{1-7} 12 \newcommand\setlipsumdefault[1]{% 13 \renewcommand{\lips@default}{#1}} 14 15 \newcommand\lips@dolipsum{% 16 \ifnum\value{lips@count}

48 \def\lips@get#1-#2;{\def\lips@min{#1}\def\lips@max{#2}} 49 \def\lips@stripmax#1-{\edef\lips@max{#1}} 50 \def\lips@minmax#1{% 51 \lips@get#1-\relax;% 52 \edef\lips@tmpa{\lips@max}% 53 \edef\lips@relax{\relax}% 54 \ifx\lips@tmpa\lips@relax\edef\lips@max{\lips@min}% 55 \else\expandafter\lips@stripmax\lips@max\fi% 56 } 57 58 \newcommand\lipsumexp{} 59 60 \newcommand\unpacklipsum{% 61 \@ifstar\@@unpacklipsum\@unpacklipsum 62 } \@@unpacklipsum \@unpacklipsum This macro is called by the starred version \unpacklipsum*. It calls \ChangeLipsumPar in a group and subsequently calls \@unpacklipsum with its argument. 63 \newcommand\@@unpacklipsum[1][\lips@default]{% 64 \begingroup 65 \ChangeLipsumPar 66 \@unpacklipsum[#1]% 67 \endgroup 68 } This is the true work horse for the \unpacklipsum and \unpacklipsum* macros. The major part consists of the loop posted by egreg. 69 70 \newcommand\@unpacklipsum[1][\lips@default]{% 71 In both the package option definition for nopar as well as in \ChangeLipsumPar, \lips@par is \let to be \relax and not \defed. Thus, \lips@par would not be expanded. I use a group, test whether \ifx\lips@par\relax is true and then locally \def \lips@par to \relax, which subsequently can can be expanded: 72 \begingroup 73 \ifx\lips@par\relax\def\lips@par{\relax}\fi Now process the argument as in \@lipsum and set the counter 74 \expandafter\lips@minmax\expandafter{#1}% 75 \c@lips@count=\lips@min\relax 76 \advance\c@lips@count\m@ne Since we are in a group, a direct \edef of \lipsumexp would be long, thus I use an internal macro here... 77 \def\@lipsumexp{}% Now start the loop and populate the internal macro with the contents of Lorem ipsum. Since we are in a group, I had to polute the global context with \@lipsumexp. . . 78 \loop\ifnum\c@lips@count

Accessible Template Sampler