Skip to content

Commit

Permalink
add warning to \include for issue #645
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcarlisle committed Oct 14, 2021
1 parent 23b9664 commit 741c371
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
5 changes: 5 additions & 0 deletions base/changes.txt
Expand Up @@ -6,6 +6,11 @@ completeness or accuracy and it contains some references to files that
are not part of the distribution.
================================================================================

2021-10-14 David Carlisle <David.Carlisle@latex-project.org>

* ltfiles.dtx: Warn if \include is used before \begin{document}
and do not try to write to the aux file (which is not open) gh/645

2021-10-04 Frank Mittelbach <Frank.Mittelbach@latex-project.org>

* classes.dtx, doc.dtx, makeindx.dtx, preload.dtx, slides.dtx, array.dtx
Expand Down
13 changes: 12 additions & 1 deletion base/doc/ltnews34.tex
Expand Up @@ -479,7 +479,18 @@ \subsection{Undo some math alphabet allocations if necessary}




\subsection{Improvements to \cs{include}}
If \cs{include} is used before \verb|\begin{document}| then previously
it would write \verb|\@include{...}| to the terminal and log as the
aux file has not yet been opened. It also locally changed
the aux filename which could have unintended effects. \LaTeX\ now
warns about any use of \cs{include} before \verb|\begin{document}|
and as a recovery action will input the specified file if it exists (as
before) but without any adjustments to the aux file settings, and
without running the \cs{include} file hooks (only the generic file
hooks from \cs{InputIfFileExists}).
%
\githubissue{645}

\subsection{???}

Expand Down
20 changes: 18 additions & 2 deletions base/ltfiles.dtx
Expand Up @@ -32,7 +32,7 @@
%<*driver>
% \fi
\ProvidesFile{ltfiles.dtx}
[2021/08/25 v1.2o LaTeX Kernel (File Handling)]
[2021/10/14 v1.3a LaTeX Kernel (File Handling)]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{ltfiles.dtx}
Expand Down Expand Up @@ -823,8 +823,16 @@
%
% \changes{v1.2j}{2020/10/04}{Quotes around the aux file name removed,
% they are not needed and upset BibTeX (gh/400)}
% \changes{v1.3a}{2021/10/14}{Warn about use in preamble}
% \begin{macrocode}
\def\@include#1 {%
% \end{macrocode}
%
% \begin{macrocode}
\ifx\@nodocument\relax
% \end{macrocode}
%
% \begin{macrocode}
\clearpage
\if@filesw
\immediate\write\@mainaux{\string\@input{#1.aux}}%
Expand Down Expand Up @@ -892,7 +900,15 @@
\deadcycles\z@
\@nameuse{cp@#1}%
\fi
\let\@auxout\@mainaux}
\let\@auxout\@mainaux
% \end{macrocode}
%
% \begin{macrocode}
\else
\@latex@warning{%
\noexpand\include should only be used after \string\begin{document}}%
\@input@{#1}%
\fi}
% \end{macrocode}
%
% \changes{v1.2o}{2021/08/25}{Declare non-generic include hooks}
Expand Down
12 changes: 12 additions & 0 deletions base/testfiles/github-0645.lvt
@@ -0,0 +1,12 @@
\documentclass{article}

\input{test2e}

\START

% neither of these should echo \@input{zzz.aux} to the terminal
\include{foobar}

\include{s}

\END
7 changes: 7 additions & 0 deletions base/testfiles/github-0645.tlg
@@ -0,0 +1,7 @@
This is a generated file for the LaTeX2e validation system.
Don't change this file in any respect.
LaTeX Warning: \include should only be used after \begin{document} on input line ....
No file foobar.
LaTeX Warning: \include should only be used after \begin{document} on input line ....
(s.tex File ignored
)

0 comments on commit 741c371

Please sign in to comment.