Debian Codegraph @

texmf-dist/source/latex/isodate/isodateo.dtx

raw
1 % \iffalse meta comment
2 % File: isodateo.dtx Copyright (C) 2000 Harald Harders
3 % \fi
4 %
5 % \iffalse
6 %
7 %<*package>
8 \def\packagename{isodateo}
9 \def\fileversion{1.06a}
10 \def\filedate{2004/02/12}
11 \def\docdate{2000/08/08}
12 %</package>
13 %<*driver>
14 \documentclass{ltxdoc}
15 \IfFileExists{isodateo.sty}{\usepackage{isodateo}
16 \let\isodateoSTYfound\active}{\GenericWarning{isodateo.dtx}{Package
17 file isodateo.sty not found (Documentation will be messed up!^^J^^A
18 Generate isodateo.sty by (La)TeXing isodateo.ins, process
19 isodateo.dtx again)^^J}\stop}
20 \usepackage{array}
21 \isodate
22 \title{The \texttt{isodateo} package\thanks{This file has version
23 \fileversion\ last revised \printdateTeX{\filedate},
24 documentation dated \printdateTeX{\docdate}.}}
25 \author{Harald Harders\\\texttt{[email protected]}}
26 \date{File Date \printdateTeX{\filedate}, Printed \today}
27 \newlength{\tempdima}%
28 \makeatletter
29 \renewenvironment{table}[1][]{%
30 \@float{table}[#1]%
31 \centering%
32 \setlength{\tempdima}{\abovecaptionskip}%
33 \setlength{\abovecaptionskip}{\belowcaptionskip}%
34 \setlength{\belowcaptionskip}{\tempdima}%
35 }{%
36 \end@float
37 }
38 \makeatother
39 \EnableCrossrefs
40 \CodelineIndex
41 \DoNotIndex{\def,\edef,\let,\newcommand,\newenvironment,\newcounter,%
42 \gdef,\@ifundefined,\@empty,\@firstoftwo,\@secondoftwo,\@nil,%
43 \,,\number,\renewcommand,\setboolean,\whiledo}
44 \DoNotIndex{\setcounter,\space}
45 \CodelineNumbered
46 \RecordChanges
47 \CheckSum{272}
48 \begin{document}
49 \DocInput{isodateo.dtx}
50 \end{document}
51 %</driver>
52 % \fi
53 %
54 % \changes{1.06a}{2004/02/12}{Path changed according to new CTAN
55 % structure}%
56 % \changes{1.05}{2000/06/15}{Throw out the commands \textbackslash
57 % IfSubStringInString and \textbackslash IfCharInString and use the
58 % package substr.sty instead}
59 % \changes{1.05}{2000/06/15}{Change all internal command names to
60 % start with \textbackslash iso@}
61 % \changes{1.04}{2000/06/13}{Make the commands robust}
62 % \changes{1.01}{2000/06/08}{Improve documentation}
63 % \maketitle
64 %
65 % \begin{abstract}
66 % \noindent This package provides commands to switch between different
67 % date formats (standard, ISO, numeric, \LaTeX\ package). They are used by the
68 % \verb|\today| command and by the \verb|\printdate| and
69 % \verb|\printdateTeX| commands that print any date.
70 % This package supports German (old and new rules, Austrian), US
71 % English, and all languages that have the same date format as British
72 % English does\footnote{E.g. Danish, French}.
73 %
74 % The idea for this package was taken from the akletter class.
75 % \end{abstract}
76 %
77 % \tableofcontents
78 %
79 % \section{Commands}
80 %
81 % \subsection{Switching the date format}
82 %
83 % \DescribeMacro{\today}%
84 % This package provides five commands to switch the output format of
85 % the \verb|\today|, the \verb|\printdate|, and the
86 % \verb|\printdateTeX| commands:
87 % \medskip
88 %
89 % \DescribeMacro{\isodate}%
90 % \DescribeMacro{\numdate}%
91 % \DescribeMacro{\shortdate}%
92 % \DescribeMacro{\TeXdate}%
93 % \DescribeMacro{\origdate}%
94 % \begin{tabular}{@{}ll}
95 % \verb|\isodate|&date format described in ISO 8601 and DIN 5008\\
96 % &(yyyy-mm-dd)\\
97 % \verb|\numdate|&numeric date format with four digits of the year\\
98 % \verb|\shortdate|&short numeric date format with two digits of the
99 % year\\
100 % \verb|\TeXdate|&date format used for version description of
101 % packages\\
102 % &(yyyy/mm/dd)\\
103 % \verb|\origdate|&original \LaTeX\ format
104 % \end{tabular}
105 % \medskip
106 %
107 % The numeric and short numeric format change their behaviour
108 % depending on the actual language:
109 %
110 % \noindent\begin{tabular}{@{}llll@{}}
111 % German, nGerman&\verb|dd.\,mm.~yyyy|&resp.&\verb|dd.\,mm.\,yy|\\
112 % US English&\verb|mm/dd/yyyy|&resp.&\verb|mm/dd/yy|\\
113 % other languages&\verb|dd/mm/yyyy|&resp.&\verb|dd/mm/yy|
114 % \end{tabular}
115 %
116 % So this package supports German (old and new rules, Austrian), US
117 % English, and all languages that have the same date format as British
118 % English does\footnote{E.g. Danish, French}.
119 % \changes{1.05}{2000/06/29}{Note that every language that has the
120 % same format as English is supported.}
121 % Switching the language by using \textbackslash selectlanguage also
122 % switches back to the original date format.
123 %
124 % \subsection{Printing any date}
125 %
126 % \DescribeMacro{\printdate}%
127 % The command \verb|\printdate{#1}| prints any date in the actual
128 % format. The argument may be a date in German, British English, or
129 % ISO format, e.g.\\
130 % \begin{quote}
131 % \verb|\printdate{24.12.2000}|\\
132 % \verb|\printdate{24/12/2000}|\\
133 % \verb|\printdate{2000-12-24}|
134 % \end{quote}
135 %
136 % \DescribeMacro{\printdateTeX}%
137 % The command \verb|\printdateTeX{#1}| prints any date in the actual
138 % format. The argument must be in the \LaTeX\ format \verb|yyyy/mm/dd|, e.g.\\
139 % \begin{quote}
140 % \verb|\printdateTeX{2000/12/24}|
141 % \end{quote}
142 % This command is useful for printing version information stored in a
143 % macro. For example the version of this documentation is stored in
144 % the macro \verb|\docdate| (``\docdate''). To print it with the actual
145 % date format you can use the command \verb|\printdateTeX{\docdate}|
146 % which leads to ``\printdateTeX{\docdate}''.
147 %
148 % \subsection{Changing the ISO format}
149 %
150 % \DescribeMacro{\isodash}%
151 % I am not sure whether the ISO format should be yyyy-mm-dd or
152 % yyyy--mm--dd. By default I use ``-'' as dash. You can change this
153 % using the \verb|\isodash| command, e.g.
154 % \begin{quote}
155 % \verb|\printdate{24/12/2000}|\\
156 % \verb|\isodash{--}|\\
157 % \verb|\printdate{24/12/2000}|
158 % \end{quote}
159 % leads to ``2000-12-24 2000--12--24''. Or for example
160 % \begin{quote}
161 % \verb|\isodash{$\cdot$}|\\
162 % \verb|\printdate{24/12/2000}|
163 % \end{quote}
164 % leads to ``2000$\cdot$12$\cdot$24''.
165 %
166 % \section{Calling the package}
167 %
168 % The package is called using the \verb|\usepackage| command:\\
169 % \verb|\usepackage[|option\verb|]{isodate}|.
170 %
171 % The possible package options can be seen in table~\ref{tab:options}.
172 % %
173 % \begin{table}[h!tbp]
174 % \centering
175 % \caption{Package options}
176 % \label{tab:options}
177 % \begin{tabular}{ll}\hline
178 % option&used date format\\ \hline
179 % \verb|iso|&ISO date format\\
180 % \verb|num|&numeric date format with 4 digits of the year\\
181 % \verb|short|&numeric date format with 2 digits of the year\\
182 % \verb|TeX|&\LaTeX\ numeric date format (yyyy/mm/dd)\\
183 % \verb|orig|&normal \LaTeX\ date format (default)\\
184 % \hline
185 % \end{tabular}
186 % \end{table}
187 %
188 % \appendix
189 %
190 % \section{Licence}
191 %
192 % Copyright 2000 Harald Harders
193 %
194 % This program can be redistributed and/or modified under the terms
195 % of the LaTeX Project Public License Distributed from CTAN
196 % archives in directory macros/latex/base/lppl.txt; either
197 % version 1 of the License, or any later version.
198 %
199 % \section{Known errors}
200 % \begin{itemize}
201 % \item The \verb|\printdate| and \verb|\printdateTeX| commands are not
202 % very good in checking the argument for correct syntax.
203 % \item For the language American: Using the package \verb|babel| only
204 % the language name ``american'' works, using the package
205 % \verb|*german| only ``USenglish'' works.
206 % \end{itemize}
207 %
208 % \section{Planned features and changes}
209 %
210 % \begin{itemize}
211 % \item Of course eliminate the errors.
212 % \item Add other languages then german, ngerman, english,
213 % USenglish. Please help me with this topic, I don't know the date
214 % formats in other languages.
215 % \end{itemize}
216 %
217 % \StopEventually{\PrintChanges \PrintIndex}
218 %
219 %
220 % \section{The implementation}
221 % \iffalse
222 %<*package>
223 % \fi
224 % Heading of the package:
225 % \begin{macrocode}
226 \NeedsTeXFormat{LaTeX2e}
227 \ProvidesPackage{isodateo}[\filedate]
228 \RequirePackage{ifthen}
229 \RequirePackage{calc}
230 \IfFileExists{substr.sty}{\RequirePackage{substr}%
231 }{\PackageError{isodateo.sty}{Package file substr.sty not found}
232 {This version of isodateo.sty needs the package substr.sty.^^J%
233 You can download it from CTAN:/macros/latex/contrib/substr/^^J%
234 E.g. one CTAN node is ftp.dante.de.
235 Install substr.sty into your TeX tree.}}
236 % \end{macrocode}
237 % At the end of the preamble the package tests whether one of the
238 % packages \verb|babel|, \verb|german|, or \verb|ngerman| is loaded. If
239 % not it is assumed that American English is wanted (\LaTeX\ is an
240 % American programme). The original date format is saved and the command
241 % \verb|\iflanguage| is redefined to process the ``true part'' for
242 % english, american, and USenglish options and otherwise the ``false part''.
243 % \changes{1.03}{2000/06/13}{Insert code for handling not loaded
244 % language packages}
245 % \begin{macrocode}
246 \AtBeginDocument{%
247 \@ifpackageloaded{babel}{}{%
248 \@ifpackageloaded{german}{}{%
249 \@ifpackageloaded{ngerman}{}{%
250 % \end{macrocode}
251 % Here you can add new languages. Tell me what you have inserted in
252 % order to enable me to actualize the package.
253 % \begin{macrocode}
254 \let\dateamerican\today%
255 \setboolean{isodate@american}{true}%
256 \def\iflanguage#1#2#3{\ifthenelse{%
257 \equal{#1}{english}\or%
258 \equal{#1}{american}\or%
259 \equal{#1}{USenglish}%
260 }{#2}{#3}}%
261 }}}}
262 % \end{macrocode}
263 %
264 % Declare the boolean variable isodate@american. This is necessary
265 % because the command \textbackslash iflanguage cannot decide if the
266 % language is English or American.
267 % \changes{1.02}{2000/06/08}{Fix American language support by a hack}
268 % \begin{macrocode}
269 \newboolean{isodate@american}%
270 % \changes{1.06}{2000/08/08}{Avoid using the hack with redefining
271 % \selectlanguage}
272 % Define the package options.
273 % \begin{macrocode}
274 \DeclareOption{iso}{\AtBeginDocument{\isodate}}
275 \DeclareOption{num}{\AtBeginDocument{\numdate}}
276 \DeclareOption{short}{\AtBeginDocument{\shortdate}}
277 \DeclareOption{TeX}{\AtBeginDocument{\TeXdate}}
278 \DeclareOption{orig}{\AtBeginDocument{\origdate}}
279 \ExecuteOptions{orig}
280 \ProcessOptions
281 % \end{macrocode}
282 % Print day or month filled with zero to a format with two digits.
283 % \begin{macrocode}
284 \def\dday{\ifthenelse{\number\day<10}{0}{}\number\day}
285 \def\dmonth{\ifthenelse{\number\month<10}{0}{}\number\month}
286 % \end{macrocode}
287 % Print day and month in numerical format using the right format for
288 % the present language.
289 % \begin{macrocode}
290 \DeclareRobustCommand*{\num@today}[1]{%
291 \iflanguage{german}{\dday.\,\dmonth.#1}{%
292 \iflanguage{austrian}{\dday.\,\dmonth.#1}{%
293 \iflanguage{ngerman}{\dday.\,\dmonth.#1}{%
294 \iflanguage{naustrian}{\dday.\,\dmonth.#1}{%
295 % \end{macrocode}
296 % Here you can add new languages. Tell me what you have inserted in
297 % order to enable me to actualize the package.
298 % \begin{macrocode}
299 \iflanguage{english}{%
300 \ifthenelse{\boolean{isodate@american}}{%
301 \dmonth/\dday/}{\dday/\dmonth/}}{%
302 \dday/\dmonth/}}}}}%
303 }
304 % \end{macrocode}
305 % \begin{macro}{\numdate}
306 % Switch to long numeric date format.
307 % \begin{macrocode}
308 \DeclareRobustCommand*{\numdate}{%
309 % \end{macrocode}
310 % Find out whether the language may be English or American. The
311 % English original date format does not contain a komma while the
312 % american does.
313 % \changes{1.06}{2000/08/08}{Choose between English and American language}
314 % \begin{macrocode}
315 \origdate%
316 \setboolean{isodate@american}{false}%
317 \iflanguage{american}{\IfCharInString{,}{\today}{%
318 \setboolean{isodate@american}{true}}{}}{}%
319 % \end{macrocode}
320 % Define the new \textbackslash today command.
321 % \begin{macrocode}
322 \gdef\today{%
323 \num@today{~}%
324 \number\year}}
325 % \end{macrocode}
326 % \end{macro}
327 % \begin{macro}{\shortdate}
328 % Switch to short numeric date format.
329 % \begin{macrocode}
330 \newcounter{yeartwo}
331 \DeclareRobustCommand*{\shortdate}{%
332 % \end{macrocode}
333 % Find out whether the language may be English or American. The
334 % English original date format does not contain a komma while the
335 % american does.
336 % \changes{1.06}{2000/08/08}{Choose between English and American language}
337 % \begin{macrocode}
338 \origdate%
339 \setboolean{isodate@american}{false}%
340 \iflanguage{american}{\IfCharInString{,}{\today}{%
341 \setboolean{isodate@american}{true}}{}}{}%
342 % \end{macrocode}
343 % Define the new \textbackslash today command.
344 % \begin{macrocode}
345 \gdef\today{%
346 \num@today{\,}%
347 \setcounter{yeartwo}{\number\year}%
348 \whiledo{\theyeartwo>99}{\setcounter{yeartwo}{\theyeartwo-100}}{}%
349 \ifthenelse{\number\theyeartwo<10}{0}{}\theyeartwo}}
350 % \end{macrocode}
351 % \end{macro}
352 % \begin{macro}{\isodate}
353 % Switch to ISO date format.
354 % \begin{macrocode}
355 \DeclareRobustCommand*{\isodate}{%
356 \gdef\today{%
357 \number\year\iso@isodash%
358 \ifthenelse{\number\month<10}{0}{}\number\month\iso@isodash%
359 \ifthenelse{\number\day<10}{0}{}\number\day}}
360 % \end{macrocode}
361 % \end{macro}
362 % Define the default ISO dash to ``-''.
363 % \begin{macrocode}
364 \def\iso@isodash{-}%
365 % \end{macrocode}
366 % \begin{macro}{\isodate}
367 % Define the command \verb|\isodash| which changes the dash in the ISO
368 % date format.
369 % \begin{macrocode}
370 \DeclareRobustCommand*{\isodash}[1]{\def\iso@isodash{#1}}%
371 % \end{macrocode}
372 % \end{macro}
373 % \begin{macro}{\origdate}
374 % Switch back to original date format.
375 % \changes{1.06}{2000/08/08}{Use the command \textbackslash
376 % date\emph{language} to switch back to the original date format}
377 % \begin{macrocode}
378 %\DeclareRobustCommand*{\origdate}{\gdef\today{\iso@origdate}}
379 \DeclareRobustCommand*{\origdate}{\csname date\languagename\endcsname}
380 % \end{macrocode}
381 % \end{macro}
382 % \begin{macro}{\TeXdate}
383 % \changes{1.04}{2000/06/13}{Add \LaTeX\ date format yyyy/mm/dd}
384 % Switch to the \TeX\ date format.
385 % \begin{macrocode}
386 \DeclareRobustCommand*{\TeXdate}{%
387 \gdef\today{%
388 \number\year/%
389 \ifthenelse{\number\month<10}{0}{}\number\month/%
390 \ifthenelse{\number\day<10}{0}{}\number\day}}
391 % \end{macrocode}
392 % \end{macro}
393 % Print any date (internal command, syntax:
394 % \verb|\iso@printdate{yyyy}{mm}{dd}|).
395 % \begin{macrocode}
396 \DeclareRobustCommand*{\iso@printdate}[3]{%
397 \begingroup%
398 \def\year{#1}%
399 \def\month{#2}%
400 \def\day{#3}%
401 \today%
402 \endgroup%
403 }
404 % \end{macrocode}
405 % Define counters to count the numbers of special characters in the
406 % arguments of the \verb|\printdate| and \verb|\printdateTeX| commands.
407 % \begin{macrocode}
408 \newcounter{iso@slash}
409 \newcounter{iso@minus}
410 \newcounter{iso@dot}
411 % \end{macrocode}
412 % \begin{macro}{\printdate}
413 % Print any date in the actual date format. This command understands
414 % the German, British, and ISO formats.
415 % \begin{macrocode}
416 \DeclareRobustCommand*{\printdate}[1]{%
417 \expandafter\iso@expafterprintdate\expandafter{#1}}%
418 % \end{macrocode}
419 % \end{macro}
420 % \begin{macro}{\iso@expafterprintdate}
421 % The command \verb|\iso@expafterprintdate| needs an already expanded
422 % argument. So the command \verb|\printdate| expands it and calls
423 % \verb|\iso@expafterprintdate|.
424 %
425 % The error handling of this macro is very poor. It is just tested if
426 % either a ``/'', ``-'', or ``.'' is included in the argument
427 % twice. It is not tested if the argument consists of numbers, only.
428 % \changes{1.05}{2000/06/15}{Count appearances of ``/'', ``.'', and
429 % ``-'' and complain if not at least one of them is equal to 2}
430 % \begin{macrocode}
431 \DeclareRobustCommand*{\iso@expafterprintdate}[1]{%
432 \SubStringsToCounter{iso@slash}{/}{#1}%
433 \SubStringsToCounter{iso@minus}{-}{#1}%
434 \SubStringsToCounter{iso@dot}{.}{#1}%
435 \ifthenelse{\equal{\theiso@dot}{2}}{\printdatenumger{#1}}{%
436 \ifthenelse{\equal{\theiso@minus}{2}}{\printdateiso{#1}}{%
437 \ifthenelse{\equal{\theiso@slash}{2}}{\printdatenumeng{#1}}{%
438 ????\iso@isodash ??\iso@isodash ??%
439 \PackageError{isodateo}{unrecognized date format}{Use one of
440 the following formats as macro argument:^^J%
441 \space\space dd.mm.yyyy^^J%
442 \space\space dd/mm/yyyy^^J%
443 \space\space yyyy-mm-dd^^J%
444 Don't use any spaces or commands like \protect\, or
445 \protect~ inside the argument.}%
446 }}}}
447 % \end{macrocode}
448 % \end{macro}
449 % Analyze the argument containing a date in ISO format an print
450 % it. This macros does not contain any error handling.
451 % \begin{macrocode}
452 \DeclareRobustCommand*{\printdateiso}[1]{%
453 \expandafter\iso@printdateiso #1\@empty}
454 \def\iso@printdateiso#1-#2-#3\@empty{\iso@printdate{#1}{#2}{#3}}
455 % \end{macrocode}
456 % Analyze the argument containing a date in German numeric format an
457 % print it. This macros does not contain any error handling.
458 % \begin{macrocode}
459 \DeclareRobustCommand*{\printdatenumger}[1]{%
460 \expandafter\iso@printdatenumger #1\@empty}
461 \def\iso@printdatenumger#1.#2.#3\@empty{\iso@printdate{#3}{#2}{#1}}
462 % \end{macrocode}
463 % Analyze the argument containing a date in Britisch English numeric
464 % format an print it. This macros does not contain any error handling.
465 % \begin{macrocode}
466 \DeclareRobustCommand*{\printdatenumeng}[1]{%
467 \expandafter\iso@printdatenumeng #1\@empty}
468 \def\iso@printdatenumeng#1/#2/#3\@empty{\iso@printdate{#3}{#2}{#1}}
469 % \end{macrocode}
470 % \changes{1.04}{2000/06/13}{Add \LaTeX\ date format yyyy/mm/dd}
471 % \begin{macro}{\printdateTeX}
472 % Analyze the argument containing a date in the LaTeX style yyyy/mm/dd
473 % an print it. This format can not be handled automaticaly by
474 % \verb|\printdate| because it could be mixed up with the English
475 % format. The error handling of this routine is very poor. It just
476 % checks whether the argument contains at least one ``/''.
477 % \changes{1.05}{2000/06/15}{Count appearances of ``/'' and complain
478 % if not equal to 2}
479 % \begin{macrocode}
480 \DeclareRobustCommand*{\printdateTeX}[1]{%
481 \expandafter\iso@printdateTeX\expandafter{#1}}
482 \DeclareRobustCommand*{\iso@printdateTeX}[1]{%
483 \SubStringsToCounter{iso@slash}{/}{#1}%
484 \ifthenelse{\equal{\theiso@slash}{2}}%
485 {\expandafter\iso@@printdateTeX #1\@empty}{%
486 ????\iso@isodash ??\iso@isodash ??%
487 \PackageError{isodateo}{unrecognized date format}{Use the format
488 yyyy/mm/dd.^^J%
489 Don't use any spaces or commands like \protect\, or
490 \protect~ inside the argument.}}%
491 }
492 \def\iso@@printdateTeX#1/#2/#3\@empty{\iso@printdate{#1}{#2}{#3}}
493 % \end{macrocode}
494 % \end{macro}
495 % The end of the package.
496 % \iffalse
497 %</package>
498 % \fi
499 % \Finale