diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/isodate/isodateo.dtx |
Initial commit
Diffstat (limited to 'macros/latex/contrib/isodate/isodateo.dtx')
-rw-r--r-- | macros/latex/contrib/isodate/isodateo.dtx | 499 |
1 files changed, 499 insertions, 0 deletions
diff --git a/macros/latex/contrib/isodate/isodateo.dtx b/macros/latex/contrib/isodate/isodateo.dtx new file mode 100644 index 0000000000..cf92ac9f94 --- /dev/null +++ b/macros/latex/contrib/isodate/isodateo.dtx @@ -0,0 +1,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 |