Skip to content

Commit fc36d24

Browse files
Pass \@FilEf@und (expanded) to \@addtofilelist
Passing the argument file name would get \@FileList wrong in a file substitution
1 parent cca8084 commit fc36d24

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

base/ltfilehook.dtx

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@
665665
% If the file exists then \cs{CurrentFile} holds its name. But we
666666
% can't rely on that still being true after the file has been
667667
% processed. Thus for using the name in the file hooks we need to
668-
% preserve the name and then restored it for the
668+
% preserve the name and then restore it for the
669669
% \texttt{file/after/...} hook.
670670
%
671671
% The hook always refers to the file requested by the user. The hook
@@ -682,34 +682,40 @@
682682
% the file name and extension are returned so that file hooks can
683683
% refer to the file by their name only. The path to the file is
684684
% returned in \cs{CurrentFilePath}.
685+
%
686+
% We pre-expand \cs{@filef@und} so that in case another file is
687+
% loaded in the true branch of \cs{InputIfFileExists}, these don't
688+
% change their value meanwhile. This isn't a worry with
689+
% \cs[no-index]{CurrentFile...} because they are kept in a stack.
685690
% \begin{macrocode}
686-
\edef\reserved@a{\@filef@und
691+
\edef\reserved@a{%
687692
\@expl@@@filehook@file@pop@assign@@nnnn
688693
{\CurrentFilePathUsed}%
689694
{\CurrentFileUsed}%
690695
{\CurrentFilePath}%
691-
{\CurrentFile}}%
696+
{\CurrentFile}%
697+
\noexpand\@input@file@exists@with@hooks{\@filef@und}}%
692698
\expandafter\@swaptwoargs\expandafter
693699
{\reserved@a}%
694-
{%
695-
#2%
696-
\@addtofilelist{#1}%
697-
\UseHook{file/before}%
700+
{#2}%
701+
\@expl@@@filehook@file@pop@@
702+
}%
703+
}
704+
\def\@input@file@exists@with@hooks#1{%
705+
\@addtofilelist{\unqu@tefilef@und#1\@nil}%
706+
\UseHook{file/before}%
698707
% \end{macrocode}
699708
% The current file name is available in \cs{CurrentFile} so we use
700709
% that in the specific hook.
701710
% \begin{macrocode}
702-
\UseHook{file/before/\CurrentFile}%
703-
\@@input
704-
}%
711+
\UseHook{file/before/\CurrentFile}%
712+
\@@input #1% <- trailing space comes from \@filef@und
705713
% \end{macrocode}
706714
% And it is restored here so we can use it once more.
707715
% \begin{macrocode}
708-
\UseHook{file/after/\CurrentFile}%
709-
\UseHook{file/after}%
710-
\@expl@@@filehook@file@pop@@
711-
}%
712-
}
716+
\UseHook{file/after/\CurrentFile}%
717+
\UseHook{file/after}}
718+
\def\unqu@tefilef@und"#1" \@nil{#1}
713719
%<latexrelease>\EndIncludeInRelease
714720
%</2ekernel|latexrelease>
715721
% \end{macrocode}

base/testfiles/github-0422.tlg

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ Package: test-fixed
3939
(test-fixed) with 'opt'
4040
(test): I should be loaded instead.
4141
)
42-
! LaTeX Error: Option clash for package test-fixed.
42+
! LaTeX Error: Option clash for package test-broken.
4343
See the LaTeX manual or LaTeX Companion for explanation.
4444
Type H <return> for immediate help.
4545
...
4646
l. ...\usepackage[opttwo]{test-broken}\relax
4747
% Option clash
48-
The package test-fixed has already been loaded with options:
48+
The package test-broken has already been loaded with options:
4949
[opt]
5050
There has now been an attempt to load it with options
5151
[opttwo]
@@ -88,18 +88,18 @@ Adding the global options:
8888
to your \documentclass declaration may fix this.
8989
Try typing <return> to proceed.
9090
==================================================
91-
(testpath//inputpath-fixed.sty
91+
(testpath/inputpath-fixed.sty
9292
Package: inputpath-fixed
9393
(inputpath-fixed) with 'opt'
9494
(inputpath): I should be loaded instead.
9595
)
96-
! LaTeX Error: Option clash for package inputpath-fixed.
96+
! LaTeX Error: Option clash for package inputpath-broken.
9797
See the LaTeX manual or LaTeX Companion for explanation.
9898
Type H <return> for immediate help.
9999
...
100100
l. ...\usepackage[opttwo]{inputpath-broken}\relax
101101
% Option clash
102-
The package inputpath-fixed has already been loaded with options:
102+
The package inputpath-broken has already been loaded with options:
103103
[opt]
104104
There has now been an attempt to load it with options
105105
[opttwo]
@@ -131,5 +131,5 @@ Try typing <return> to proceed.
131131
testpath/teststy.sty
132132
test-fixed.sty
133133
testpath/in-fixed.sty
134-
./testpath//inputpath-fixed.sty
134+
./testpath/inputpath-fixed.sty
135135
***********

0 commit comments

Comments
 (0)