summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/isodate/isodateo.dtx
blob: cf92ac9f9477eea6021b6dc515b217d7c27d87c4 (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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
% \iffalse meta comment
% File: isodateo.dtx Copyright (C) 2000 Harald Harders
% \fi
%
% \iffalse
%
%<*package>
\def\packagename{isodateo}
\def\fileversion{1.06a}
\def\filedate{2004/02/12}
\def\docdate{2000/08/08}
%</package>
%<*driver>
\documentclass{ltxdoc}
\IfFileExists{isodateo.sty}{\usepackage{isodateo}
 \let\isodateoSTYfound\active}{\GenericWarning{isodateo.dtx}{Package
 file isodateo.sty not found (Documentation will be messed up!^^J^^A
 Generate isodateo.sty by (La)TeXing isodateo.ins, process
 isodateo.dtx again)^^J}\stop}
\usepackage{array}
\isodate
\title{The \texttt{isodateo} package\thanks{This file has version 
    \fileversion\ last revised \printdateTeX{\filedate}, 
    documentation dated \printdateTeX{\docdate}.}}
\author{Harald Harders\\\texttt{h.harders@tu-bs.de}}
\date{File Date \printdateTeX{\filedate}, Printed \today}
\newlength{\tempdima}%
\makeatletter
\renewenvironment{table}[1][]{%
  \@float{table}[#1]%
  \centering%
  \setlength{\tempdima}{\abovecaptionskip}%
  \setlength{\abovecaptionskip}{\belowcaptionskip}%
  \setlength{\belowcaptionskip}{\tempdima}%
  }{%
\end@float
}
\makeatother
\EnableCrossrefs
\CodelineIndex
\DoNotIndex{\def,\edef,\let,\newcommand,\newenvironment,\newcounter,%
  \gdef,\@ifundefined,\@empty,\@firstoftwo,\@secondoftwo,\@nil,%
  \,,\number,\renewcommand,\setboolean,\whiledo}
\DoNotIndex{\setcounter,\space}
\CodelineNumbered
\RecordChanges
\CheckSum{272}
\begin{document}
 \DocInput{isodateo.dtx}
\end{document}
%</driver>
% \fi
%
% \changes{1.06a}{2004/02/12}{Path changed according to new CTAN
%   structure}%
% \changes{1.05}{2000/06/15}{Throw out the commands \textbackslash
% IfSubStringInString and \textbackslash IfCharInString and use the
% package substr.sty instead}
% \changes{1.05}{2000/06/15}{Change all internal command names to
% start with \textbackslash iso@}
% \changes{1.04}{2000/06/13}{Make the commands robust}
% \changes{1.01}{2000/06/08}{Improve documentation}
% \maketitle
%
% \begin{abstract}
% \noindent This package provides commands to switch between different 
% date formats (standard, ISO, numeric, \LaTeX\ package). They are used by the
% \verb|\today| command and by the \verb|\printdate| and
% \verb|\printdateTeX| commands that print any date.
% This package supports German (old and new rules, Austrian), US
% English, and all languages that have the same date format as British
% English does\footnote{E.g. Danish, French}.
%
% The idea for this package was taken from the akletter class. 
% \end{abstract}
%
% \tableofcontents
% 
% \section{Commands}
% 
% \subsection{Switching the date format}
%
% \DescribeMacro{\today}%
% This package provides five commands to switch the output format of
% the \verb|\today|, the \verb|\printdate|, and the
% \verb|\printdateTeX| commands:
% \medskip 
%
% \DescribeMacro{\isodate}%
% \DescribeMacro{\numdate}%
% \DescribeMacro{\shortdate}%
% \DescribeMacro{\TeXdate}%
% \DescribeMacro{\origdate}%
% \begin{tabular}{@{}ll}
% \verb|\isodate|&date format described in ISO 8601 and DIN 5008\\
% &(yyyy-mm-dd)\\
% \verb|\numdate|&numeric date format with four digits of the year\\
% \verb|\shortdate|&short numeric date format with two digits of the
% year\\
% \verb|\TeXdate|&date format used for version description of 
% packages\\
% &(yyyy/mm/dd)\\
% \verb|\origdate|&original \LaTeX\ format
% \end{tabular}
% \medskip 
%
% The numeric and short numeric format change their behaviour
% depending on the actual language:
%
% \noindent\begin{tabular}{@{}llll@{}}
% German, nGerman&\verb|dd.\,mm.~yyyy|&resp.&\verb|dd.\,mm.\,yy|\\
% US English&\verb|mm/dd/yyyy|&resp.&\verb|mm/dd/yy|\\ 
% other languages&\verb|dd/mm/yyyy|&resp.&\verb|dd/mm/yy|
% \end{tabular}
%
% So this package supports German (old and new rules, Austrian), US
% English, and all languages that have the same date format as British
% English does\footnote{E.g. Danish, French}.
% \changes{1.05}{2000/06/29}{Note that every language that has the
% same format as English is supported.}
% Switching the language by using \textbackslash selectlanguage also
% switches back to the original date format.
%
% \subsection{Printing any date}
%
% \DescribeMacro{\printdate}%
% The command \verb|\printdate{#1}| prints any date in the actual
% format. The argument may be a date in German, British English, or
% ISO format, e.g.\\
% \begin{quote}
% \verb|\printdate{24.12.2000}|\\
% \verb|\printdate{24/12/2000}|\\
% \verb|\printdate{2000-12-24}|
% \end{quote}
%
% \DescribeMacro{\printdateTeX}%
% The command \verb|\printdateTeX{#1}| prints any date in the actual
% format. The argument must be in the \LaTeX\ format \verb|yyyy/mm/dd|, e.g.\\
% \begin{quote}
% \verb|\printdateTeX{2000/12/24}|
% \end{quote}
% This command is useful for printing version information stored in a
% macro. For example the version of this documentation is stored in
% the macro \verb|\docdate| (``\docdate''). To print it with the actual
% date format you can use the command \verb|\printdateTeX{\docdate}|
% which leads to ``\printdateTeX{\docdate}''.
%
% \subsection{Changing the ISO format}
%
% \DescribeMacro{\isodash}%
% I am not sure whether the ISO format should be yyyy-mm-dd or
% yyyy--mm--dd. By default I use ``-'' as dash. You can change this
% using the \verb|\isodash| command, e.g.
% \begin{quote}
% \verb|\printdate{24/12/2000}|\\
% \verb|\isodash{--}|\\
% \verb|\printdate{24/12/2000}|
% \end{quote}
% leads to ``2000-12-24 2000--12--24''. Or for example
% \begin{quote}
% \verb|\isodash{$\cdot$}|\\
% \verb|\printdate{24/12/2000}|
% \end{quote}
% leads to ``2000$\cdot$12$\cdot$24''.
%
% \section{Calling the package}
%
% The package is called using the \verb|\usepackage| command:\\
% \verb|\usepackage[|option\verb|]{isodate}|. 
%
% The possible package options can be seen in table~\ref{tab:options}.
% %
% \begin{table}[h!tbp]
% \centering
% \caption{Package options}
% \label{tab:options}
% \begin{tabular}{ll}\hline
% option&used date format\\ \hline
% \verb|iso|&ISO date format\\
% \verb|num|&numeric date format with 4 digits of the year\\
% \verb|short|&numeric date format with 2 digits of the year\\
% \verb|TeX|&\LaTeX\ numeric date format (yyyy/mm/dd)\\
% \verb|orig|&normal \LaTeX\ date format (default)\\
% \hline
% \end{tabular}
% \end{table}
%
% \appendix
% 
% \section{Licence} 
% 
% Copyright 2000 Harald Harders
%
% This program can be redistributed and/or modified under the terms
% of the LaTeX Project Public License Distributed from CTAN
% archives in directory macros/latex/base/lppl.txt; either
% version 1 of the License, or any later version.
% 
% \section{Known errors}
% \begin{itemize} 
% \item The \verb|\printdate| and \verb|\printdateTeX| commands are not
% very good in checking the argument for correct syntax.
% \item For the language American: Using the package \verb|babel| only
% the language name ``american'' works, using the package
% \verb|*german| only ``USenglish'' works.
% \end{itemize}
%
% \section{Planned features and changes}
%
% \begin{itemize}
% \item Of course eliminate the errors.
% \item Add other languages then german, ngerman, english,
%   USenglish. Please help me with this topic, I don't know the date
%   formats in other languages.
% \end{itemize}
%
% \StopEventually{\PrintChanges \PrintIndex}
%
%
% \section{The implementation}
% \iffalse
%<*package>
% \fi
% Heading of the package:
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{isodateo}[\filedate]
\RequirePackage{ifthen}
\RequirePackage{calc}
\IfFileExists{substr.sty}{\RequirePackage{substr}%
 }{\PackageError{isodateo.sty}{Package file substr.sty not found}
   {This version of isodateo.sty needs the package substr.sty.^^J%
     You can download it from CTAN:/macros/latex/contrib/substr/^^J%
     E.g. one CTAN node is ftp.dante.de. 
     Install substr.sty into your TeX tree.}}
%    \end{macrocode}
% At the end of the preamble the package tests whether one of the
% packages \verb|babel|, \verb|german|, or \verb|ngerman| is loaded. If
% not it is assumed that American English is wanted (\LaTeX\ is an
% American programme). The original date format is saved and the command
% \verb|\iflanguage| is redefined to process the ``true part'' for
% english, american, and USenglish options and otherwise the ``false part''.
% \changes{1.03}{2000/06/13}{Insert code for handling not loaded
% language packages}
%    \begin{macrocode}
\AtBeginDocument{%
  \@ifpackageloaded{babel}{}{%
    \@ifpackageloaded{german}{}{%
      \@ifpackageloaded{ngerman}{}{%
%    \end{macrocode}
% Here you can add new languages. Tell me what you have inserted in
% order to enable me to actualize the package.
%    \begin{macrocode}
        \let\dateamerican\today%
        \setboolean{isodate@american}{true}%
        \def\iflanguage#1#2#3{\ifthenelse{%
            \equal{#1}{english}\or%
            \equal{#1}{american}\or%
            \equal{#1}{USenglish}%
            }{#2}{#3}}%
        }}}}
%    \end{macrocode}
%
% Declare the boolean variable isodate@american. This is necessary
% because the command \textbackslash iflanguage cannot decide if the
% language is English or American.
% \changes{1.02}{2000/06/08}{Fix American language support by a hack}
%    \begin{macrocode}
\newboolean{isodate@american}%
% \changes{1.06}{2000/08/08}{Avoid using the hack with redefining
% \selectlanguage}
% Define the package options.
%    \begin{macrocode}
\DeclareOption{iso}{\AtBeginDocument{\isodate}}
\DeclareOption{num}{\AtBeginDocument{\numdate}}
\DeclareOption{short}{\AtBeginDocument{\shortdate}}
\DeclareOption{TeX}{\AtBeginDocument{\TeXdate}}
\DeclareOption{orig}{\AtBeginDocument{\origdate}}
\ExecuteOptions{orig}
\ProcessOptions
%    \end{macrocode}
% Print day or month filled with zero to a format with two digits.
%    \begin{macrocode}
\def\dday{\ifthenelse{\number\day<10}{0}{}\number\day}
\def\dmonth{\ifthenelse{\number\month<10}{0}{}\number\month}
%    \end{macrocode}
% Print day and month in numerical format using the right format for
% the present language.
%    \begin{macrocode}
\DeclareRobustCommand*{\num@today}[1]{%
  \iflanguage{german}{\dday.\,\dmonth.#1}{%
    \iflanguage{austrian}{\dday.\,\dmonth.#1}{%
      \iflanguage{ngerman}{\dday.\,\dmonth.#1}{%
        \iflanguage{naustrian}{\dday.\,\dmonth.#1}{%
%    \end{macrocode}
% Here you can add new languages. Tell me what you have inserted in
% order to enable me to actualize the package.
%    \begin{macrocode}
          \iflanguage{english}{%
            \ifthenelse{\boolean{isodate@american}}{%
              \dmonth/\dday/}{\dday/\dmonth/}}{%
  \dday/\dmonth/}}}}}%
}
%    \end{macrocode}
% \begin{macro}{\numdate}
% Switch to long numeric date format.
%    \begin{macrocode}
\DeclareRobustCommand*{\numdate}{%
%    \end{macrocode}
% Find out whether the language may be English or American. The
% English original date format does not contain a komma while the
% american does.
% \changes{1.06}{2000/08/08}{Choose between English and American language}
%    \begin{macrocode}
  \origdate%
  \setboolean{isodate@american}{false}%
  \iflanguage{american}{\IfCharInString{,}{\today}{%
    \setboolean{isodate@american}{true}}{}}{}%
%    \end{macrocode}
% Define the new \textbackslash today command.
%    \begin{macrocode}
  \gdef\today{%
    \num@today{~}%
    \number\year}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\shortdate}
% Switch to short numeric date format.
%    \begin{macrocode}
\newcounter{yeartwo}
\DeclareRobustCommand*{\shortdate}{%
%    \end{macrocode}
% Find out whether the language may be English or American. The
% English original date format does not contain a komma while the
% american does.
% \changes{1.06}{2000/08/08}{Choose between English and American language}
%    \begin{macrocode}
  \origdate%
  \setboolean{isodate@american}{false}%
  \iflanguage{american}{\IfCharInString{,}{\today}{%
    \setboolean{isodate@american}{true}}{}}{}%
%    \end{macrocode}
% Define the new \textbackslash today command.
%    \begin{macrocode}
  \gdef\today{%
    \num@today{\,}%
    \setcounter{yeartwo}{\number\year}%
    \whiledo{\theyeartwo>99}{\setcounter{yeartwo}{\theyeartwo-100}}{}%
    \ifthenelse{\number\theyeartwo<10}{0}{}\theyeartwo}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\isodate}
% Switch to ISO date format.
%    \begin{macrocode}
\DeclareRobustCommand*{\isodate}{%
  \gdef\today{%
    \number\year\iso@isodash%
    \ifthenelse{\number\month<10}{0}{}\number\month\iso@isodash%
    \ifthenelse{\number\day<10}{0}{}\number\day}}
%    \end{macrocode}
% \end{macro}
% Define the default ISO dash to ``-''.
%    \begin{macrocode}
\def\iso@isodash{-}%
%    \end{macrocode}
% \begin{macro}{\isodate}
% Define the command \verb|\isodash| which changes the dash in the ISO 
% date format.
%    \begin{macrocode}
\DeclareRobustCommand*{\isodash}[1]{\def\iso@isodash{#1}}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\origdate}
% Switch back to original date format.
% \changes{1.06}{2000/08/08}{Use the command \textbackslash
% date\emph{language} to switch back to the original date format}
%    \begin{macrocode}
%\DeclareRobustCommand*{\origdate}{\gdef\today{\iso@origdate}}
\DeclareRobustCommand*{\origdate}{\csname date\languagename\endcsname}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\TeXdate}
% \changes{1.04}{2000/06/13}{Add \LaTeX\ date format yyyy/mm/dd}
% Switch to the \TeX\ date format.
%    \begin{macrocode}
\DeclareRobustCommand*{\TeXdate}{%
  \gdef\today{%
    \number\year/%
    \ifthenelse{\number\month<10}{0}{}\number\month/%
    \ifthenelse{\number\day<10}{0}{}\number\day}}
%    \end{macrocode}
% \end{macro}
% Print any date (internal command, syntax:
% \verb|\iso@printdate{yyyy}{mm}{dd}|). 
%    \begin{macrocode}
\DeclareRobustCommand*{\iso@printdate}[3]{%
  \begingroup%
  \def\year{#1}%
  \def\month{#2}%
  \def\day{#3}%
  \today%
  \endgroup%
}
%    \end{macrocode}
% Define counters to count the numbers of special characters in the
% arguments of the \verb|\printdate| and \verb|\printdateTeX| commands.
%    \begin{macrocode}
\newcounter{iso@slash}
\newcounter{iso@minus}
\newcounter{iso@dot}
%    \end{macrocode}
% \begin{macro}{\printdate}
% Print any date in the actual date format. This command understands
% the German, British, and ISO formats.
%    \begin{macrocode}
\DeclareRobustCommand*{\printdate}[1]{%
  \expandafter\iso@expafterprintdate\expandafter{#1}}%
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\iso@expafterprintdate}
% The command \verb|\iso@expafterprintdate| needs an already expanded
% argument. So the command \verb|\printdate| expands it and calls
% \verb|\iso@expafterprintdate|.
%
% The error handling of this macro is very poor. It is just tested if
% either a ``/'', ``-'', or ``.'' is included in the argument
% twice. It is not tested if the argument consists of numbers, only.
% \changes{1.05}{2000/06/15}{Count appearances of ``/'', ``.'', and
% ``-'' and complain if not at least one of them is equal to 2}
%    \begin{macrocode}
\DeclareRobustCommand*{\iso@expafterprintdate}[1]{%
  \SubStringsToCounter{iso@slash}{/}{#1}%
  \SubStringsToCounter{iso@minus}{-}{#1}%
  \SubStringsToCounter{iso@dot}{.}{#1}%
  \ifthenelse{\equal{\theiso@dot}{2}}{\printdatenumger{#1}}{%
    \ifthenelse{\equal{\theiso@minus}{2}}{\printdateiso{#1}}{%
      \ifthenelse{\equal{\theiso@slash}{2}}{\printdatenumeng{#1}}{%
        ????\iso@isodash ??\iso@isodash ??%
        \PackageError{isodateo}{unrecognized date format}{Use one of
          the following formats as macro argument:^^J%
          \space\space dd.mm.yyyy^^J%
          \space\space dd/mm/yyyy^^J%
          \space\space yyyy-mm-dd^^J%
          Don't use any spaces or commands like \protect\, or
          \protect~ inside the argument.}%
        }}}}
%    \end{macrocode}
% \end{macro}
% Analyze the argument containing a date in ISO format an print
% it. This macros does not contain any error handling.
%    \begin{macrocode}
\DeclareRobustCommand*{\printdateiso}[1]{%
  \expandafter\iso@printdateiso #1\@empty}
\def\iso@printdateiso#1-#2-#3\@empty{\iso@printdate{#1}{#2}{#3}}
%    \end{macrocode}
% Analyze the argument containing a date in German numeric format an
% print it. This macros does not contain any error handling.
%    \begin{macrocode}
\DeclareRobustCommand*{\printdatenumger}[1]{%
  \expandafter\iso@printdatenumger #1\@empty}
\def\iso@printdatenumger#1.#2.#3\@empty{\iso@printdate{#3}{#2}{#1}}
%    \end{macrocode}
% Analyze the argument containing a date in Britisch English numeric
% format an print it. This macros does not contain any error handling.
%    \begin{macrocode}
\DeclareRobustCommand*{\printdatenumeng}[1]{%
  \expandafter\iso@printdatenumeng #1\@empty}
\def\iso@printdatenumeng#1/#2/#3\@empty{\iso@printdate{#3}{#2}{#1}}
%    \end{macrocode}
% \changes{1.04}{2000/06/13}{Add \LaTeX\ date format yyyy/mm/dd}
% \begin{macro}{\printdateTeX}
% Analyze the argument containing a date in the LaTeX style yyyy/mm/dd
% an print it. This format can not be handled automaticaly by
% \verb|\printdate| because it could be mixed up with the English
% format. The error handling of this routine is very poor. It just
% checks whether the argument contains at least one ``/''.
% \changes{1.05}{2000/06/15}{Count appearances of ``/'' and complain
% if not equal to 2}
%    \begin{macrocode}
\DeclareRobustCommand*{\printdateTeX}[1]{%
  \expandafter\iso@printdateTeX\expandafter{#1}}
\DeclareRobustCommand*{\iso@printdateTeX}[1]{%
  \SubStringsToCounter{iso@slash}{/}{#1}%
  \ifthenelse{\equal{\theiso@slash}{2}}%
  {\expandafter\iso@@printdateTeX #1\@empty}{%
    ????\iso@isodash ??\iso@isodash ??%
    \PackageError{isodateo}{unrecognized date format}{Use the format
      yyyy/mm/dd.^^J%
      Don't use any spaces or commands like \protect\, or
      \protect~ inside the argument.}}% 
}
\def\iso@@printdateTeX#1/#2/#3\@empty{\iso@printdate{#1}{#2}{#3}}
%    \end{macrocode}
% \end{macro}
% The end of the package.
% \iffalse
%</package>
% \fi
% \Finale