summaryrefslogtreecommitdiff
path: root/macros/latex/base/ltclass.dtx
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-10-05 03:01:15 +0000
committerNorbert Preining <norbert@preining.info>2019-10-05 03:01:15 +0000
commit72c9345e5bafe708888bf65448a81d1aee8275ed (patch)
treea1a99929b3d7307572844833f09ad7ba5ad1405d /macros/latex/base/ltclass.dtx
parent9d9c04e14d0da9dd7829d0ec896aabfd50414fd8 (diff)
CTAN sync 201910050301
Diffstat (limited to 'macros/latex/base/ltclass.dtx')
-rw-r--r--macros/latex/base/ltclass.dtx282
1 files changed, 251 insertions, 31 deletions
diff --git a/macros/latex/base/ltclass.dtx b/macros/latex/base/ltclass.dtx
index 2f19c74352..3d19971701 100644
--- a/macros/latex/base/ltclass.dtx
+++ b/macros/latex/base/ltclass.dtx
@@ -1,6 +1,6 @@
% \iffalse meta-comment
%
-% Copyright 1993-2018
+% Copyright (C) 1993-2019
% The LaTeX3 Project and any individual authors listed elsewhere
% in this file.
%
@@ -13,7 +13,7 @@
% The latest version of this license is in
% https://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.
+% version 2008 or later.
%
% This file has the LPPL maintenance status "maintained".
%
@@ -33,7 +33,7 @@
%<*driver>
% \fi
\ProvidesFile{ltclass.dtx}
- [2018/05/29 v1.2j LaTeX Kernel (Class & Package Interface)]
+ [2019/09/11 v1.3c LaTeX Kernel (Class & Package Interface)]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{ltclass.dtx}
@@ -155,11 +155,27 @@
% verbatim to the file name given as the first argument, together with
% some comments about how it was produced.
%
-% The environment is allowed only before |\documentclass| to ensure
-% that all packages or options necessary for this particular run are
-% present when needed. The begin and end tags should each be on a
-% line by itself. There is also a star-form; this does not write
-% extra comments into the file.
+% The package can also be called with an optional argument which is
+% used to alter some of its behavior: option \texttt{force} or
+% \texttt{overwrite} will allow for overwriting existing files,
+% option \texttt{nosearch} will only check the current directory
+% when looking if the file exists. This can be useful if you want to
+% generate a local (modified) copy of some file that is already in the
+% search tree of \TeX{}. Finally, you can use \texttt{nopremable} to
+% prevent it from writing the standard blurb at the top of the file
+% (this is actually the same as using the star form of the environment).
+%
+% The environment is now allowed anywhere in the document, but to ensure
+% that all packages or options necessary are available when the
+% document is run, it is normally best to place it at the top of your
+% file (before \cs{documentclass}).
+% A possible use case for using it inside the document body is if you
+% want to reuse some text several times in the document you could then
+% write it and later use \cs{input} to retrieve it where needed.
+%
+%
+% The begin and end tags should each be on a
+% line by itself.
%
% \subsection{Option processing}
%
@@ -1580,8 +1596,8 @@
% \end{macrocode}
%
% \begin{macrocode}
-\def\AtBeginDocument{\g@addto@macro\@begindocumenthook}
-\def\AtEndDocument{\g@addto@macro\@enddocumenthook}
+\DeclareRobustCommand\AtBeginDocument{\g@addto@macro\@begindocumenthook}
+\DeclareRobustCommand\AtEndDocument{\g@addto@macro\@enddocumenthook}
\@onlypreamble\AtBeginDocument
% \end{macrocode}
% \end{macro}
@@ -1705,6 +1721,69 @@
% {Close input check stream: latex/1487}
% \changes{v1.0p}{1995/05/25}{Delete \cs{filec@ntents} after preamble}
% \begin{macrocode}
+% \changes{v1.3a}{2019/07/01}{Support UTF8 and spaces in
+% filecontents environment file name}
+% \changes{v1.3b}{2019/08/27}{Make various commands robust}
+% \changes{v1.3c}{2019/09/11}{Support optional argument for filecontents}
+%
+%</2ekernel>
+%<*2ekernel|latexrelease>
+%<latexrelease>\IncludeInRelease{2019/10/01}%
+%<latexrelease> {\filec@ntents}{Spaces in file names + optional arg}%
+%
+
+
+% \end{macrocode}
+% We use |@tempswa| to mean no preamble writing and reuse |@filesw|
+% to indicate no overwriting:
+% \begin{macrocode}
+\def\filecontents{\@tempswatrue\@fileswtrue
+ \@ifnextchar[\filec@ntents@opt\filec@ntents
+}
+\@namedef{filecontents*}{\@tempswafalse\@fileswtrue
+ \@ifnextchar[\filec@ntents@opt\filec@ntents
+}
+% \end{macrocode}
+% To handle the optional argument we execute for each option the
+% command \cs{filec@ntents@OPTION} if it exist or complain about
+% unknown option.
+% \begin{macrocode}
+\def\filec@ntents@opt[#1]{%
+ \@for\@tempa:=#1\do{%
+ \ifcsname filec@ntents@\@tempa\endcsname
+ \csname filec@ntents@\@tempa\endcsname
+ \else
+ \@latex@error{Unknown filecontents option #1}%
+ {Valid options are force (or overwrite), nosearch, noheader}%
+ \fi}%
+ \filec@ntents
+}
+% \end{macrocode}
+% Option \texttt{force}) (or \texttt{overwrite}) changes the
+% overwriting switch
+% \begin{macrocode}
+\let\filec@ntents@force\@fileswfalse
+\let\filec@ntents@overwrite\@fileswfalse % alternative name
+% \end{macrocode}
+% and option \texttt{noheader} the preamble switch (which is
+% equivalent to using the star form of the environment).
+% \begin{macrocode}
+\let\filec@ntents@noheader\@tempswafalse
+% \end{macrocode}
+% Option \texttt{nosearch} only checks the current directory not
+% the how \TeX{} tree for the existence of the file to write.
+% \begin{macrocode}
+\def\filec@ntents@nosearch{%
+ \let\filec@ntents@checkdir\@currdir
+ \def\filec@ntents@where{in current directory}}
+% \end{macrocode}
+% By default we search the whole tree:
+% \begin{macrocode}
+\let\filec@ntents@checkdir\@empty
+\def\filec@ntents@where{exists on the system}
+% \end{macrocode}
+%
+% \begin{macrocode}
\begingroup%
\@tempcnta=1
\loop
@@ -1719,16 +1798,13 @@
% \end{macrocode}
%
% \begin{macrocode}
-\gdef\filecontents{\@tempswatrue\filec@ntents}%
-\gdef\filecontents*{\@tempswafalse\filec@ntents}%
-% \end{macrocode}
-%
-% \begin{macrocode}
\gdef\filec@ntents#1{%
- \openin\@inputcheck#1 %
+ \set@curr@file{\filec@ntents@checkdir#1}%
+ \edef\q@curr@file{\expandafter\quote@name\expandafter{\@curr@file}}%
+ \openin\@inputcheck\q@curr@file \space %
\ifeof\@inputcheck%
\@latex@warning@no@line%
- {Writing file `\@currdir#1'}%
+ {Writing file `\@currdir\@curr@file'}%
% \end{macrocode}
%
% \changes{v1.0y}{1997/10/10}
@@ -1736,20 +1812,61 @@
% \begin{macrocode}
\chardef\reserved@c15 %
\ch@ck7\reserved@c\write%
- \immediate\openout\reserved@c#1\relax%
+ \immediate\openout\reserved@c\q@curr@file\relax%
\else%
% \end{macrocode}
%
% \changes{v1.0y}{1997/10/10}
% {Use \cs{@gobbletwo}}
% \begin{macrocode}
- \closein\@inputcheck%
- \@latex@warning@no@line%
- {File `#1' already exists on the system.\MessageBreak%
+ \if@filesw%
+ \@latex@warning@no@line%
+ {File `\@curr@file' already \filec@ntents@where.\MessageBreak%
Not generating it from this source}%
- \let\write\@gobbletwo%
- \let\closeout\@gobble%
+ \let\write\@gobbletwo%
+ \let\closeout\@gobble%
+ \else%
+% \end{macrocode}
+% If we are overwriting, we try to make sure that the user is not
+% by mistake overwriting the input file (\cs{jobname}). Of course,
+% this only works for input files ending in \texttt{.tex}. If a
+% different extension is used there is no way to see that we are
+% overwriting outselves!
+% \begin{macrocode}
+ \edef\reserved@a{#1}%
+ \edef\reserved@a{\detokenize\expandafter{\reserved@a}}%
+ \edef\reserved@b{\detokenize\expandafter{\jobname}}%
+ \ifx\reserved@a\reserved@b%
+ \@fileswtrue%
+ \else%
+ \edef\reserved@b{\reserved@b\detokenize{.tex}}%
+ \ifx\reserved@a\reserved@b
+ \@fileswtrue%
+ \fi%
+ \fi%
+% \end{macrocode}
+% We allocate a write channel but we open it only if it is
+% (hopefully) safe. If not opened that means we are going to write
+% on the terminal.
+% \begin{macrocode}
+ \chardef\reserved@c15 %
+ \ch@ck7\reserved@c\write%
+ \if@filesw% % Foul ... trying to overwrite \jobname!
+ \@latex@error{Trying to overwrite `\jobname.tex'}{You can't %
+ write to the file you a reading from!\MessageBreak%
+ Data is written to screen instead.}%
+ \else%
+ \@latex@warning@no@line%
+ {Writing or overwriting file `\@currdir\@curr@file'}%
+ \immediate\openout\reserved@c#1\relax%
+ \fi%
+ \fi%
\fi%
+% \end{macrocode}
+% Closing the \cs{@inputcheck} is done here ot avoid having to do
+% this in each branch.
+% \begin{macrocode}
+ \closein\@inputcheck%
\if@tempswa%
% \end{macrocode}
%
@@ -1758,7 +1875,7 @@
% \begin{macrocode}
\immediate\write\reserved@c{%
\@percentchar\@percentchar\space%
- \expandafter\@gobble\string\LaTeX2e file `#1'^^J%
+ \expandafter\@gobble\string\LaTeX2e file `\@curr@file'^^J%
\@percentchar\@percentchar\space generated by the %
`\@currenvir' \expandafter\@gobblefour\string\newenvironment^^J%
\@percentchar\@percentchar\space from source `\jobname' on %
@@ -1805,7 +1922,7 @@
% Text before the |\end|, write it with a warning.
% \begin{macrocode}
\@latex@warning{Writing text `##1' before %
- \string\end{\@currenvir}\MessageBreak as last line of #1}%
+ \string\end{\@currenvir}\MessageBreak as last line of \@curr@file}%
\immediate\write\reserved@c{##1}%
\fi%
\ifx\relax##2\relax%
@@ -1820,6 +1937,7 @@
^^M}%
% \end{macrocode}
%
+%
% \changes{v1.2j}{2018/05/29}{use \cs{csname} not \cs{@undefined}}
% \begin{macrocode}
\catcode`\^^L\active%
@@ -1834,6 +1952,104 @@
\endgroup%
% \end{macrocode}
%
+%
+% \begin{macrocode}
+%</2ekernel|latexrelease>
+%<latexrelease>\EndIncludeInRelease
+%<latexrelease>\IncludeInRelease{0000/00/00}%
+%<latexrelease> {\filec@ntents}{Spaces in file names + optional arg}%
+%<latexrelease>
+%<latexrelease>\let\filec@ntents@opt \@undefined
+%<latexrelease>\let\filec@ntents@force \@undefined
+%<latexrelease>\let\filec@ntents@overwrite \@undefined
+%<latexrelease>\let\filec@ntents@noheader \@undefined
+%<latexrelease>\let\filec@ntents@nosearch \@undefined
+%<latexrelease>\let\filec@ntents@checkdir \@undefined
+%<latexrelease>\let\filec@ntents@where \@undefined
+%<latexrelease>
+%<latexrelease>\begingroup%
+%<latexrelease>\@tempcnta=1
+%<latexrelease>\loop
+%<latexrelease> \catcode\@tempcnta=12 %
+%<latexrelease> \advance\@tempcnta\@ne %
+%<latexrelease>\ifnum\@tempcnta<32 %
+%<latexrelease>\repeat %
+%<latexrelease>\catcode`\*=11 %
+%<latexrelease>\catcode`\^^M\active%
+%<latexrelease>\catcode`\^^L\active\let^^L\relax%
+%<latexrelease>\catcode`\^^I\active%
+%<latexrelease>
+%<latexrelease>\gdef\filec@ntents#1{%
+%<latexrelease> \openin\@inputcheck#1 %
+%<latexrelease> \ifeof\@inputcheck%
+%<latexrelease> \@latex@warning@no@line%
+%<latexrelease> {Writing file `\@currdir#1'}%
+%<latexrelease> \chardef\reserved@c15 %
+%<latexrelease> \ch@ck7\reserved@c\write%
+%<latexrelease> \immediate\openout\reserved@c#1\relax%
+%<latexrelease> \else%
+%<latexrelease> \closein\@inputcheck%
+%<latexrelease> \@latex@warning@no@line%
+%<latexrelease> {File `#1' already exists on the system.\MessageBreak%
+%<latexrelease> Not generating it from this source}%
+%<latexrelease> \let\write\@gobbletwo%
+%<latexrelease> \let\closeout\@gobble%
+%<latexrelease> \fi%
+%<latexrelease> \if@tempswa%
+%<latexrelease> \immediate\write\reserved@c{%
+%<latexrelease> \@percentchar\@percentchar\space%
+%<latexrelease> \expandafter\@gobble\string\LaTeX2e file `#1'^^J%
+%<latexrelease> \@percentchar\@percentchar\space generated by the %
+%<latexrelease> `\@currenvir' \expandafter\@gobblefour\string\newenvironment^^J%
+%<latexrelease> \@percentchar\@percentchar\space from source `\jobname' on %
+%<latexrelease> \number\year/\two@digits\month/\two@digits\day.^^J%
+%<latexrelease> \@percentchar\@percentchar}%
+%<latexrelease> \fi%
+%<latexrelease> \let\do\@makeother\dospecials%
+%<latexrelease> \count@ 128\relax%
+%<latexrelease> \loop%
+%<latexrelease> \catcode\count@ 11\relax%
+%<latexrelease> \advance\count@ \@ne%
+%<latexrelease> \ifnum\count@<\@cclvi%
+%<latexrelease> \repeat%
+%<latexrelease> \edef\E{\@backslashchar end\string{\@currenvir\string}}%
+%<latexrelease> \edef\reserved@b{%
+%<latexrelease> \def\noexpand\reserved@b%
+%<latexrelease> ####1\E####2\E####3\relax}%
+%<latexrelease> \reserved@b{%
+%<latexrelease> \ifx\relax##3\relax%
+%<latexrelease> \immediate\write\reserved@c{##1}%
+%<latexrelease> \else%
+%<latexrelease> \edef^^M{\noexpand\end{\@currenvir}}%
+%<latexrelease> \ifx\relax##1\relax%
+%<latexrelease> \else%
+%<latexrelease> \@latex@warning{Writing text `##1' before %
+%<latexrelease> \string\end{\@currenvir}\MessageBreak as last line of #1}%
+%<latexrelease> \immediate\write\reserved@c{##1}%
+%<latexrelease> \fi%
+%<latexrelease> \ifx\relax##2\relax%
+%<latexrelease> \else%
+%<latexrelease> \@latex@warning{%
+%<latexrelease> Ignoring text `##2' after \string\end{\@currenvir}}%
+%<latexrelease> \fi%
+%<latexrelease> \fi%
+%<latexrelease> ^^M}%
+%<latexrelease>
+%<latexrelease> \catcode`\^^L\active%
+%<latexrelease> \let\L\@undefined%
+%<latexrelease> \def^^L{\expandafter\ifx\csname L\endcsname\relax\fi ^^J^^J}%
+%<latexrelease> \catcode`\^^I\active%
+%<latexrelease> \let\I\@undefined%
+%<latexrelease> \def^^I{\expandafter\ifx\csname I\endcsname\relax\fi\space}%
+%<latexrelease> \catcode`\^^M\active%
+%<latexrelease> \edef^^M##1^^M{%
+%<latexrelease> \noexpand\reserved@b##1\E\E\relax}}%
+%<latexrelease>\endgroup%
+%<latexrelease>\EndIncludeInRelease
+%<*2ekernel>
+% \end{macrocode}
+%
+%
% \begin{macrocode}
\begingroup
\catcode`|=\catcode`\%
@@ -1850,12 +2066,16 @@
\T\I{Tab}{Spac}|
\immediate\write\@unused{}}
\global\let\endfilecontents*\endfilecontents
-\@onlypreamble\filecontents
-\@onlypreamble\endfilecontents
-\@onlypreamble\filecontents*
-\@onlypreamble\endfilecontents*
+% \end{macrocode}
+% We no longer prevent the code to be used after begin document (no
+% rollback needed for this change).
+% \begin{macrocode}
+%\@onlypreamble\filecontents
+%\@onlypreamble\endfilecontents
+%\@onlypreamble\filecontents*
+%\@onlypreamble\endfilecontents*
\endgroup
-\@onlypreamble\filec@ntents
+%\@onlypreamble\filec@ntents
% \end{macrocode}
% \end{macro}
% \end{macro}
@@ -2461,7 +2681,7 @@
%
% Most often the second argument (before-date-code) will be empty.
% \begin{macrocode}
-\long\def\IfTargetDateBefore#1{%
+\DeclareRobustCommand\IfTargetDateBefore[1]{%
\ifnum\pkgcls@innerdate <%
\expandafter\@parse@version\expandafter0#1//00\@nil
\typeout{Exclude code introduced on #1}%