diff --git a/base/changes.txt b/base/changes.txt index c00b2351e..c6da05755 100644 --- a/base/changes.txt +++ b/base/changes.txt @@ -13,6 +13,12 @@ not part of the distribution. \index entries that are used directly in the document and aren't hidden inside other macros (because then no expansion happens) gh/1418 +2024-12-23 Frank Mittelbach + + * docstrip.dtx (subsection{Batchfile commands}): + Check that the stream macro (with the name of a file to generate) is not + already used, e.g., as a declared preamble (gh/1150) + 2024-12-22 Frank Mittelbach * ltcmdhooks.dtx (subsection{Patching or delaying}): diff --git a/base/doc/ltnews41.tex b/base/doc/ltnews41.tex index 2a5abf5c1..fbe8cac83 100644 --- a/base/doc/ltnews41.tex +++ b/base/doc/ltnews41.tex @@ -370,6 +370,18 @@ \subsection{Fix the use of \texttt{localmathalpabets}} % \githubissue[s]{1101 1028} +\subsection{\pkg{docstrip}:\ Error if \texttt{.ins} file is problematical} + +If a file to generate had the same name as a preamble declared with +\cs{declarepreamble} the preamble definition was overwritten because +the macro used to store it was reused for denoting the output +stream. The same problem happened with postambles declared with +\cs{declarepostamble}. This is now detected and an error message is +issued. To circumvent the issue in that case, simply use a different +macro name for the preamble or postamble. +% +\githubissue{1150} + \subsection{Prevent \texttt{cmd} hook from defining an undefined command} diff --git a/base/docstrip.dtx b/base/docstrip.dtx index 1d61d78f5..72ce24f5b 100644 --- a/base/docstrip.dtx +++ b/base/docstrip.dtx @@ -29,9 +29,9 @@ \catcode`\{=1 \catcode`\}=2 \def\filename{docstrip.dtx} -\def\fileversion{v2.6b} -\def\filedate{2022-09-03} -\def\docdate {2024-02-08} +\def\fileversion{v2.6c} +\def\filedate{2024-12-23} +\def\docdate {2024-12-23} %% % %\iffalse @@ -3027,8 +3027,37 @@ Z % defining preamble for the current file. % \begin{macrocode} \def\@fileX#1#2{% +% \end{macrocode} +% If the csname used for the stream has already been defined, e.g., +% as a preamble or postamble or for some other purposes, chances are +% that turning it into a stream number will break something. We +% therefore generate an error and show the current definition. +% \changes{v2.6c}{2024-12-23}{Check that stream macro is not already +% used (gh/1150)} +% \begin{macrocode} + \ifx#1\relax \else + \errmessage{Command \string#1 for denoting the output \noexpand + \file stream already defined!^^J + \space Current meaning is:^^J^^J\meaning#1^^J^^J + \space Extraction will probably fail - check result}% + \fi \chardef#1=\stream@closed \def\curout{#1}% +% \end{macrocode} +% If it matches the name of the current preamble or postamble then +% it definitely can't work, so we call that out explicitly: +% \begin{macrocode} + \ifx\curout\currentpreamble + \errmessage{Declared preamble name \string#1 not allowed if + \string\file{\@stripstring#1} is used}% + \fi + \ifx\curout\currentpostamble + \errmessage{Declared postamble name \string#1 not allowed if + \string\file{\@stripstring#1} is used}% + \fi +% \end{macrocode} +% +% \begin{macrocode} \let\curinfiles\empty \let\curinnames\empty \def\curref{\MetaPrefix ^^J%