1 | % \iffalse |
---|
2 | %% Source File: textcase.dtx |
---|
3 | %% Copyright 1997 1998 David Carlisle |
---|
4 | %% |
---|
5 | %% This file may be distributed under the terms of the LPPL. |
---|
6 | %% See 00readme.txt for details. |
---|
7 | % |
---|
8 | %<*dtx> |
---|
9 | \ProvidesFile{textcase.dtx} |
---|
10 | %</dtx> |
---|
11 | %<package>\NeedsTeXFormat{LaTeX2e} |
---|
12 | %<package>\ProvidesPackage{textcase} |
---|
13 | %<driver> \ProvidesFile{textcase.drv} |
---|
14 | % \fi |
---|
15 | % \ProvidesFile{textcase.dtx} |
---|
16 | [1998/11/12 v0.06 Text only upper/lower case changing (DPC)] |
---|
17 | % |
---|
18 | % \iffalse |
---|
19 | %<*driver> |
---|
20 | \documentclass{ltxdoc} |
---|
21 | \usepackage{textcase} |
---|
22 | \begin{document} |
---|
23 | \DocInput{textcase.dtx} |
---|
24 | \end{document} |
---|
25 | %</driver> |
---|
26 | % \fi |
---|
27 | % |
---|
28 | % \GetFileInfo{textcase.dtx} |
---|
29 | % \CheckSum{110} |
---|
30 | % |
---|
31 | % \changes{v0.01}{1997/09/28} |
---|
32 | % {Posted to c.t.t} |
---|
33 | % \changes{v0.02}{1997/09/28} |
---|
34 | % {Support \cs{ensuremath}} |
---|
35 | % \changes{v0.03}{1997/12/12} |
---|
36 | % {Donald Arseneau: support \cs{ref} \cs{cite} \cs{label}} |
---|
37 | % \changes{v0.04}{1997/12/14} |
---|
38 | % {Convert to dtx form, add \cs{NoCaseChange}} |
---|
39 | % \changes{v0.04}{1997/12/14} |
---|
40 | % {Support (most uses of) optional argument of \cs{cite}} |
---|
41 | % \changes{v0.05}{1997/12/16} |
---|
42 | % {More comments from Donald, |
---|
43 | % perhaps I should just give him this package for Christmas} |
---|
44 | % \changes{v0.06}{1998/11/12} |
---|
45 | % {overload option} |
---|
46 | % |
---|
47 | % |
---|
48 | % \title{The \textsf{textcase} package\thanks{This file |
---|
49 | % has version number \fileversion, last |
---|
50 | % revised \filedate.}} |
---|
51 | % \author{David Carlisle\thanks{%^^A |
---|
52 | % Reorganisation to suppport skipping a wider class of |
---|
53 | % things than just math done by Donald Arseneau}} |
---|
54 | % |
---|
55 | % \date{\filedate} |
---|
56 | % |
---|
57 | % \maketitle |
---|
58 | % |
---|
59 | % \section{Introduction}\label{intro} |
---|
60 | % |\MakeTextUppercase| and |\MakeTextLowercase| are versions of the |
---|
61 | % standard |\MakeUppercase| and |\MakeLowercase| that do not change |
---|
62 | % the case of any math sections in their arguments. |
---|
63 | %\begin{verbatim} |
---|
64 | % \MakeTextUppercase{abc\ae\ \( a = b \) and $\alpha \neq a$ |
---|
65 | % or even \ensuremath{x=y} and $\ensuremath{x=y}$} |
---|
66 | %\end{verbatim} |
---|
67 | % Should produce: |
---|
68 | % \begin{quotation} |
---|
69 | % ABC\AE\ \( a = b \) AND $\alpha \neq a$ |
---|
70 | % OR EVEN \ensuremath{x=y} AND $\ensuremath{x=y}$ |
---|
71 | % \end{quotation} |
---|
72 | % |
---|
73 | % Version 0.03 of this package incorporates some changes suggested by |
---|
74 | % Donald Arseneau so that as well as math mode, the arguments of |
---|
75 | % |\cite|, |\label| and |\ref| are also prevented from being uppercased. |
---|
76 | % So you can now go |
---|
77 | %\begin{verbatim} |
---|
78 | % \MakeTextUppercase{% |
---|
79 | % Text in section~\ref{intro}, about \cite[pp 2--4]{bbb}} |
---|
80 | %\end{verbatim} |
---|
81 | % which produces |
---|
82 | % \begin{quotation} |
---|
83 | % \MakeTextUppercase{% |
---|
84 | % Text in section~\ref{intro}, about \cite[pp 2--4]{bbb}} |
---|
85 | % \end{quotation} |
---|
86 | % If, instead, the standard |\MakeUppercase| were used here, the keys |
---|
87 | % `into' and `bbb' would be uppercased and generate errors about |
---|
88 | % undefined references to INTRO and BBB. |
---|
89 | % |
---|
90 | % Sometimes there may be a special section of text that should not be |
---|
91 | % uppercased. This can be marked with |\NoCaseChange|, as follows. |
---|
92 | %\begin{verbatim} |
---|
93 | % \MakeTextUppercase{% |
---|
94 | % Text \NoCaseChange{More Text} yet more text} |
---|
95 | %\end{verbatim} |
---|
96 | % which produces |
---|
97 | % \begin{quotation} |
---|
98 | % \MakeTextUppercase{% |
---|
99 | % Text \NoCaseChange{More Text} yet more text} |
---|
100 | % \end{quotation} |
---|
101 | % |
---|
102 | % |\NoCaseChange| has other uses. If for some reason you need a |
---|
103 | % tabular environment within an uppercased section, then you need |
---|
104 | % to ensure that the name `tabular' and the preamble (eg `ll') |
---|
105 | % does not get uppercased: |
---|
106 | %\begin{verbatim} |
---|
107 | % \MakeTextUppercase{% |
---|
108 | % Text \NoCaseChange{\begin{tabular}{ll}}% |
---|
109 | % table&stuff\\goes&here |
---|
110 | % \NoCaseChange{\end{tabular}} |
---|
111 | % More text} |
---|
112 | %\end{verbatim} |
---|
113 | % which produces |
---|
114 | % \begin{quotation} |
---|
115 | % \MakeTextUppercase{% |
---|
116 | % Text \NoCaseChange{\begin{tabular}{ll}}%^^A |
---|
117 | % table&stuff\\goes&here |
---|
118 | % \NoCaseChange{\end{tabular}} |
---|
119 | % More text} |
---|
120 | % \end{quotation} |
---|
121 | % |
---|
122 | % \section{Features and Foibles} |
---|
123 | % |
---|
124 | % \subsection{Nested text} |
---|
125 | % The commands defined here only skip math sections and |\ref| arguments |
---|
126 | % if they are not `hidden' inside a |{ }| brace group. All text inside |
---|
127 | % such a group will be made uppercase just as with the standard |
---|
128 | % |\MakeUppercase|. |
---|
129 | %\begin{verbatim} |
---|
130 | % \MakeTextUppercase{a b {c $d$} $e$} |
---|
131 | %\end{verbatim} |
---|
132 | % produces |
---|
133 | % \begin{quotation} |
---|
134 | % \MakeTextUppercase{a b {c $d$} $e$} |
---|
135 | % \end{quotation} |
---|
136 | % Of course, this restriction does not apply to the arguments of the |
---|
137 | % supported commands |\ensuremath|, |\label|, |\ref|, and |\cite|. |
---|
138 | % |
---|
139 | % If you cannot arrange for your |
---|
140 | % mathematics to be at the outer level of brace grouping, you should |
---|
141 | % use the following basic technique (which works even with the standard |
---|
142 | % |\MakeUppercase| command). Define a new command that expands to your |
---|
143 | % math expression, and then use that command, with |\protect|, in the |
---|
144 | % text to be uppercased. Note that if the text being uppercased is in a |
---|
145 | % section title or other moving argument you may need to make the |
---|
146 | % definition in the document preamble, rather than just before the |
---|
147 | % section command, so that the command is defined when the table of |
---|
148 | % contents file is read. |
---|
149 | %\begin{verbatim} |
---|
150 | % \MakeTextUppercase{% |
---|
151 | % Text \fbox{$a=b$ and $x=y$}}% |
---|
152 | % |
---|
153 | % \newcommand{\mathexprone}{$a=b$} |
---|
154 | % \newcommand{\mathexprtwo}{$x=y$} |
---|
155 | % \MakeTextUppercase{% |
---|
156 | % Text \fbox{\protect\mathexprone\ and \protect\mathexprtwo}}% |
---|
157 | %\end{verbatim} |
---|
158 | % which produces |
---|
159 | % \begin{quotation} |
---|
160 | % \MakeTextUppercase{% |
---|
161 | % Text \fbox{$a=b$ and $x=y$}}% |
---|
162 | % |
---|
163 | % \newcommand{\mathexprone}{$a=b$} |
---|
164 | % \newcommand{\mathexprtwo}{$x=y$} |
---|
165 | % \MakeTextUppercase{% |
---|
166 | % Text \fbox{\protect\mathexprone\ and \protect\mathexprtwo}}% |
---|
167 | % \end{quotation} |
---|
168 | % |
---|
169 | % \subsection{Citations} |
---|
170 | % As documented above, |\cite| and |\ref| commands are not uppercased by |
---|
171 | % |\MakeTextUppercase|. If you are using a non-numeric citation scheme |
---|
172 | % you may want the replacement text for |\cite| to be uppercased. |
---|
173 | % |
---|
174 | % It is difficult to arrange that |\MakeTextUppercase| uppercases such |
---|
175 | % text, not least because this would lead to interaction with the many |
---|
176 | % bibliography packages which redefine |\cite| one way or another. One |
---|
177 | % possibility to achieve this is to use Donald Arseneau's cite package |
---|
178 | % and to locally redefine |\citeform| to add |\MakeUppercase| around |
---|
179 | % the final text string produced by |\cite|. |
---|
180 | %\begin{verbatim} |
---|
181 | % \MakeTextUppercase{% |
---|
182 | % Text \cite{bbb} and \cite{ccc}} |
---|
183 | % |
---|
184 | % {\renewcommand\citeform{\MakeUppercase}\MakeTextUppercase{% |
---|
185 | % Text \cite{bbb} and \cite{ccc}}} |
---|
186 | %\end{verbatim} |
---|
187 | % which produces\footnote{This is faked, so this document does not |
---|
188 | % rely on \texttt{cite.sty} being installed} |
---|
189 | % \begin{quotation} |
---|
190 | % TEXT [1] AND [David Carlisle 1997] |
---|
191 | % |
---|
192 | % TEXT [1] AND [DAVID CARLISLE 1997] |
---|
193 | % \end{quotation} |
---|
194 | % |
---|
195 | % \subsection{overload Option} |
---|
196 | % By default the package only defines new commands, |\MakeTextUppercase| |
---|
197 | % and |\MakeTextlowercase| as described above. You may wish to redefine |
---|
198 | % the standard |\MakeUppercase| and |\MakeLowercase| commands to be |
---|
199 | % the same as these new commands. So that for example headings in the |
---|
200 | % book class have this new feature without any further redefinition. |
---|
201 | % You may use the package option |[overload]| in which case these |
---|
202 | % new definitions will be overloaded on to the existing command names. |
---|
203 | % |
---|
204 | % \begin{thebibliography}{9} |
---|
205 | % |
---|
206 | % \bibitem{bbb} Something numeric |
---|
207 | % \bibitem[David Carlisle 1997]{ccc} Something textual |
---|
208 | % \end{thebibliography} |
---|
209 | % |
---|
210 | % \StopEventually{} |
---|
211 | % |
---|
212 | % \section{Implementation} |
---|
213 | % |
---|
214 | % \begin{macrocode} |
---|
215 | %<*package> |
---|
216 | % \end{macrocode} |
---|
217 | % |
---|
218 | % \begin{macro}{\@uclcnotmath} |
---|
219 | % This is the main macro of this package. It is basically |
---|
220 | % a copy of |\MakeTextUppercase| and |\MakeTextLowercase| |
---|
221 | % from the \LaTeX\ kernel, modified slightly so that they |
---|
222 | % can share code (that modification could be done to the |
---|
223 | % standard versions as well) and then further changed to |
---|
224 | % skip certain features like math mode and |\label| arguments. |
---|
225 | % |
---|
226 | % The arguments are:\\ |
---|
227 | % |#1|: Extra commands to apply for case changing. |
---|
228 | % Used to locally redefine |\i| and |\j| for uppercasing.\\ |
---|
229 | % |#2|: Either |##1##2| or |##2##1| to control the order |
---|
230 | % in which |\let| is applied to the pairs of control |
---|
231 | % sequences in |\@uclclist|.\\ |
---|
232 | % |#3|: |\uppercase| or |\lowercase|.\\ |
---|
233 | % |#4|: The text to be upper (or lower) cased. |
---|
234 | % \begin{macrocode} |
---|
235 | \def\@uclcnotmath#1#2#3#4{\begingroup |
---|
236 | % \end{macrocode} |
---|
237 | % Run extra commands (currently just to redefine |\i| and |\j|). |
---|
238 | % \begin{macrocode} |
---|
239 | #1% |
---|
240 | % \end{macrocode} |
---|
241 | % |
---|
242 | % Locally set |\( \)| to be just |$ $|, so that the math skipping |
---|
243 | % code can be simplified, just to look for |$|. |
---|
244 | % \begin{macrocode} |
---|
245 | \def\({$}\let\)\(% |
---|
246 | % \end{macrocode} |
---|
247 | % |
---|
248 | % Set up the `non-math' things that also have to be skipped. |
---|
249 | % \begin{macrocode} |
---|
250 | \def\NoCaseChange##1{\noexpand\NoCaseChange{\noexpand##1}}% |
---|
251 | \@nonchangecase\label |
---|
252 | \@nonchangecase\ref |
---|
253 | \@nonchangecase\ensuremath |
---|
254 | % \end{macrocode} |
---|
255 | % |
---|
256 | % |\cite| a bit trickier, as we want to uppercase any optional argument. |
---|
257 | % This will fail if the optional argument contains a brace group, but |
---|
258 | % should catch most cases. |
---|
259 | % |
---|
260 | % |text \cite[page 1]{foo} more text| ends up as |
---|
261 | %\begin{verbatim} |
---|
262 | % \uppercase{text \toks@{\cite[page1]}% |
---|
263 | % \the\toks@{foo}% |
---|
264 | % \uppercase{ more text} |
---|
265 | %\end{verbatim} |
---|
266 | % \begin{macrocode} |
---|
267 | \def\cite##1##{\toks@{\noexpand\cite##1}\@citex}% |
---|
268 | \def\@citex##1{\NoCaseChange{\the\toks@{##1}}}% |
---|
269 | % \end{macrocode} |
---|
270 | % (|\@citex| is a scratch macro here, not a redefinition of the existing |
---|
271 | % |\@citex|.) |
---|
272 | % |
---|
273 | % The following is essentially taken from |\MakeUppercase|. |
---|
274 | % Recursively execute |\reserved@a| to |\let| the pairs in |\@uclclist|. |
---|
275 | % The strange construction with |\@gobble| at the end just gobbles the |
---|
276 | % final recursive call. |
---|
277 | % |
---|
278 | % Incidentally, packages should not use the |\reserved@|\ldots\ scratch |
---|
279 | % macros, which are `reserved' for use within the \LaTeX\ kernel, but |
---|
280 | % (a) this code is essentially a copy from the kernel, and |
---|
281 | % (b) I'm allowed to break the rules, so there. |
---|
282 | % \begin{macrocode} |
---|
283 | \def\reserved@a##1##2{\let#2\reserved@a}% |
---|
284 | \expandafter\reserved@a\@uclclist\reserved@b{\reserved@b\@gobble}% |
---|
285 | % \end{macrocode} |
---|
286 | % |
---|
287 | % Expand everything first so that the `skipping' code can see what to |
---|
288 | % skip and so that tokens are revealed to |\uppercase|. |
---|
289 | % This makes the argument `moving'. |
---|
290 | % The |$\valign$| is just a fake math expression used to terminate |
---|
291 | % the parsing done by |\@skipmath|. |
---|
292 | % \begin{macrocode} |
---|
293 | \protected@edef\reserved@a{\endgroup |
---|
294 | \noexpand\@skipmath#3#4$\valign$}% |
---|
295 | % \end{macrocode} |
---|
296 | % |
---|
297 | % \begin{macrocode} |
---|
298 | \reserved@a} |
---|
299 | % \end{macrocode} |
---|
300 | % \end{macro} |
---|
301 | % |
---|
302 | % \begin{macro}{\@nonchangecase} |
---|
303 | % \begin{macrocode} |
---|
304 | \def\@nonchangecase#1{\def#1##1{\NoCaseChange{#1{##1}}}} |
---|
305 | % \end{macrocode} |
---|
306 | % \end{macro} |
---|
307 | % |
---|
308 | % \begin{macro}{\NoCaseChange} |
---|
309 | % For hiding arbitrary text from |\uppercase|. This innocuous |
---|
310 | % definition is used for any occurrence of |\NoCaseChange| |
---|
311 | % in text that is not passed to |\MakeTextUppercase|. For example a |
---|
312 | % section heading may be uppercased, but the toc entry may not. |
---|
313 | % It is also used for nested definitions of |\cite| etc, where the |
---|
314 | % |\NoCaseChange| is inserted by expansion, but not removed as it is |
---|
315 | % hidden by the brace group. |
---|
316 | % \begin{macrocode} |
---|
317 | \let\NoCaseChange\@firstofone |
---|
318 | % \end{macrocode} |
---|
319 | % \end{macro} |
---|
320 | % |
---|
321 | %\begin{macro}{\@skipmath} |
---|
322 | % |#1|: operation |\uppercase| / |\lowercase|\\ |
---|
323 | % |#2|: text up to first (next) |$|\\ |
---|
324 | % |#3|: first math mode material (or |\valign| sentinel) |
---|
325 | % \begin{macrocode} |
---|
326 | \def\@skipmath#1#2$#3${% |
---|
327 | \@skip@nonchangecase#1#2\NoCaseChange\valign |
---|
328 | \ifx\valign#3% |
---|
329 | \else |
---|
330 | $#3$% |
---|
331 | \expandafter\@skipmath\expandafter#1% |
---|
332 | \fi} |
---|
333 | % \end{macrocode} |
---|
334 | % \end{macro} |
---|
335 | % |
---|
336 | %\begin{macro}{\@skip@nonchangecase} |
---|
337 | % |#1|: |\uppercase| or |\lowercase|\\ |
---|
338 | % |#2|: Text up to the first command (such as |\cite|) made `safe'. |
---|
339 | % or the first use of |\NoCaseChange|. |
---|
340 | % \begin{macrocode} |
---|
341 | \def\@skip@nonchangecase#1#2\NoCaseChange#3{% |
---|
342 | #1{#2}% |
---|
343 | \ifx\valign#3% |
---|
344 | \else |
---|
345 | #3% |
---|
346 | \expandafter\@skip@nonchangecase\expandafter#1% |
---|
347 | \fi} |
---|
348 | % \end{macrocode} |
---|
349 | % \end{macro} |
---|
350 | % |
---|
351 | % \begin{macro}{\MakeTextUppercase} |
---|
352 | % \changes{v0.06}{1998/11/12} |
---|
353 | % {Add edef to make behaviour more like \cs{MakeUppercase}} |
---|
354 | % Put it all together. Arrange for \i\ and \j\ to uppercase, and |
---|
355 | % to read the pairs in the ucase list `forwards'. |
---|
356 | % \begin{macrocode} |
---|
357 | \DeclareRobustCommand\MakeTextUppercase{% |
---|
358 | \@uclcnotmath{\def\i{I}\def\j{J}}{##1##2}\uppercase} |
---|
359 | % \end{macrocode} |
---|
360 | % |
---|
361 | % \begin{macrocode} |
---|
362 | \protected@edef\MakeTextUppercase#1{\MakeTextUppercase{#1}} |
---|
363 | % \end{macrocode} |
---|
364 | % \end{macro} |
---|
365 | % |
---|
366 | % \begin{macro}{\MakeTextLowercase} |
---|
367 | % \changes{v0.06}{1998/11/12} |
---|
368 | % {Add edef to make behaviour more like \cs{MakeLowercase}} |
---|
369 | % probably will never be used, but it is easy to implement. |
---|
370 | % Use |\lowercase| and read the pairs in the uppercase list `backwards'. |
---|
371 | % \begin{macrocode} |
---|
372 | \DeclareRobustCommand\MakeTextLowercase{% |
---|
373 | \@uclcnotmath{}{##2##1}\lowercase} |
---|
374 | % \end{macrocode} |
---|
375 | % |
---|
376 | % \begin{macrocode} |
---|
377 | \protected@edef\MakeTextLowercase#1{\MakeTextLowercase{#1}} |
---|
378 | % \end{macrocode} |
---|
379 | % \end{macro} |
---|
380 | % |
---|
381 | % \begin{macro}{\MakeUppercase} |
---|
382 | % \begin{macro}{\MakeLowercase} |
---|
383 | % \changes{v0.06}{1998/11/12} |
---|
384 | % {Option to overload added. latex/2906} |
---|
385 | % \begin{macrocode} |
---|
386 | \DeclareOption{overload}{% |
---|
387 | \expandafter\let\csname MakeUppercase \expandafter\endcsname |
---|
388 | \csname MakeTextUppercase \endcsname |
---|
389 | \expandafter\let\csname MakeLowercase \expandafter\endcsname |
---|
390 | \csname MakeTextLowercase \endcsname} |
---|
391 | % \end{macrocode} |
---|
392 | % |
---|
393 | % \begin{macrocode} |
---|
394 | \ProcessOptions |
---|
395 | % \end{macrocode} |
---|
396 | % \end{macro} |
---|
397 | % \end{macro} |
---|
398 | % |
---|
399 | % \begin{macrocode} |
---|
400 | %</package> |
---|
401 | % \end{macrocode} |
---|
402 | % |
---|
403 | % \Finale |
---|
404 | % |
---|