summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/xpackages/xbase/ldcsetup.dtx
blob: b47930bc217515a2e6fd175abe7f672c46745c59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
% \iffalse
%% File: ldcsetup.dtx (C) Copyright 1999 Frank Mittelbach, Chris Rowley, David Carlisle
%%                    (C) Copyright 2004-2009 Frank Mittelbach, LaTeX3 Project
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
%% license or (at your option) any later version.  The latest version
%% of this license is in the file
%%
%%    http://www.latex-project.org/lppl.txt
%%
%% This file is part of the ``xbase bundle'' (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%%
%% The released version of this bundle is available from CTAN.
%%
%% -----------------------------------------------------------------------
%%
%% The development version of the bundle can be found at
%%
%%    http://www.latex-project.org/svnroot/experimental/trunk/
%%
%% for those people who are interested.
%%
%%%%%%%%%%%
%% NOTE: %% 
%%%%%%%%%%%
%%
%%   Snapshots taken from the repository represent work in progress and may
%%   not work or may contain conflicting material!  We therefore ask
%%   people _not_ to put them into distributions, archives, etc. without
%%   prior consultation with the LaTeX Project Team.
%%
%% -----------------------------------------------------------------------
%%
%<*driver|package>
\RequirePackage{expl3}
%</driver|package>
%\fi
\GetIdInfo$Id: ldcsetup.dtx 1628 2009-10-25 09:54:34Z mittelba $
       {coding conventions and stuff}
%\iffalse
%<*driver>
%\fi
\ProvidesFile{\filename.\filenameext}
  [\filedate\space v\fileversion\space\filedescription]
%\iffalse
\documentclass{l3doc}
\begin{document}
\DocInput{ldcsetup.dtx}
\end{document}
%</driver>
% \fi
%
% \CheckSum{0}
%
% \title{The \textsf{ldcsetup} package\thanks{This file
%         has version number \fileversion, last
%         revised \filedate.}}
% \author{DPC, FMi}
% \date{\filedate}
%  \maketitle
% 
% \begin{abstract}
%   Basic code shared by several other packages currently under development.
% \end{abstract}
%
% \StopEventually{}
%
%    \begin{macrocode}
%<*package>
\ProvidesExplPackage
  {\filename}{\filedate}{\fileversion}{\filedescription}
%    \end{macrocode}
%    \begin{macrocode}
\RequirePackage{keyval}
\RequirePackage{expl3}
\ExplSyntaxOff
%    \end{macrocode}
%
% \section{Ignoring White Space}
% Within a package, or in a document preamble, you can use
% |\IgnoreWhiteSpace| this makes white space ignored, and |@|
% a letter, and |~| a space character. It lasts until the end of the
% current package or preamble.
%
%% Puts an ignored space at the end of the line, so `|\ |' does the right
% thing. (Perhaps should instead just change catcode of |^^M|)
%    \begin{macrocode}
\def\IgnoreWhiteSpace{%
  \edef\@tempa{%
  \catcode`\noexpand\~=\the\catcode`\~\relax
  \catcode`\noexpand\ =\the\catcode`\ \relax
  \catcode`\noexpand\^^I=\the\catcode`\^^I\relax
  \catcode`\noexpand\@=\the\catcode`\@\relax
  \endlinechar=\the\endlinechar\relax
  }%
  \ifx\@currname\@empty
    \expandafter\AtBeginDocument\expandafter{\@tempa}%
  \else
    \expandafter\AtEndOfPackage\expandafter{\@tempa}%
  \fi
  \catcode`\~=10\relax
  \catcode`\ =9\relax
  \catcode`\^^I=9\relax
  \makeatletter
  \endlinechar=` %
  \relax
}
%    \end{macrocode}
%    The new syntax requires |:| and |_| to be letters; instead of
%    putting that into |\IgnoreWhiteSpace| we make a new command which
%    helps to gradually change packages from old to new syntax.
%    \begin{macrocode}
\def\InternalSyntaxOn{%
  \edef\@tempa{%
  \catcode`\noexpand\~=\the\catcode`\~\relax
  \catcode`\noexpand\ =\the\catcode`\ \relax
  \catcode`\noexpand\^^I=\the\catcode`\^^I\relax
  \catcode`\noexpand\@=\the\catcode`\@\relax
  \catcode`\noexpand\:=\the\catcode`\:\relax
  \catcode`\noexpand\_=\the\catcode`\_\relax
  \endlinechar=\the\endlinechar\relax
%FMi fix is not properly reset
  \endlinechar=13\relax
  }%
%%% ????
% this needs further work, don't think it is working
  \ifx\InternalSyntaxOff\relax
    \expandafter\def\expandafter\InternalSyntaxOff\expandafter
      {\@tempa\let\InternalSyntaxOff\relax}%
  \fi
  \ifx\@currname\@empty
    \expandafter\AtBeginDocument\expandafter{\@tempa}%
  \else
    \expandafter\AtEndOfPackage\expandafter{\@tempa}%
  \fi
  \catcode`\~=10\relax
  \catcode`\ =9\relax
  \catcode`\^^I=9\relax
  \makeatletter
  \catcode`\_=11\relax
  \catcode`\:=11\relax
  \endlinechar=` %
  \relax
}
\let\InternalSyntaxOff\relax
%    \end{macrocode}
%
% Do it for this package.
%    \begin{macrocode}
%\InternalSyntaxOn
\ExplSyntaxOn
%    \end{macrocode}
%
% \section{KV fixes}
% Allow\footnote{Not needed now?} key names to start with |\|.
%    \begin{macrocode}
\cs_set_nopar:Npn \define@key#1#2{%
  \@ifnextchar[
     {\KV@def{#1}{\string#2}}
     {\@namedef{KV@#1@\string#2}####1}}
\cs_set_nopar:Npn \setkeys#1#2{%
  \cs_set_nopar:Npn \KV@prefix{KV@#1@\expandafter\string}%
  \KV@do#2,\relax,}
%    \end{macrocode}
%
% Make KV |#| safe.
%    \begin{macrocode}
%    \end{macrocode}
%
%    \begin{macrocode}
\newtoks\KV@toks
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_set_nopar:Npn \KV@@sp@c#1\@nil#2\relax#3{\KV@toks{#1}\cs_set_nopar:Npx #3{\the\KV@toks}}
%    \end{macrocode}
%
% Generate error messages on missing `,'.
%
% More exactly if two `=' appear after a key generate an error.
% The current KV just silently ignores everything after the second `='.
%    \begin{macrocode}
\cs_set_nopar:Npn \KV@equal{=}
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_set_nopar:Npn \KV@split#1=#2=#3\relax{%
  \KV@@sp@def\@tempa{#1}%
  \cs_set_nopar:Npn \@tempd{#3}%
  \ifx\@tempa\@empty\else
    \expandafter\cs_set_eq:NN \expandafter\@tempc
      \csname\KV@prefix\@tempa\endcsname
    \ifx\@tempc\relax
      \KV@error{\@tempa\space \expandafter\@gobbletwo\string\@undefined}\@eha
    \else
      \ifx\@tempd\@empty
        \KV@default
      \else
        \KV@@sp@def\@tempb{#2}%
        \ifx\@tempd\KV@equal
          \expandafter\@tempc\expandafter{\@tempb}\relax
        \else
          \KV@error{Extra~=~ sign~ after~ `#1'}\KV@erry
        \fi
      \fi
    \fi
  \fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_set_nopar:Npn \KV@erry{\expandafter\KV@errx\meaning\@tempd\relax ignored\MessageBreak
             missing~comma~in~`\expandafter\strip@prefix\meaning\@tempb'~?}
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_set_nopar:Npn \KV@errx#1>#2==\relax{%
 `#2' }
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_set_nopar:Npn \KV@default{%
  \expandafter\cs_set_eq:NN \expandafter\@tempb
    \csname\KV@prefix\@tempa @default\endcsname
  \ifx\@tempb\relax
    \KV@error{No value specified for \@tempa}\@eha
  \else
    \@tempb\relax
  \fi}
%    \end{macrocode}
%
% \LaTeX\ style error message.
%    \begin{macrocode}
\cs_set_nopar:Npn \KV@error#1#2{\PackageError{keyval}{#1}{#2}}
%    \end{macrocode}
%
% Instead of doing a full KV parse, and evaluating all the keys,
% you might want to parse a parameter list, even for undefined keys,
% removing spaces, splitting up the `,` and `=' and resolving cases
% where no value is supplied. This is used in |\DeclareGenericFunction|
% which \emph{defines} a set of keys via such a KV parse.
%
% A setting of |, key = value ,| will result in |\KV@elt{key}{value}|
% being added to the list, a seting of |, key ,| will result in
% |\KV@default@elt{key}| being added. At the end of the parse the list
% is executed. No keys are checked at this stage (so no csnames are used
% up) the two |\KV|\ldots|@elt| commands must be defined as appropriate.
%
%    \begin{macrocode}
\cs_set_nopar:Npn \KV@parse#1{
  \begingroup
%    \end{macrocode}
%
% Locally fudge |\KV@@def| to just add to a token register
% rather than make a definition.
%    \begin{macrocode}
\cs_set_nopar:Npn \KV@@sp@c##1\@nil##2\relax##3{\addto@hook##3{{##1}}}
%    \end{macrocode}
%
% Locally fudge |\KV@split| to just add to a token register
% rather than execute the code for the found keys.
%    \begin{macrocode}
\cs_set_nopar:Npn \KV@split##1=##2=##3\relax{%
  \cs_set_nopar:Npn \@tempd{##3}%
  \expandafter\ifx\expandafter=\@firstofone##1=\else
      \ifx\@tempd\@empty
        \addto@hook\KV@toks\KV@default@elt
        \KV@@sp@def\KV@toks{##1}%
      \else
        \ifx\@tempd\KV@equal
          \addto@hook\KV@toks\KV@elt
          \KV@@sp@def\KV@toks{##1}%
          \KV@@sp@def\KV@toks{##2}%
        \else
          \KV@err{Extra `=' after `##1'}\@ehd
        \fi
    \fi
  \fi}
%    \end{macrocode}
%
% Initialise
%    \begin{macrocode}
  \KV@toks{}
%    \end{macrocode}
% Do the parse
%    \begin{macrocode}
   \KV@do#1,\relax,
%    \end{macrocode}
% Evaluate the token register outside the group.
%    \begin{macrocode}
  \expandafter
  \endgroup
  \the\KV@toks}
%    \end{macrocode}
%
% \section{Calc fixes}
%
% Count Register assignments via calc. Here we also provide some
% global versions since a normal global prefix won't have any effect.
%    \begin{macrocode}
\cs_set_eq:NN \SetInternalCounter \calc_int_set:Nn
\cs_set_eq:NN \GSetInternalCounter\calc_int_gset:Nn
%    \end{macrocode}
%
%
% \section{Misc code that is best collected in one place}
%
% This section will receive odd code that would be of potential use to
% other packages and should eventually made it to the kernel
% (perhaps).
%
% \begin{macro}{\UndeclareRobustCommand}
%    Remove a robust command from memory if it isn't used any
%    longer. Of course this doesn't free the hash table but at least
%    the space gets reclaimed.
%    \begin{macrocode}
\cs_set_nopar:Npn \UndeclareRobustCommand#1{%
  \cs_gundefine:N #1
  \exp_args:Nc \cs_gundefine:N {\cs_to_str:N #1~}
}
%    \end{macrocode}
% \end{macro}
%
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \Finale
%