[latex3-commits] [git/LaTeX3-latex3-latex2e] hotfix/gh464: Correctly restore \CurrentFile after the file ends (dac80c95)
PhelypeOleinik
phelype.oleinik at latex-project.org
Mon Jan 4 06:11:10 CET 2021
Repository : https://github.com/latex3/latex2e
On branch : hotfix/gh464
Link : https://github.com/latex3/latex2e/commit/dac80c953bfc7adffa311c3c3a98b7f243572a0d
>---------------------------------------------------------------
commit dac80c953bfc7adffa311c3c3a98b7f243572a0d
Author: PhelypeOleinik <phelype.oleinik at latex-project.org>
Date: Mon Jan 4 01:51:12 2021 -0300
Correctly restore \CurrentFile after the file ends
Fixes #464
>---------------------------------------------------------------
dac80c953bfc7adffa311c3c3a98b7f243572a0d
base/ltfilehook.dtx | 71 +++++++++++++++++++++++++++--------------------------
1 file changed, 36 insertions(+), 35 deletions(-)
diff --git a/base/ltfilehook.dtx b/base/ltfilehook.dtx
index c7ed13f0..bd690fcd 100644
--- a/base/ltfilehook.dtx
+++ b/base/ltfilehook.dtx
@@ -514,7 +514,6 @@
% \begin{macro}{
% \@@_file_parse_full_name:nN,
% \@@_full_name:nn,
-% \@@_set_curr_file_assign:nnnNN
% }
% A utility macro to trigger \pkg{expl3}'s file-parsing and lookup,
% and return a normalized representation of the file name. If the
@@ -717,8 +716,27 @@
\DeclareRobustCommand \InputIfFileExists[2]{%
\IfFileExists{#1}%
{%
- \@expl@@@filehook at file@push@@
- \@filehook at set@CurrentFile
+ \@expl@@@filehook at file@push@@
+ \@filehook at set@CurrentFile
+% \end{macrocode}
+% We pre-expand \cs{@filef at und} so that in case another file is
+% loaded in the true branch of \cs{InputIfFileExists}, these don't
+% change their value meanwhile. This isn't a worry with
+% \cs[no-index]{CurrentFile...} because they are kept in a stack.
+%
+% \changes{v1.0d}{2020/11/20}
+% {Move loading to \cs{@input at file@exists at with@hooks} and expand
+% \cs{@filef at und} to avoid getting the wrong file name in the case of
+% a substitution.}
+% \begin{macrocode}
+ \expandafter\@swaptwoargs\expandafter
+ {\expandafter\@input at file@exists at with@hooks
+ \expandafter{\@filef at und}}%
+ {#2}%
+ \@expl@@@filehook at file@pop@@
+ }%
+}
+\def\@input at file@exists at with@hooks#1{%
% \end{macrocode}
% If the file exists then \cs{CurrentFile} holds its name. But we
% can't rely on that still being true after the file has been
@@ -741,31 +759,13 @@
% refer to the file by their name only. The path to the file is
% returned in \cs{CurrentFilePath}.
% \begin{macrocode}
- \edef\reserved at a{%
- \@expl@@@filehook at file@pop at assign@@nnnn
- {\CurrentFilePathUsed}%
- {\CurrentFileUsed}%
- {\CurrentFilePath}%
- {\CurrentFile}%
-% \end{macrocode}
-%
-% We pre-expand \cs{@filef at und} so that in case another file is
-% loaded in the true branch of \cs{InputIfFileExists}, these don't
-% change their value meanwhile. This isn't a worry with
-% \cs[no-index]{CurrentFile...} because they are kept in a stack.
-%
-% \changes{v1.0d}{2020/11/20}
-% {Move loading to \cs{@input at file@exists at with@hooks} and expand
-% \cs{@filef at und} to avoid getting the wrong file name in the case of
-% a substitution.}
-% \begin{macrocode}
- \noexpand\@input at file@exists at with@hooks{\@filef at und}}%
- \expandafter\@swaptwoargs\expandafter
- {\reserved at a}%
- {#2}%
- \@expl@@@filehook at file@pop@@
- }%
-}
+ \edef\reserved at a{%
+ \@expl@@@filehook at file@pop at assign@@nnnn
+ {\CurrentFilePathUsed}%
+ {\CurrentFileUsed}%
+ {\CurrentFilePath}%
+ {\CurrentFile}}%
+ \expandafter\@swaptwoargs\expandafter{\reserved at a}%
% \end{macrocode}
%
% Before adding to the file list we need to make all (letter) characters
@@ -787,18 +787,19 @@
% approach (grepping the packages in \TeX{} Live didn't bring up any
% obvious candidate for breaking with this catcode change).
% \begin{macrocode}
-\def\@input at file@exists at with@hooks#1{%
- \edef\reserved at a{\unqu at tefilef@und#1\@nil}%
- \@addtofilelist{\string at makeletter\reserved at a}%
- \UseHook{file/before}%
+ {\edef\reserved at a{\unqu at tefilef@und#1\@nil}%
+ \@addtofilelist{\string at makeletter\reserved at a}%
+ \UseHook{file/before}%
% \end{macrocode}
% The current file name is available in \cs{CurrentFile} so we use
% that in the specific hook.
% \begin{macrocode}
- \UseHook{file/before/\CurrentFile}%
- \@@input #1% <- trailing space comes from \@filef at und
+ \UseHook{file/before/\CurrentFile}%
+ \@@input #1% <- trailing space comes from \@filef at und
+ }%
% \end{macrocode}
-% And it is restored here so we can use it once more.
+% And here, \cs{CurrentFile} is restored
+% (by \cs{@expl@@@filehook at file@pop at assign@@nnnn}) so we can use it once more.
% \begin{macrocode}
\UseHook{file/after/\CurrentFile}%
\UseHook{file/after}}
More information about the latex3-commits
mailing list.