|
665 | 665 | % If the file exists then \cs{CurrentFile} holds its name. But we
|
666 | 666 | % can't rely on that still being true after the file has been
|
667 | 667 | % 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 |
669 | 669 | % \texttt{file/after/...} hook.
|
670 | 670 | %
|
671 | 671 | % The hook always refers to the file requested by the user. The hook
|
|
682 | 682 | % the file name and extension are returned so that file hooks can
|
683 | 683 | % refer to the file by their name only. The path to the file is
|
684 | 684 | % 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. |
685 | 690 | % \begin{macrocode}
|
686 |
| - \edef\reserved@a{\@filef@und |
| 691 | + \edef\reserved@a{% |
687 | 692 | \@expl@@@filehook@file@pop@assign@@nnnn
|
688 | 693 | {\CurrentFilePathUsed}%
|
689 | 694 | {\CurrentFileUsed}%
|
690 | 695 | {\CurrentFilePath}%
|
691 |
| - {\CurrentFile}}% |
| 696 | + {\CurrentFile}% |
| 697 | + \noexpand\@input@file@exists@with@hooks{\@filef@und}}% |
692 | 698 | \expandafter\@swaptwoargs\expandafter
|
693 | 699 | {\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}% |
698 | 707 | % \end{macrocode}
|
699 | 708 | % The current file name is available in \cs{CurrentFile} so we use
|
700 | 709 | % that in the specific hook.
|
701 | 710 | % \begin{macrocode}
|
702 |
| - \UseHook{file/before/\CurrentFile}% |
703 |
| - \@@input |
704 |
| - }% |
| 711 | + \UseHook{file/before/\CurrentFile}% |
| 712 | + \@@input #1% <- trailing space comes from \@filef@und |
705 | 713 | % \end{macrocode}
|
706 | 714 | % And it is restored here so we can use it once more.
|
707 | 715 | % \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} |
713 | 719 | %<latexrelease>\EndIncludeInRelease
|
714 | 720 | %</2ekernel|latexrelease>
|
715 | 721 | % \end{macrocode}
|
|
0 commit comments