summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/normalcolor/normalcolor.dtx
blob: c48f3ba3fe708a1abce2d3466314197b9394304c (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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
% \CheckSum{129}
% \iffalse^^A meta-comment
% ======================================================================
% normalcolor.dtx
% Copyright (c) Markus Kohm, 2016
%
% This work may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, version 1.3c of the license.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer and author of this work is Markus Kohm.
%
% The work consists of the file `normalcolor.dtx` only.
% ======================================================================
% \fi^^A meta-comment
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \iffalse^^A meta-comment
%<*package>
% From File: $Id: normalcolor.dtx 11 2016-03-22 07:55:35Z mjk $
%</package>
%<*dtx>
\ifx\ProvidesFile\undefined\def\ProvidesFile#1[#2]{}\fi
%</dtx>
%<package>\NeedsTeXFormat{LaTeX2e}[1995/12/01]
%<*dtx|package>
\begingroup
  \def\filedate$#1: #2-#3-#4 #5${\gdef\filedate{#2/#3/#4}}
  \filedate$Date: 2016-03-22 08:55:35 +0100 (Di, 22 Mär 2016) $
  \def\filerevision$#1: #2 ${\gdef\filerevision{r#2}}
  \filerevision$Revision: 11 $
\endgroup
%</dtx|package>
%<*dtx>
\ProvidesFile{normalcolor.dtx}[%
%</dtx>
%<package>\ProvidesPackage{normalcolor}[%
%<*dtx|package>
  \filedate \space\filerevision\space
  simple (x)color extension package]
%</dtx|package>
%<*dtx>
\ifx\documentclass\undefined
  \input docstrip.tex
  \keepsilent
  \askforoverwritefalse
  \usedir{tex/latex/normalcolor}
  \generate{%
    \file{normalcolor.sty}{%
      \from{normalcolor.dtx}{package}%
    }%
    \file{normalcolor-example.tex}{%
      \from{normalcolor.dtx}{example}%
    }%
  }%
  \generate{\nopreamble\nopostamble
    \file{README.txt}{%
      \from{normalcolor.dtx}{README}%
    }%
  }%
\else
  \let\endbatchfile\relax
\fi
\endbatchfile
%</dtx>
%<*driver>
  \documentclass{ltxdoc}
  \usepackage{hypdoc}
  \CodelineIndex
  \RecordChanges
  \GetFileInfo{normalcolor.dtx}
  \begin{document}
  \DocInput{\filename}
  \end{document}
%</driver>
% \fi^^A meta-comment
%
% \changes{r0}{2016/03/18}{Start of project}
% \changes{r11}{2016/03/22}{First release}
%
% \title{The \texttt{(x)color} Extension Package \texttt{normalcolor}\\
%   Revision~\fileversion}
% \date{\filedate}
% \author{Markus Kohm}
% \maketitle
% \begin{abstract}
%   Packages \texttt{color} and \texttt{xcolor} provide excellent features for
%   managing and using colours. There is only one little feature sometimes
%   missing: Setting up the default colour of \cs{normalcolor}. The only
%   purpose of \texttt{normalcolor} is to extend both packages by exactly this
%   single feature.
% \end{abstract}
% \tableofcontents
%
% \section{Loading \texttt{normalcolor}}
%
% You can load package \texttt{normalcolor} as you load all other packages,
% too:
% \begin{verbatim}
% \usepackage{normalcolor}
% \end{verbatim}
% \vskip-\baselineskip
% Note: It does not matter whether you load
% \texttt{color}\footnote{\url{http://ctan.org/pkg/color}} or
% \texttt{xcolor}\footnote{\url{http://ctan.org/pkg/xcolor}} before or after
% \texttt{normalcolor}.  Even using neither \texttt{color} nor \texttt{xcolor}
% would not blame \texttt{normalcolor}, but then it would be completely
% useless.
%
% \section{Setting up the Normal Colour}
%
% \DescribeMacro{\setnormalcolor} This command has the same arguments like
% \cs{color}. See the documentation of either package
% \texttt{color}\footnotemark[1] or package \texttt{xcolor}\footnotemark[2]
% (depending on the one you are using) for the syntax. But in opposite to
% \cs{color} it does not change the current colour but the colour of all
% implicit or explicit usages of \cs{normalcolor}.
%
% If you use the command before |\begin{document}| it will also change the
% initial colour of the document.
%
% \DescribeMacro{\resetnormalcolor}
% This command, which has no argument, changes the colour of \cs{normalcolor}
% into the current colour. If you use it before |\begin{document}| it will be
% delayed until |\begin{document}| and therefore also changes the current
% colour at the start of the document. But after |\begin{document}| it will
% only change \cs{normalcolor} without changing the current colour.
%
% \StopEventually{\PrintChanges\PrintIndex}
%
% \iffalse^^A meta-comment
% We do not need documentation of the README or the makefile in the manual.
%<*README>
%    \begin{macrocode}
normalcolor
Copyright (c) Markus Kohm, 2016
----------------------------------------------------------------------------
This work may be distributed and/or modified under the conditions of
the LaTeX Project Public License, version 1.3c of the license.
The latest version of this license is in
  http://www.latex-project.org/lppl.txt
and version 1.3c or later is part of all distributions of LaTeX
version 2005/12/01 or later.

This work has the LPPL maintenance status "maintained".

The Current Maintainer and author of this work is Markus Kohm.

The work consists of the file `normalcolor.dtx` only.
----------------------------------------------------------------------------
SHORT DESCRIPTION

The package simple provides a command `\setnormalcolor` with the same
syntax as command `\color' either of package `color' or package `xcolor'.
But `\setnormalcolor' will not change the current colour but the normal
colour.  So using `\normalcolor' (implicit or explicit) afterwards will
change the current colour to the colour given by the previous 
`\setnormalcolor'.
----------------------------------------------------------------------------
PACKAGE GENERATION

Simple way:

To use the simple way you need the original `makefile' from the source
distribution of `normalcolor' and `GNU make'.  Then you can use:

    make all

to generate all files of `normalcolor'.

Manual way:

If you cannot use make you can extract all the files using:

    tex normalcolor.dtx

Note that you have to use `tex' not any LaTeX format!

This will generate files `normalcolor.sty' and `README.txt'. Rename the
generated `README.txt' to `README'.

To make the documentation use:

    pdflatex normalcolor.dtx
    pdflatex normalcolor.dtx
    mkindex normalcolor
    pdflatex normalcolor.dtx
    pdflatex normalcolor.dtx

This will result in the manual file `normalcolor.pdf'.
----------------------------------------------------------------------------
INSTALLATION

Simple way:

To use the simple way you need the original `makefile' from the source
distribution of `normalcolor' and `GNU make' and a TeX-Live-compatible 
`kpsewhich'.  Then you can use:

    make install

to install normalcolor into your personal TEXMF tree.  If you want to use
the local TEXMF tree instead of the personal one, you may use:

    make INSTALLLOCAL=true install

If you want to use another TEXMF tree, you may use

    make INSTALLROOT=<path to the TEXMF tree> install

Manual way:

Copy `normalcolor.sty' to `tex/latex/normalcolor/' inside the TDS tree you
want to install `normalcolor'.

Copy `normalcolor.pdf' and `README.txt' as `README' to 
`doc/latex/normalcolor/' inside the TDS tree you want to install
`normalcolor'.

Maybe you have to call `texhash' for the TDS tree you have installed
`normalcolor'.
----------------------------------------------------------------------------
USAGE

See `normalcolor.pdf'.
----------------------------------------------------------------------------
%    \end{macrocode}
%</README>
% \fi^^A meta-comment
%
% \section{Example}
%
% Try the following example and have a look at the page numbers in the table
% of contents and the page footer. All these, except the section page numbers
% in the table of contents, are printed using |\normalcolor|:
%
% \iffalse^^A meta-comment
%<*example>
% \fi^^A meta-comment
%    \begin{macrocode}
\listfiles
\documentclass{article}

\usepackage{normalcolor}
\setnormalcolor{green}
\usepackage{xcolor}

\usepackage{blindtext}
\begin{document}
\color{blue}
\tableofcontents
\blinddocument
\setnormalcolor{red}
\blinddocument

\resetnormalcolor
\blinddocument
\end{document}
%    \end{macrocode}
% \iffalse^^A meta-comment
%</example>
% \fi^^A meta-comment^
%
% \section{Implementation}
%
% The package does not have any options. So we just call
% \iffalse^^A meta-comment
%<*package>
% \fi^^A meta-comment 
%    \begin{macrocode}
\ProcessOptions\relax
%    \end{macrocode}
%
% \begin{macro}{\resetnormalcolor}
%   This is the very simple first version of the command. Before
%   |\begin{documet}| it simply delays itself until |\begin{document}|.
%    \begin{macrocode}
\DeclareRobustCommand*{\resetnormalcolor}{\AtBeginDocument{\resetnormalcolor}}
%    \end{macrocode}
%   To make this work, we need to redefine it at |\begin{document}|:
%    \begin{macrocode}
\AtBeginDocument{%
  \let\resetnormalcolor\relax
  \DeclareRobustCommand*{\resetnormalcolor}{%
    \ifdefined\default@color
      \ifdefined\current@color
        \let\default@color\current@color
      \fi
    \fi
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\setnormalcolor}
% \begin{macro}{\@setnormalcolor}
% \begin{macro}{\@@setnormalcolor}
%   Note, that changing the default colour before loading either
%   \texttt{color} or \texttt{xcolor} does not work, because these packages
%   set |\default@color| themselves at |\begin{document}|. But indeed in this
%   case it is much more simple, because we just have to set up the wanted
%   colour.
%    \begin{macrocode}
\DeclareRobustCommand*{\setnormalcolor}{%
  \@ifnextchar [%]
    \@@setnormalcolor\@setnormalcolor
}
\newcommand*{\@@setnormalcolor}[2][]{%
  \AtBeginDocument{%
    \begingroup\expandafter\expandafter\expandafter\endgroup
    \expandafter\ifx\csname color\endcsname\relax\else
      \color[{#1}]{#2}\let\default@color\current@color
    \fi
  }%
}
\newcommand*{\@setnormalcolor}[1]{%
  \AtBeginDocument{%
    \begingroup\expandafter\expandafter\expandafter\endgroup
    \expandafter\ifx\csname color\endcsname\relax\else
      \color{#1}\let\default@color\current@color
    \fi
  }%
}
%    \end{macrocode}
%  After |\begin{document}| we need another definition of |\@@setnormalcolor|
%  and |\@setnormalcolor|. In this case we need to change |\default@color|
%  without changing |\current@color|. This may be done using a trick.
%    \begin{macrocode}
\AtBeginDocument{%
  \begingroup\expandafter\expandafter\expandafter\endgroup
  \expandafter\ifx\csname color\endcsname\relax
    \renewcommand*{\@@setnormalcolor}[2][]{}%
    \let\@setnormalcolor\@gobble
  \else
    \renewcommand*{\@@setnormalcolor}[2][]{%
      \begingroup
        \color[{#1}]{#2}%
        \edef\reserved@a{%
          \noexpand\endgroup
          \noexpand\def\noexpand\default@color{%
            \unexpanded\expandafter{\current@color}%
          }%
        }%
      \reserved@a
    }%
    \renewcommand*{\@setnormalcolor}[1]{%
      \begingroup
        \color{#1}%
        \edef\reserved@a{%
          \noexpand\endgroup
          \noexpand\def\noexpand\default@color{%
            \unexpanded\expandafter{\current@color}%
          }%
        }%
      \reserved@a
    }%
  \fi
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \iffalse^^A meta-comment
%</package>
% \fi^^A meta-comment 
%
% \Finale
%
\endinput
%
% end of file `normalcolor.dtx'

%%% Local Variables:
%%% mode: doctex
%%% mode: flyspell
%%% ispell-local-dictionary: "en_GB"
%%% TeX-master: t
%%% End: