Skip to content

Commit

Permalink
Merge branch 'hotfix/gh464'
Browse files Browse the repository at this point in the history
# Conflicts:
#	base/changes.txt
  • Loading branch information
FrankMittelbach committed Jan 7, 2021
2 parents ac4e176 + bbf9e8a commit 3ee45f0
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 43 deletions.
16 changes: 13 additions & 3 deletions base/changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ are not part of the distribution.
All changes above are only part of the development branch for the next release.
================================================================================


#########################
# 2020-10-01 PL 4 Release
#########################

2021-01-07 Phelype Oleinik <[email protected]>

* ltfilehook.dtx:
Expand All @@ -18,15 +23,20 @@ All changes above are only part of the development branch for the next release.
* lthooks.dtx:
Modified internal copies of l3tl commands to avoid errors with l3debug (gh/463).

#########################
# 2020-10-01 PL 4 Release
#########################
2020-12-18 Phelype Oleinik <[email protected]>

* lthooks.dtx:
Preserve trailing slash in file hook name if the file name is empty (gh/464).

* ltfilehook.dtx:
Restore \CurrentFile(Path)(Used) after the file is input (gh/464).

2020-12-03 Joseph Wright <[email protected]>

* usrguide3.tex
New file to cover creation of document commands


#########################
# 2020-10-01 PL 3 Release
#########################
Expand Down
75 changes: 39 additions & 36 deletions base/ltfilehook.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -711,14 +710,33 @@
%<latexrelease> {\InputIfFileExists}{Hook management (files)}%
%<*2ekernel|latexrelease>
% \end{macrocode}
%
%
% \begin{macrocode}
\let\InputIfFileExists\@undefined
\DeclareRobustCommand \InputIfFileExists[2]{%
\IfFileExists{#1}%
{%
\@expl@@@filehook@file@push@@
\@filehook@set@CurrentFile
\@expl@@@filehook@file@push@@
\@filehook@set@CurrentFile
% \end{macrocode}
% We pre-expand \cs{@filef@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@file@exists@with@hooks} and expand
% \cs{@filef@und} to avoid getting the wrong file name in the case of
% a substitution.}
% \begin{macrocode}
\expandafter\@swaptwoargs\expandafter
{\expandafter\@input@file@exists@with@hooks
\expandafter{\@filef@und}}%
{#2}%
\@expl@@@filehook@file@pop@@
}%
}
\def\@input@file@exists@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
Expand All @@ -740,32 +758,16 @@
% the file name and extension are returned so that file hooks can
% refer to the file by their name only. The path to the file is
% returned in \cs{CurrentFilePath}.
% \changes{v1.0e}{2021/01/07}{Restore \cs[no-index]{CurrentFile(Path)(Used)}
% after the input (gh/464)}
% \begin{macrocode}
\edef\reserved@a{%
\@expl@@@filehook@file@pop@assign@@nnnn
{\CurrentFilePathUsed}%
{\CurrentFileUsed}%
{\CurrentFilePath}%
{\CurrentFile}%
% \end{macrocode}
%
% We pre-expand \cs{@filef@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@file@exists@with@hooks} and expand
% \cs{@filef@und} to avoid getting the wrong file name in the case of
% a substitution.}
% \begin{macrocode}
\noexpand\@input@file@exists@with@hooks{\@filef@und}}%
\expandafter\@swaptwoargs\expandafter
{\reserved@a}%
{#2}%
\@expl@@@filehook@file@pop@@
}%
}
\edef\reserved@a{%
\@expl@@@filehook@file@pop@assign@@nnnn
{\CurrentFilePathUsed}%
{\CurrentFileUsed}%
{\CurrentFilePath}%
{\CurrentFile}}%
\expandafter\@swaptwoargs\expandafter{\reserved@a}%
% \end{macrocode}
%
% Before adding to the file list we need to make all (letter) characters
Expand All @@ -787,18 +789,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@file@exists@with@hooks#1{%
\edef\reserved@a{\unqu@tefilef@und#1\@nil}%
\@addtofilelist{\string@makeletter\reserved@a}%
\UseHook{file/before}%
{\edef\reserved@a{\unqu@tefilef@und#1\@nil}%
\@addtofilelist{\string@makeletter\reserved@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@und
\UseHook{file/before/\CurrentFile}%
\@@input #1% <- trailing space comes from \@filef@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@file@pop@assign@@nnnn}) so we can use it once more.
% \begin{macrocode}
\UseHook{file/after/\CurrentFile}%
\UseHook{file/after}}
Expand Down
17 changes: 13 additions & 4 deletions base/lthooks.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -2572,11 +2572,20 @@
{ \@@_strip_double_slash:n {#1} }
\cs_new:Npn \@@_strip_double_slash:n #1
{ \@@_strip_double_slash:w #1 // \s_@@_mark }
\cs_new:Npn \@@_strip_double_slash:w #1 // #2 \s_@@_mark
% \end{macrocode}
% This function is always called after testing if the argument is a
% file hook with \cs{@@_if_file_hook:wTF}, so we can assume it has
% three parts (it is either \verb|file/before/...| or
% \verb|file/after/...|), so we use \verb|#1/#2/#3 //| instead of just
% \verb|#1 //| to prevent losing a slash if the file name is empty.
% \changes{v1.0h}{2021/01/07}{Assume hook name has at least three
% nonempty parts (gh/464)}
% \begin{macrocode}
\cs_new:Npn \@@_strip_double_slash:w #1/#2/#3 // #4 \s_@@_mark
{
\tl_if_empty:nTF {#2}
{#1}
{ \@@_strip_double_slash:w #1 / #2 \s_@@_mark }
\tl_if_empty:nTF {#4}
{ #1/#2/#3 }
{ \@@_strip_double_slash:w #1/#2/#3 / #4 \s_@@_mark }
}
% \end{macrocode}
% \end{macro}
Expand Down
18 changes: 18 additions & 0 deletions base/testfiles-lthooks/github-0464.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
\RequirePackage[enable-debug]{expl3}
\ExplSyntaxOn
\debug_on:n { check-declarations , deprecation }
\ExplSyntaxOff

\begin{filecontents}{testA.tex}
\egroup\bgroup
\end{filecontents}

\input{regression-test}

\documentclass{article}
\AddToHook{file/after}{\typeout{After "\CurrentFile"}}
\START
\bgroup
\input{testA}
\egroup
\END
4 changes: 4 additions & 0 deletions base/testfiles-lthooks/github-0464.tlg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
(testA.tex)
After "testA.tex"

0 comments on commit 3ee45f0

Please sign in to comment.