From a9726d029d99c128a7abb22e73074ba0a1ce838e Mon Sep 17 00:00:00 2001
From: Norbert Preining <norbert@preining.info>
Date: Tue, 1 Sep 2020 03:03:37 +0000
Subject: CTAN sync 202009010303

---
 macros/latex-dev/base/ltfiles.dtx | 418 ++++++++++++++++++++++++++++----------
 1 file changed, 312 insertions(+), 106 deletions(-)

(limited to 'macros/latex-dev/base/ltfiles.dtx')

diff --git a/macros/latex-dev/base/ltfiles.dtx b/macros/latex-dev/base/ltfiles.dtx
index 60b6a23e5c..a5ad754bfd 100644
--- a/macros/latex-dev/base/ltfiles.dtx
+++ b/macros/latex-dev/base/ltfiles.dtx
@@ -32,7 +32,7 @@
 %<*driver>
 % \fi
 \ProvidesFile{ltfiles.dtx}
-             [2020-06-05 v1.2h LaTeX Kernel (File Handling)]
+             [2020/08/21 v1.2i LaTeX Kernel (File Handling)]
 % \iffalse
 \documentclass{ltxdoc}
 \GetFileInfo{ltfiles.dtx}
@@ -47,6 +47,8 @@
   Chris Rowley\and
   Rainer Sch\"opf}
 
+\providecommand\pkg[1]{\texttt{#1}}
+
 \begin{document}
  \MaintainedByLaTeXTeam{latex}
  \maketitle
@@ -55,6 +57,8 @@
 %</driver>
 % \fi
 %
+% \providecommand\hook[1]{\texttt{#1}}
+%
 %
 % \changes{v1.0h}{1994/05/21}{Use new error commands}
 % \changes{v1.0n}{1994/11/17}
@@ -62,6 +66,7 @@
 % \changes{v1.0u}{1995/07/13}{Updates to docu}
 % \changes{v1.1m}{2015/02/21}
 %         {Removed autoload support}
+% \changes{v1.2i}{2020/08/21}{Integration of new hook management interface}
 %
 % \section{File Handling}
 %
@@ -234,22 +239,28 @@
 % \changes{v0.9e}{1993/12/09}{Hook added}
 %    \begin{macrocode}
 %</2ekernel>
-%<latexrelease>\IncludeInRelease{2020/06/05}%
+%<latexrelease>\IncludeInRelease{2020/10/01}%
 %<latexrelease>  {\document}{Added hook to load l3backend code}%
 %<*2ekernel|latexrelease>
+\def\document{%
 %    \end{macrocode}
-%    Cancel the |\begingroup| from |\begin|.
+%    We do cancel the grouping as part of the \cs{begin} handling
+%    (this is now done inside \cs{begin} instead) so that the
+%    \hook{env/\meta{env}/begin} hook is not hidden inside \cs{begingroup}
+%    \texttt{...} \cs{endgroup}.
 %    \begin{macrocode}
-\def\document{\endgroup
+%  \endgroup
 %    \end{macrocode}
-% \changes{v1.2h}{2020/06/05}{Added hook to load \textsf{l3backend} code}
+%    
 %    \begin{macrocode}
-  \@expl@sys@load@backend@@
+  \UseOneTimeHook{begindocument/before}%
+  \@kernel@after@begindocument@before
 %    \end{macrocode}
-%    If some options on |\documentclass| haven't been used by any
-%    package we will now give a warning since this is most certainly a
-%    misspelling.
+%
+% Added hook to load \textsf{l3backend} code:
+% \changes{v1.2h}{2020/06/05}{Added hook to load \textsf{l3backend} code}
 %    \begin{macrocode}
+  \@expl@sys@load@backend@@
   \ifx\@unusedoptionlist\@empty\else
     \@latex@warning@no@line{Unused global option(s):^^J%
             \@spaces[\@unusedoptionlist]}%
@@ -352,9 +363,11 @@
 % \changes{v1.1e}{1996/04/24}
 %            {(DPC) Reset \cs{AtBeginDocument} eg for latex/1297}
 %    \begin{macrocode}
-  \let\AtBeginDocument\@firstofone
-  \@begindocumenthook
+  \@kernel@before@begindocument
+  \UseOneTimeHook{begindocument}%
+  \@kernel@after@begindocument
 %    \end{macrocode}
+%    
 %    Most of the following assignments will be done globally in case
 %    the user adds something like |\begin{multicols}| to the document
 %    hook, i.e. starts are group in |\begin{document}|.
@@ -403,16 +416,73 @@
 %    \begin{macrocode}
   \global\let\do\noexpand
 %    \end{macrocode}
+%
+%    \begin{macrocode}
+  \UseOneTimeHook{begindocument/end}%
+%    \end{macrocode}
 % \changes{v1.1c}{1995/12/05}{\cs{ignorespaces} added for latex/1933}
-%    Use of |\AtBeginDocument| hook might mean that we are already in
+%    Use of the hook might mean that we are already in
 %    horizontal mode, so ignore the space after |\begin{document}|.
 %    \begin{macrocode}
   \ignorespaces}
+%    \end{macrocode}
+%
+%    The \hook{begindocument} hook already existed in the kernel since
+%    1994 under the name \cs{atbegindocumenthook} the 
+%    additional ones are originally from the \pkg{etoolbox}
+%    package under the names \cs{@endpreamblehook} \cs{afterpreamble}.
+%    \begin{macrocode}
+\NewHook{begindocument}
+\NewHook{begindocument/before}
+\NewHook{begindocument/end}
+%    \end{macrocode}
+
+
+
+%  \begin{macro}{\@kernel@after@begindocument@before,
+%                \@kernel@before@begindocument,
+%                \@kernel@after@begindocument}
+%
+%    Above we used two kernel only hooks to be run after the public
+%    \hook{begindocument/before} and after \hook{begindocument}
+%    hooks.
+%
+%    In \cs{@kernel@after@begindocument@before} we already place one
+%    action: drop the fast execution code for the
+%    \hook{env/document/begin} hook. That hook marks the end of the
+%    preamble and should therefore only be run once. In a normal 
+%    document that is anyway the case (so the code would just sit
+%    there taking up space afterwards, which these days is rather
+%    harmless), however, in more complicated scenarios where several
+%    full documents are combined to a single document it might get
+%    applied several times with harmful effects. We therefore
+%    explicitly drop it at this point. the coing is somewhat obscure
+%    due to the name of the macro which requires constructing.
+%    \begin{macrocode}
+\edef \@kernel@after@begindocument@before {%
+  \let\expandafter\noexpand\csname
+       g__hook_env/document/begin_code_tl\endcsname
+  \noexpand\@empty}
+%    \end{macrocode}
+%
+%    \begin{macrocode}
+\let \@kernel@before@begindocument \@empty
+\let \@kernel@after@begindocument \@empty
+%    \end{macrocode}
+%    
+%  \end{macro}
+%
+
+%
+%    \begin{macrocode}
 %</2ekernel|latexrelease>
 %<latexrelease>\EndIncludeInRelease
-%<latexrelease>
+%    \end{macrocode}
+%    
+%    \begin{macrocode}
 %<latexrelease>\IncludeInRelease{2017/04/15}%
 %<latexrelease>  {\document}{Save language for hyphenation}%
+%<latexrelease>
 %<latexrelease>\def\document{\endgroup
 %<latexrelease>  \ifx\@unusedoptionlist\@empty\else
 %<latexrelease>    \@latex@warning@no@line{Unused global option(s):^^J%
@@ -601,43 +671,14 @@
 %    \end{macrocode}
 %
 %
-% \begin{macro}{\includeonly}
+%  \begin{macro}{\include,\includeonly}
+% \changes{v0.9p}{1994/01/18}
+%         {Use \cs{@input@} so include files are listed.}
 % \changes{v1.0p}{1995/04/22}{Allow blanks in argument}
 % \changes{v1.2a}{2019/07/01}{Support UTF-8}
 % \changes{v1.2g}{2020/05/02}{Improved support for spaces in filenames
 %    (gh/217)}
-%    \begin{macrocode}
-%</2ekernel>
-%<*2ekernel|latexrelease>
-%<latexrelease>\IncludeInRelease{2020/10/01}%
-%<latexrelease>                 {\includeonly}{Spaces in file names}%
-\def\includeonly#1{%
-  \@partswtrue
-%    \end{macrocode}
-%    Because the argument to |\includeonly| is a comma-separated list
-%    of filenames where there may be comma's precedeing some of the
-%    filenames or trailing them. Therefore we need to take the list
-%    apart, remove the unwanted spaces while leaving the spaces
-%    \emph{in} the filenames intact.
-%    \begin{macrocode}
-  \let\@partlist\@empty
-  \@for\reserved@a:=#1 \do
-    {
-      \expandafter\set@curr@file@trim@spaces\expandafter{\reserved@a}%
-      \ifx\@partlist\@empty
-        \edef\@partlist{\@curr@file}%
-      \else
-        \edef\@partlist{\@partlist,\@curr@file}%
-      \fi
-    }%
-  }
-\@onlypreamble\includeonly
-%    \end{macrocode}
-% \end{macro}
 %
-% \begin{macro}{\include}
-% \changes{v0.9p}{1994/01/18}
-%         {Use \cs{@input@} so include files are listed.}
 % In the definition of |\include|, |\def\reserved@b| changed to
 % |\edef\reserved@b| to be consistent with the |\edef| in
 % |\includeonly|.
@@ -655,12 +696,26 @@
 %    from the filename (gh/217)}
 % \changes{v1.2g}{2020-05-02}{Pass the filename to \cs{@include} by
 %    value instead of by reference (gh/217)} 
+%
+%    \begin{macrocode}
+%</2ekernel>
+%<*2ekernel|latexrelease>
+%<latexrelease>\IncludeInRelease{2020/10/01}%
+%<latexrelease>                 {\includeonly}{Spaces in file names}%
+%    \end{macrocode}
+%    
 %    \begin{macrocode}
 \def\include#1{\relax
   \ifnum\@auxout=\@partaux
     \@latex@error{\string\include\space cannot be nested}\@eha
   \else
-    \set@curr@file@trim@spaces{#1}%
+%    \end{macrocode}
+%    Here the normalisation will add |.tex| for all files, (it uses the
+%    the same normalisation as the hooks), so we need to remove that
+%    manually.  \cs{@strip@tex@ext} does that.
+%    \begin{macrocode}
+    \set@curr@file{#1}%
+    \edef\@curr@file{\@strip@tex@ext\@curr@file}%
 %    \end{macrocode}
 %    For historical reasons \cs{@include} expects an argument
 %    delimited by a space. This is kept (though uncessary now) to avoid
@@ -669,27 +724,56 @@
     \expandafter\@include\expandafter{\@curr@file} % deliberate space
   \fi}
 %    \end{macrocode}
-% \end{macro}
-%
-%
-%
-%  \begin{macro}{\set@curr@file@trim@spaces}
 %
-%    For |\include| and |\includeonly| we need a variant that removes
-%    any leading and trailing spaces from the filename, while leaving
-%    any spaces \emph{inside} the filename intact. In order simplify
-%    the implementaion we borrow some code from the \texttt{expl3}
-%    language, \textbf{\emph{beware}: this may change unannounced}.
+%    Here in \cs{includeonly} we also need to strip |.tex| after
+%    normalisation:
 %    \begin{macrocode}
-\def\set@curr@file@trim@spaces#1{%
-  \@expl@tl@trim@spaces@apply@@nN {#1} \set@curr@file }
+\def\includeonly#1{%
+  \@partswtrue
 %    \end{macrocode}
-%  \end{macro}
-%
+%    Because the argument to |\includeonly| is a comma-separated list
+%    of filenames where there may be comma's precedeing some of the
+%    filenames or trailing them. Therefore we need to take the list
+%    apart, remove the unwanted spaces while leaving the spaces
+%    \emph{in} the filenames intact.
+%    \begin{macrocode}
+  \let\@partlist\@empty
+  \@for\reserved@a:=#1 \do
+    {%
+      \expandafter\set@curr@file\expandafter{\reserved@a}%
+      \ifx\@partlist\@empty
+        \edef\@partlist{\@strip@tex@ext\@curr@file}%
+      \else
+        \edef\@partlist{\@partlist,\@strip@tex@ext\@curr@file}%
+      \fi
+    }%
+  }
+\@onlypreamble\includeonly
+%    \end{macrocode}
+% \end{macro}
 %
+%  \begin{macro}{\@strip@tex@ext,\@strip@tex@ext@aux}
+%    These macros take a (\cs{detokenize}d file name and remove any
+%    |.tex| extension).  Extra care is taken to not remove the string
+%    |.tex| from the middle of a file name:  it is only removed if it's
+%    the very last thing in the file name.
+%    \begin{macrocode}
+\def\reserved@a#1{%
+\def\@strip@tex@ext##1{%
+  \expandafter\@strip@tex@ext@aux
+    ##1\@nil\@nil
+     #1\@nil\relax\@nnil}
+\def\@strip@tex@ext@aux##1#1\@nil##2\@nnil{%
+  \ifx\relax##2\@empty
+    \expandafter\@cdr\expandafter\@empty\@cdr{}##1%
+  \else##1\fi}}%
+\expandafter\reserved@a
+\expandafter{\detokenize{.tex}}
+%</2ekernel|latexrelease>
+%    \end{macrocode}
+%  \end{macro}
 %
 %    \begin{macrocode}
-%</2ekernel|latexrelease>
 %<latexrelease>\EndIncludeInRelease
 %<latexrelease>\IncludeInRelease{2019/10/01}%
 %<latexrelease>                 {\includeonly}{Spaces in file names}%
@@ -708,7 +792,9 @@
 %<latexrelease>    \expandafter\@include\@curr@file
 %<latexrelease>  \fi}
 %<latexrelease>
-%<latexrelease>\let\set@curr@file@trim@spaces\@undefined
+%<latexrelease>\let\@strip@tex@ext\@undefined
+%<latexrelease>\let\@strip@tex@ext@aux\@undefined
+%<latexrelease>
 %<latexrelease>\EndIncludeInRelease
 %    \end{macrocode}
 %    
@@ -727,7 +813,6 @@
 %<latexrelease>\EndIncludeInRelease
 %<*2ekernel>
 %    \end{macrocode}
-
 %
 % \begin{macro}{\@include}
 % \changes{v1.2g}{2020/05/02}{Support spaces in filenames by enclosing
@@ -736,7 +821,7 @@
 %</2ekernel>
 %<*2ekernel|latexrelease>
 %<latexrelease>\IncludeInRelease{2020/10/01}%
-%<latexrelease>                 {\@include}{Spaces in file names}%
+%<latexrelease>                 {\@include}{Spaces in file names and hooks}%
 %    \end{macrocode}
 %    
 %    \begin{macrocode}
@@ -758,8 +843,38 @@
       \immediate\openout\@partaux "#1.aux"
       \immediate\write\@partaux{\relax}%
     \fi
+%    \end{macrocode}
+%    Now before going to the hooks we need to set \cs{CurrentFile}:
+%    \begin{macrocode}
+%-----------------------------------------
+    \@filehook@set@CurrentFile
+%    \end{macrocode}
+%    Execute the \texttt{before} hooks just after we switched the
+%    \texttt{.aux} file \ldots
+%    \begin{macrocode}
+    \UseHook{include/before}%
+    \UseHook{include/before/#1}%
+%-----------------------------------------
     \@input@{#1.tex}%
+%-----------------------------------------
+%    \end{macrocode}
+%    \ldots{} then \texttt{end} hooks \ldots
+%    \begin{macrocode}
+    \UseHook{include/end/#1}%
+    \UseHook{include/end}%
+%-----------------------------------------
     \clearpage
+%-----------------------------------------
+%    \end{macrocode}
+%    \ldots{} and after the \cs{clearpage} the \texttt{after} hooks
+%    followed by another \cs{clearpage} just in case new material got
+%    added (after all we need to be in  well defined state after the
+%    \cs{include}).
+%    \begin{macrocode}
+    \UseHook{include/after/#1}%
+    \UseHook{include/after}%
+    \clearpage
+%-----------------------------------------
     \@writeckpt{#1}%
     \if@filesw
       \immediate\closeout\@partaux
@@ -776,7 +891,10 @@
   \fi
   \let\@auxout\@mainaux}
 %<latexrelease>\EndIncludeInRelease
-%<latexrelease>
+%</2ekernel|latexrelease>
+%    \end{macrocode}
+%
+%    \begin{macrocode}
 %<latexrelease>\IncludeInRelease{0000/00/00}%
 %<latexrelease>                 {\@include}{Spaces in file names}%
 %<latexrelease>\def\@include#1 {%
@@ -859,7 +977,6 @@
 %
 %
 %
-
 %  \begin{macro}{\@curr@file}
 %  \begin{macro}{\set@curr@file}
 %
@@ -887,11 +1004,11 @@
 %  \changes{v1.2c}{2019/10/11}{Remove one brace group}
 %  \changes{v1.2d}{2019/10/26}{remove quotes}
 %  \changes{v1.2e}{2019/11/09}{expand and \cs{string} before removing quotes}
+%
+%    The definition below is from 2019 and only used during kernel
+%    bootstrapping, later on in \texttt{ltfilehook.dtx} it will get
+%    overwritten.
 %    \begin{macrocode}
-%</2ekernel>
-%<*2ekernel|latexrelease>
-%<latexrelease>\IncludeInRelease{2019/10/01}%
-%<latexrelease>                 {\set@curr@file}{Quote file names}%
 \def\set@curr@file#1{%
   \begingroup
     \escapechar\m@ne
@@ -918,6 +1035,10 @@
 %           -> ""
 %\end{verbatim}
 %    \begin{macrocode}
+%</2ekernel>
+%<*2ekernel|latexrelease>
+%<latexrelease>\IncludeInRelease{2019/10/01}%
+%<latexrelease>                 {\quote@name}{Quote file names}%
 \def\quote@name#1{"\quote@@name#1\@gobble""}
 \def\quote@@name#1"{#1\quote@@name}
 %    \end{macrocode}
@@ -999,12 +1120,11 @@
 %</2ekernel|latexrelease>
 %<latexrelease>\EndIncludeInRelease
 %<latexrelease>\IncludeInRelease{0000/00/00}%
-%<latexrelease>                 {\set@curr@file}{Quote file names}%
+%<latexrelease>                 {\quote@name}{Quote file names}%
 %<latexrelease>
 %<latexrelease>\let\quote@name\@undefined
 %<latexrelease>\let\quote@@name\@undefined
 %<latexrelease>\let\unquote@name\@undefined
-%<latexrelease>\let\set@curr@file\@undefined
 %<latexrelease>
 %<latexrelease>\let\IfFileExists@\@undefined
 %<latexrelease>
@@ -1044,25 +1164,14 @@
 %
 %
 % \begin{macro}{\InputIfFileExists}
-% \changes{v0.9b}
-%         {1993/12/04}{Macro added}
-% \changes{v0.9p}
-%         {1994/01/18}{New Definition}
-% \changes{v0.3b}{1994/03/13}
-%         {Use new cmd \cs{@addtofilelist}}
-% Now define |\InputIfFileExists| to input |#1| if it seems to exist.
-% Immediately prior to the input, |#2| is executed.
-% If the file |#1| does not exist, execute `|#3|'.
-% \changes{v1.0t}{1995/05/25}
-%         {(CAR) added \cs{long}}
-% \changes{v1.1o}{2019/02/07}{Expand \cs{@filef@und} before executing
-%   second argument (github/109)}
-% \changes{v1.2b}{2019/08/27}{Make command robust}
-%    \begin{macrocode}
-%</2ekernel>
-%<latexrelease>\IncludeInRelease{2019/10/01}%
-%<latexrelease>  {\InputIfFileExists}{Don't lose the file name}%
-%<*2ekernel|latexrelease>
+%
+%    Now define |\InputIfFileExists| to input |#1| if it seems to exist.
+%    Immediately prior to the input, |#2| is executed.
+%    If the file |#1| does not exist, execute `|#3|'.
+%
+%    This here is a temporary definition for the kernel. The real one
+%    comes somewhat later in the file \texttt{ltfilehook.dtx}.
+%
 %    \begin{macrocode}
 \DeclareRobustCommand \InputIfFileExists[2]{%
   \IfFileExists{#1}%
@@ -1079,25 +1188,23 @@
 %    Swap two arguments and return them unbraced (like
 %   \cs{@firstoftwo} etc).
 %    \begin{macrocode}
+%</2ekernel>
+%<*2ekernel|latexrelease>
+%<latexrelease>\IncludeInRelease{2019/10/01}%
+%<latexrelease>  {\@swaptwoargs}{Don't lose the file name}%
 \long\def\@swaptwoargs#1#2{#2#1}
 %    \end{macrocode}
-%  \end{macro}
-%
 %
 %    \begin{macrocode}
 %</2ekernel|latexrelease>
 %<latexrelease>\EndIncludeInRelease
 %<latexrelease>\IncludeInRelease{0000/00/00}%
-%<latexrelease>  {\InputIfFileExists}{Don't lose the file name}%
-%<latexrelease>\long\def \InputIfFileExists#1#2{%
-%<latexrelease>  \IfFileExists{#1}%
-%<latexrelease>    {#2\@addtofilelist{#1}\@@input \@filef@und}}
-%<latexrelease>
+%<latexrelease>  {\@swaptwoargs}{Don't lose the file name}%
 %<latexrelease>\let\@swaptwoargs\@undefined
 %<latexrelease>\EndIncludeInRelease
 %<*2ekernel>
 %    \end{macrocode}
-%
+%  \end{macro}
 %
 %
 %  \begin{macro}{\input}
@@ -1114,20 +1221,51 @@
 %    Define |\@iinput| (i.e., |\input|) in terms of
 %    |\InputIfIfileExists|.
 % \changes{v0.9b}{1993/12/04}{Macro reimplemented}
+%
+%   Changes to \cs{@iinput}: adapt to the changes to
+%   \cs{@missingfileerror}.
 %    \begin{macrocode}
 %</2ekernel>
 %<*2ekernel|latexrelease>
-%<latexrelease>\IncludeInRelease{2019/10/01}%
-%<latexrelease>                 {\@iinput}{Quote file names}%
+%<latexrelease>\IncludeInRelease{2020/10/01}%
+%<latexrelease>                 {\@iinput}{Change in file error handling}%
 \def\@iinput#1{%
   \InputIfFileExists{#1}{}%
   {\filename@parse\@curr@file
    \edef\reserved@a{\noexpand\@missingfileerror
      {\filename@area\filename@base}%
      {\ifx\filename@ext\relax tex\else\filename@ext\fi}}%
+%    \end{macrocode}
+%   This line now just sets \cs[no-index]{@missingfile@\meta{part}}:
+%    \begin{macrocode}
+   \reserved@a
+%    \end{macrocode}
+%   Now here we have to use it.  The file here is guaranteed to exist,
+%   because \cs{@missingfileerror} ensures so, but we have to use
+%   \cs{InputIfFileExists} because it executes the file hooks.
+%    \begin{macrocode}
+   \edef\reserved@a{\noexpand\@iinput{%
+     \@missingfile@area\@missingfile@base.\@missingfile@ext}}%
    \reserved@a}}
 %</2ekernel|latexrelease>
 %<latexrelease>\EndIncludeInRelease
+%    \end{macrocode}
+%    
+%    \begin{macrocode}
+%<latexrelease>\IncludeInRelease{2019/10/01}%
+%<latexrelease>                 {\@iinput}{Quote file names}%
+%<latexrelease>
+%<latexrelease>\def\@iinput#1{%
+%<latexrelease>  \InputIfFileExists{#1}{}%
+%<latexrelease>  {\filename@parse\@curr@file
+%<latexrelease>   \edef\reserved@a{\noexpand\@missingfileerror
+%<latexrelease>     {\filename@area\filename@base}%
+%<latexrelease>     {\ifx\filename@ext\relax tex\else\filename@ext\fi}}%
+%<latexrelease>   \reserved@a}}
+%<latexrelease>\EndIncludeInRelease
+%    \end{macrocode}
+%
+%    \begin{macrocode}
 %<latexrelease>\IncludeInRelease{0000/00/00}%
 %<latexrelease>                 {\@iinput}{Quote file names}%
 %<latexrelease>\def\@iinput#1{%
@@ -1172,6 +1310,11 @@
 %    \end{macrocode}
 %  \end{macro}
 %
+%
+%
+%
+%
+%
 % \begin{macro}{\@missingfileerror}
 % This `error' command avoids \TeX's primitive missing file loop.
 %
@@ -1189,7 +1332,16 @@
 %         {Move here from ltclass}
 % \changes{v1.0w}{1995/10/06}
 %         {Autoload error}
+%
+%   Changes to \cs{@missingfileerror}:  rather than trying to input the
+%   file by force, now \cs{@missingfileerror} just returns three
+%   \cs[no-index]{@missingfile@\meta{part}} and the caller macro is
+%   responsible for doing the right thing with it.
 %    \begin{macrocode}
+%</2ekernel>
+%<*2ekernel|latexrelease>
+%<latexrelease>\IncludeInRelease{2020/10/01}%
+%<latexrelease>        {\@missingfileerror}{Do not load missing file immediately}%
 \gdef\@missingfileerror#1#2{%
      \typeout{^^J! LaTeX Error: File `#1.#2' not found.^^J^^J%
       Type X to quit or <RETURN> to proceed,^^J%
@@ -1198,20 +1350,74 @@
       {\endlinechar\m@ne
        \global\read\m@ne to\@gtempa}%
     \ifx\@gtempa\@empty
+%    \end{macrocode}
+%   If the user answers with \meta{return}, fallback to the |.tex| file
+%   (previously it did nothing).
+%    \begin{macrocode}
+      \let\@missingfile@area\@empty
+      \let\@missingfile@base\@empty
+      \def\@missingfile@ext{tex}%
     \else
-      \def\reserved@a{x}\ifx\reserved@a\@gtempa\batchmode\@@end\fi
-      \def\reserved@a{X}\ifx\reserved@a\@gtempa\batchmode\@@end\fi
+%    \end{macrocode}
+%   Use \cs{batchmode}\cs{read}|-1 to |\meta{tl} to end the \TeX{} run,
+%   same as \pkg{expl3} does (it was \cs{batchmode}\cs{@@end} before).
+%    \begin{macrocode}
+      \def\reserved@b{\batchmode\read-1 to \reserved@a}%
+      \def\reserved@a{x}\ifx\reserved@a\@gtempa\reserved@b\fi
+      \def\reserved@a{X}\ifx\reserved@a\@gtempa\reserved@b\fi
       \filename@parse\@gtempa
       \edef\filename@ext{%
         \ifx\filename@ext\relax#2\else\filename@ext\fi}%
      \edef\reserved@a{%
-       \noexpand\InputIfFileExists
+%    \end{macrocode}
+%   Only check \cs{IfFileExists} (it was \cs{InputIfFileExists}).
+%    \begin{macrocode}
+       \noexpand\IfFileExists
          {\filename@area\filename@base.\filename@ext}%
-         {}%
+%    \end{macrocode}
+%   If the file exists, define \cs[no-index]{@missingfile@\meta{part}}.
+%    \begin{macrocode}
+         {\def\noexpand\@missingfile@area{\filename@area}%
+          \def\noexpand\@missingfile@base{\filename@base}%
+          \def\noexpand\@missingfile@ext {\filename@ext}}%
          {\noexpand\@missingfileerror
             {\filename@area\filename@base}{\filename@ext}}}%
       \reserved@a
-    \fi}
+    \fi
+}
+%</2ekernel|latexrelease>
+%<latexrelease>\EndIncludeInRelease
+%    \end{macrocode}
+%    
+%    \begin{macrocode}
+%<latexrelease>\IncludeInRelease{0000/00/00}%
+%<latexrelease>        {\@missingfileerror}{Do not load missing file immediately}%
+%<latexrelease>
+%<latexrelease>\gdef\@missingfileerror#1#2{%
+%<latexrelease>     \typeout{^^J! LaTeX Error: File `#1.#2' not found.^^J^^J%
+%<latexrelease>      Type X to quit or <RETURN> to proceed,^^J%
+%<latexrelease>      or enter new name. (Default extension: #2)^^J}%
+%<latexrelease>     \message{Enter file name: }%
+%<latexrelease>      {\endlinechar\m@ne
+%<latexrelease>       \global\read\m@ne to\@gtempa}%
+%<latexrelease>    \ifx\@gtempa\@empty
+%<latexrelease>    \else
+%<latexrelease>      \def\reserved@a{x}\ifx\reserved@a\@gtempa\batchmode\@@end\fi
+%<latexrelease>      \def\reserved@a{X}\ifx\reserved@a\@gtempa\batchmode\@@end\fi
+%<latexrelease>      \filename@parse\@gtempa
+%<latexrelease>      \edef\filename@ext{%
+%<latexrelease>        \ifx\filename@ext\relax#2\else\filename@ext\fi}%
+%<latexrelease>     \edef\reserved@a{%
+%<latexrelease>       \noexpand\InputIfFileExists
+%<latexrelease>         {\filename@area\filename@base.\filename@ext}%
+%<latexrelease>         {}%
+%<latexrelease>         {\noexpand\@missingfileerror
+%<latexrelease>            {\filename@area\filename@base}{\filename@ext}}}%
+%<latexrelease>      \reserved@a
+%<latexrelease>    \fi}
+%<latexrelease>
+%<latexrelease>\EndIncludeInRelease
+%<*2ekernel>
 %    \end{macrocode}
 % \end{macro}
 %
-- 
cgit v1.2.3

