summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/kantlipsum
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2011-12-24 23:51:19 +0000
committerKarl Berry <karl@freefriends.org>2011-12-24 23:51:19 +0000
commit7af65506fa2152224f81b051fd958eb3dca5c1c2 (patch)
treeddd509586abf214f5ee0f9a2b4494da6140fdc08 /Master/texmf-dist/source/latex/kantlipsum
parent0c4528cceb79f3a737dfba22f77cfe787889f057 (diff)
kantlipsum 0.5 (24dec11)
git-svn-id: svn://tug.org/texlive/trunk@24935 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/kantlipsum')
-rw-r--r--Master/texmf-dist/source/latex/kantlipsum/kantlipsum.dtx248
1 files changed, 132 insertions, 116 deletions
diff --git a/Master/texmf-dist/source/latex/kantlipsum/kantlipsum.dtx b/Master/texmf-dist/source/latex/kantlipsum/kantlipsum.dtx
index 196b5be54ec..afe3325bb00 100644
--- a/Master/texmf-dist/source/latex/kantlipsum/kantlipsum.dtx
+++ b/Master/texmf-dist/source/latex/kantlipsum/kantlipsum.dtx
@@ -24,7 +24,7 @@
\usepackage{bookmark}
%</driver>
%<*driver|package>
-\GetIdInfo$Id: kantlipsum.dtx 0.1 2011-11-18 12:00:00Z Enrico $
+\GetIdInfo$Id: kantlipsum.dtx 0.5 2011-12-23 12:00:00Z Enrico $
{Dummy text in Kantian style}
%</driver|package>
%<*driver>
@@ -36,7 +36,7 @@
%
% \title{^^A
% The \textsf{kantlipsum} package\\ Dummy text in Kantian style^^A
-% \thanks{This file describes \ExplFileVersion
+% \thanks{This file describes version \ExplFileVersion,
% last revised \ExplFileDate.}^^A
% }
%
@@ -61,37 +61,42 @@
% found in \href{http://www.diveintopython.net/}{\emph{Dive into
% Python}}.
%
+% It has at least one advantage over \pkg{lipsum}: the text is in
+% English and so finding good hyphenation points should be less
+% problematic. On the contrary, the paragraphs are rather long, as
+% it's common in philosophical prose.
+%
% \section{Options}
%
% The package has three document options, the first two of which are
% alternative to each other:
% \begin{itemize}[font=\ttfamily]
-% \item[par$\,\vert\,$nopar] With the default \texttt{par} all pieces of text
-% will be ended by a \cs{par} command; specifying \texttt{par} is
-% optional; the option \texttt{nopar} will not add this \cs{par} at
-% the end of each fragment of Kantian prose.
-% \item[numbers] Each piece of Kantian prose will be preceded by its
-% number (such as in ``1~\textbullet~As any dedicated reader can
-% clearly see\dots'') which can be useful for better control of what
-% is produced.
+% \item[par$\,\vert\,$nopar] With the default \texttt{par} all pieces
+% of text will be ended by a \cs{par} command; specifying \texttt{par}
+% is optional; the option \texttt{nopar} will not add this \cs{par} at
+% the end of each fragment of Kantian prose.
+% \item[numbers] Each piece of Kantian prose will be preceded by its
+% number (such as in ``1~\textbullet~As any dedicated reader can
+% clearly see\dots''), which can be useful for better control of what
+% is produced.
% \end{itemize}
%
% \section{Commands}
%
% The commands provided by the package are:
% \begin{itemize}[font=\ttfamily]
-% \item[\cs{kant}] This command takes an optional argument which can
-% be of the form \texttt{[42]} (that is, only one integer) or
-% \texttt{[3-14]} (that is, two integers separated by a hyphen); as
-% in \pkg{lipsum}, \verb|\kant[42]|, \verb|\kant[3-14]| and
-% \verb|\kant| will produce the 42nd pseudokantian paragraph, the
-% paragraphs from the 3rd to the 14th, and those from the 1st to the
-% 7th, respectively.
-% \item[\cs{kant*}] The same as before, see later for the difference.
-% \item[\cs{kantdef}] This command takes two arguments, a control
-% sequence and an integer; the call \verb|\kantdef{\mytext}{164}|
-% will store in \cs{mytext} the 164th paragraph of pseudokantian
-% text provided by this package.
+% \item[\cs{kant}] This command takes an optional argument which can
+% be of the form \texttt{[42]} (that is, only one integer) or
+% \texttt{[3-14]} (that is, two integers separated by a hyphen); as in
+% \pkg{lipsum}, \verb|\kant[42]|, \verb|\kant[3-14]| and \verb|\kant|
+% will produce the 42nd pseudokantian paragraph, the paragraphs from
+% the 3rd to the 14th, and those from the 1st to the 7th,
+% respectively.
+% \item[\cs{kant*}] The same as before, see later for the difference.
+% \item[\cs{kantdef}] This command takes two arguments, a control
+% sequence and an integer; the call \verb|\kantdef{\mytext}{164}| will
+% store in \cs{mytext} the 164th paragraph of pseudokantian text
+% provided by this package.
% \end{itemize}
%
% What's the difference between \cs{kant} and \cs{kant*}? The normal
@@ -103,13 +108,23 @@
%
% By the way, 164 is the number of available pieces; if one exceeds
% the limit, nothing will be printed. Thus \verb|\kant[164-200]| will
-% print only \emph{one} paragraph.
+% print only \emph{one} paragraph. However, printing all paragraphs
+% with the standard ten point size Computer Modern font and the
+% \pkg{article} class fills more than fifty pages, so it seems that
+% the supply of text can be sufficient.
%
% \subsection*{Note}
%
% This package is just an exercise for practicing with \LaTeX3
% syntax. It uses the ``experimental'' packages made available by the
-% \LaTeX3 team.
+% \LaTeX3 team. Many thanks to Joseph Wright and Bruno Le Floch for
+% suggesting improvements.
+%
+% \subsection*{Changes from version 0.1}
+%
+% There's no user level change; the implementation has been modified
+% in some places (in particular a sequence is used to store the
+% phrases, rather than many token lists).
%
% \end{documentation}
%
@@ -143,18 +158,22 @@
%
% \subsection{Package options and required packages}
% We declare the allowed options and choose by default
-% \texttt{par}. We need also to declare a function |\kgl_number:n|
+% \texttt{par}. We also need to declare a function |\kgl_number:n|
% that is set by the \texttt{numbers} option; its default action is to
% gobble its argument.
% \begin{macrocode}
\DeclareOption { par }
- {\cs_set:Nn \kgl_star: { \c_space_tl }
- \cs_set:Nn \kgl_nostar: { \par } }
+ {
+ \cs_set:Nn \kgl_star: { \c_space_tl }
+ \cs_set:Nn \kgl_nostar: { \par }
+ }
\DeclareOption{ nopar }
- { \cs_set:Nn \kgl_star: { \par }
- \cs_set:Nn \kgl_nostar: { \c_space_tl } }
+ {
+ \cs_set:Nn \kgl_star: { \par }
+ \cs_set:Nn \kgl_nostar: { \c_space_tl }
+ }
\DeclareOption{ numbers }
- { \cs_set:Nn \kgl_number:n {#1~\textbullet\space} }
+ { \cs_set:Nn \kgl_number:n { #1\nobreakspace\textbullet\nobreakspace } }
\cs_new_eq:NN \kgl_number:n \use_none:n
\ExecuteOptions{par}
\ProcessOptions \scan_stop:
@@ -165,32 +184,30 @@
\RequirePackage{xparse}
% \end{macrocode}
%
-% \subsection{Variables and constants}
-% The |\l_kgl_start_tl| variable will contain the starting number for
-% processing, while |\l_kgl_end_tl| the ending number. The constant
-% |\c_kgl_total_tl| stores the total number of available pseudokantian
-% sentences.
-% \begin{macrocode}
-\tl_new:N \l_kgl_start_tl
-\tl_new:N \l_kgl_end_tl
-\tl_new:N \l_kgl_total_tl
-% \end{macrocode}
-%
-% There are many other constants containing the various sentences,
-% declaring them is just a waste of time; they will be set later.
-%
% \subsection{Messages}
% We define two messages.
% \begin{macrocode}
\msg_new:nnn {kantlipsum}{how-many}
- {The~package~provides~paragraphs~1~to~#1\\
- Values~outside~this~range~will~be~ignored}
+ {The~package~provides~paragraphs~1~to~#1.~
+ Values~outside~this~range~will~be~ignored.}
\msg_new:nnnn {kantlipsum}{already-defined}
- {Control~sequence~#1~defined}
- {The~control~sequence~#1~is~already~defined\\
+ {Control~sequence~#1~already~defined.}
+ {The~control~sequence~#1~is~already~defined,~
I'll~ignore~it}
% \end{macrocode}
%
+% \subsection{Variables and constants}
+% The |\l_kgl_start_int| variable will contain the starting number for
+% processing, while |\l_kgl_end_int| the ending number. The
+% |\g_kgl_pars_seq| sequence will contain the pseudokantian sentences.
+% Since we'll start counting them from one, we add a bogus zeroth element.
+% \begin{macrocode}
+\int_new:N \l_kgl_start_int
+\int_new:N \l_kgl_end_int
+\seq_new:N \g_kgl_pars_seq
+\seq_gput_right:Nx \g_kgl_pars_seq {This~is~the~Kant~lipsum~generator.}
+% \end{macrocode}
+%
% \subsection{User level commands}
% There are two user level commands, \cs{kant} (with a *-variant) and \cs{kantdef}.
%
@@ -200,91 +217,91 @@
% whether the `range form' has been specified. In the \cs{kant*}
% form we reverse the logic.
% \begin{macrocode}
-\NewDocumentCommand{\kant}{s>{\SplitArgument{1}{-}}o}{
- \group_begin:
- \IfBooleanTF{#1}
- { \cs_set_eq:NN \kgl_par: \kgl_star: }
- { \cs_set_eq:NN \kgl_par: \kgl_nostar: }
- \IfNoValueTF{#2}
- { \tl_set:Nn \l_kgl_start_tl {1} \tl_set:Nn \l_kgl_end_tl {7} }
- { \kgl_process:nn #2 }
- \kgl_print:
- \group_end:
-}
+\NewDocumentCommand{\kant}{s>{\SplitArgument{1}{-}}O{1-7}}
+ {
+ \group_begin:
+ \IfBooleanTF{#1}
+ { \cs_set_eq:NN \kgl_par: \kgl_star: }
+ { \cs_set_eq:NN \kgl_par: \kgl_nostar: }
+ \kgl_process:nn #2
+ \kgl_print:
+ \group_end:
+ }
% \end{macrocode}
% \end{function}
%
% \begin{function}{\kantdef}
-% Sometimes one needs just a piece of text without implicit \cs{par}
-% attached, so we provide \cs{kantdef}. In a group we neutralize the
-% meaning of |\kgl_number:n| and |\kgl_par:| and define the control
-% sequence given as first argument to the pseudokantian sentence
-% having the number given as second argument, which is stored in a
-% constant named |\c_kgl_i_tl| (number~1) or |\c_kgl_ii_tl|
-% (number~2) and so on, by converting the number to a Roman
-% numeral. If the given control sequence is already defined we issue
-% an error and don't perform the definition.
+% Sometimes one needs just a piece of text without implicit \cs{par}
+% attached, so we provide \cs{kantdef}. In a group we neutralize the
+% meaning of |\kgl_number:n| and |\kgl_par:| and define the control
+% sequence given as first argument to the pseudokantian sentence being
+% the $k$th element of the sequence containing them, where $k$ is the
+% number given as second argument. If the control sequence is already
+% defined we issue an error and don't perform the definition.
% \begin{macrocode}
-\NewDocumentCommand{\kantdef}{mm}{
- \group_begin:
- \cs_set_eq:NN \kgl_number:n \use_none:n
- \cs_set_eq:NN \kgl_par: \prg_do_nothing:
- \cs_if_exist:NTF #1
- { \msg_error:nnx {kantlipsum}{already-defined}
+\NewDocumentCommand{\kantdef}{mm}
+ {
+ \group_begin:
+ \cs_set_eq:NN \kgl_number:n \use_none:n
+ \cs_set_eq:NN \kgl_par: \prg_do_nothing:
+ \cs_if_exist:NTF #1
+ {
+ \msg_error:nnx {kantlipsum}{already-defined}
{\token_to_str:N #1}
- }
- { \cs_new:Npx #1 { \cs:w c_kgl_\int_to_roman:w #2 _tl \cs_end: } }
- \group_end:
-}
+ }
+ { \cs_new:Npx #1 { \kgl_use:n {#2} } }
+ \group_end:
+ }
% \end{macrocode}
% \end{function}
%
% \subsection{Internal functions}
% \begin{function}{\kgl_process:nn}
-% The function |\kgl_process:nn| sets the variables
-% |\l_kgl_start_tl| and |\l_kgl_end_tl|. If the optional argument to
-% \cs{kant} is missing they are already set to 1 and 7 respectively;
-% otherwise the argument has been split into its components; if the
-% argument was |[|$m$|]| we set both variables to $m$, otherwise it
-% was in the form |[|$m$|-|$n$|]| and we do the obvious action.
+% The function |\kgl_process:nn| sets the temporary variables
+% |\l_kgl_start_int| and |\l_kgl_end_int|. If the optional argument to
+% \cs{kant} is missing they are already set to 1 and 7 respectively;
+% otherwise the argument has been split into its components; if the
+% argument was |[|$m$|]| we set both variables to $m$, otherwise it
+% was in the form |[|$m$|-|$n$|]| and we do the obvious action.
% \begin{macrocode}
-\cs_new:Nn \kgl_process:nn {
- \tl_set:Nn \l_kgl_start_tl {#1}
- \IfNoValueTF{#2}
- { \tl_set:Nn \l_kgl_end_tl {#1} }
- { \tl_set:Nn \l_kgl_end_tl {#2} }
-}
+\cs_new:Nn \kgl_process:nn
+ {
+ \int_set:Nn \l_kgl_start_int {#1}
+ \IfNoValueTF{#2}
+ { \int_set:Nn \l_kgl_end_int {#1} }
+ { \int_set:Nn \l_kgl_end_int {#2} }
+ }
% \end{macrocode}
%\end{function}
%
-% \begin{function}{\kgl_print:}
+% \begin{function}{\kgl_print:,\kgl_use:n}
% The printing routine is in the function |\kgl_print:|; we start a
-% loop printing |c_kgl_|$x$|_tl| for all Roman numerals $x$ in the
-% specified range.
+% loop printing item number $x$ in the sequence |\g_kgl_pars_seq| for
+% all numbers $x$ in the specified range. The function |\kgl_use:n|
+% function is a wrapper to be used with |\prg_stepwise_function:nnnN|
+% that's also useful in the defining command |\kantdef|: it's passed a
+% number as argument, builds the constant name corresponding to it and
+% produces the text.
% \begin{macrocode}
-\cs_new_protected:Nn \kgl_print: {
- \int_set:Nn \l_tmpa_int {\l_kgl_start_tl}
- \int_do_until:nNnn \l_tmpa_int > \l_kgl_end_tl
- {
- \cs:w c_kgl_\int_to_roman:w \l_tmpa_int _tl \cs_end:
- \int_incr:N \l_tmpa_int
- }
-}
+\cs_new:Nn \kgl_print:
+ {
+ \prg_stepwise_function:nnnN
+ {\l_kgl_start_int} {1} {\l_kgl_end_int} \kgl_use:n
+ }
+\cs_new:Nn \kgl_use:n
+ {
+ \kgl_number:n {#1}
+ \seq_item:Nn \g_kgl_pars_seq {#1}
+ }
% \end{macrocode}
% \end{function}
%
% \begin{function}{\kgl_newpara:n}
-% The |\kgl_newpara:n| function defines the constants storing the
-% sentences. It increments the counter |\l_tmpa_int| and defines, say,
-% |\c_kgl_xxxxii_tl| to expand to\\
-% |\kgl_number:n {42}|\meta{text of the 42nd sentence}|\kgl_par:|
+% The |\kgl_newpara:n| appends a new item to the sequence |\g_kgl_pars_seq|
+% consisting of, say, \meta{text of the 42nd sentence}|\kgl_par:|
% \begin{macrocode}
-\cs_new:Nn \kgl_newpara:n {
- \int_incr:N \l_tmpa_int
- \tl_gset:cx {c_kgl_\int_to_roman:w \l_tmpa_int _tl}
- {\exp_not:N \kgl_number:n {\int_to_arabic:n \l_tmpa_int}
- \exp_not:n {#1\kgl_par:} }
-}
+\cs_new:Nn \kgl_newpara:n
+ { \seq_gput_right:Nn \g_kgl_pars_seq {#1\kgl_par:} }
% \end{macrocode}
% \end{function}
%
@@ -294,11 +311,10 @@
% spaces.
% \begin{macrocode}
\group_begin:
-\int_set:Nn \l_tmpa_int {0}
\char_set_catcode_space:n {`\ }
% \end{macrocode}
%
-% Then we provide all of the sentences with the pattern\\
+% Then we provide all of the sentences with the pattern
% |\kgl_newpara:n {|\meta{text}|}|
% \begin{macrocode}
\kgl_newpara:n {As any dedicated reader can clearly see, the Ideal of
@@ -3210,12 +3226,12 @@ whole content of philosophy.}
% \end{macrocode}
%
-% Finally we close the group and issue in the log file a message
+% Finally we close the group and issue a message in the log file
% stating how many sentences are available.
% \begin{macrocode}
\group_end:
-
-\msg_info:nnx{kantlipsum}{how-many}{ \int_to_arabic:n \l_tmpa_int }
+\msg_info:nnx{kantlipsum}{how-many}
+ { \int_eval:n {\seq_length:N \g_kgl_pars_seq - 1} }
% \end{macrocode}
% \iffalse
%</package>