From 4dddea453d529140f21d883475a62dd068d096b0 Mon Sep 17 00:00:00 2001 From: Frank Mittelbach Date: Mon, 23 Dec 2024 15:21:22 +0100 Subject: [PATCH 1/3] fix for #1150 --- base/changes.txt | 6 ++++++ base/doc/ltnews41.tex | 12 ++++++++++++ base/docstrip.dtx | 35 ++++++++++++++++++++++++++++++++--- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/base/changes.txt b/base/changes.txt index 387c6ab02..857d332dc 100644 --- a/base/changes.txt +++ b/base/changes.txt @@ -6,6 +6,12 @@ to completeness or accuracy and it contains some references to files that are not part of the distribution. ================================================================================ +2024-12-23 Frank Mittelbach + + * docstrip.dtx (subsection{Batchfile commands}): + Check that stream macro (with the name of a file to generate) is not + already used, e.g., as declared preamble (gh/1150) + 2024-12-21 Joseph Wright * ltoutenc.dtx Correct \=\i setup in T1 (gh/1587) diff --git a/base/doc/ltnews41.tex b/base/doc/ltnews41.tex index 0a2058288..d05026879 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 stored 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} + %\section{Changes to packages in the \pkg{amsmath} category} diff --git a/base/docstrip.dtx b/base/docstrip.dtx index 1d61d78f5..c1ad6fb3c 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 purpose, 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 postable 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% From 5337573e32c3b0e15b4d8ce1146ce07f7e11b80e Mon Sep 17 00:00:00 2001 From: Frank Mittelbach Date: Mon, 23 Dec 2024 15:23:37 +0100 Subject: [PATCH 2/3] try again --- base/doc/ltnews41.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/doc/ltnews41.tex b/base/doc/ltnews41.tex index d05026879..1e58dfa8b 100644 --- a/base/doc/ltnews41.tex +++ b/base/doc/ltnews41.tex @@ -370,7 +370,7 @@ \subsection{Fix the use of \texttt{localmathalpabets}} % \githubissue[s]{1101 1028} -\subsection{\pkg{docstrip}:\ Error if \texttt{.ins} file is problematical}} +\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 From fa4ef17b2081842e0fdc56c526313e80184e06a3 Mon Sep 17 00:00:00 2001 From: Frank Mittelbach Date: Mon, 23 Dec 2024 17:55:17 +0100 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Yukai Chou --- base/doc/ltnews41.tex | 2 +- base/docstrip.dtx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/base/doc/ltnews41.tex b/base/doc/ltnews41.tex index 1e58dfa8b..a43cf192e 100644 --- a/base/doc/ltnews41.tex +++ b/base/doc/ltnews41.tex @@ -374,7 +374,7 @@ \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 stored it was reused for denoting the output +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 diff --git a/base/docstrip.dtx b/base/docstrip.dtx index c1ad6fb3c..665e33b49 100644 --- a/base/docstrip.dtx +++ b/base/docstrip.dtx @@ -3029,7 +3029,7 @@ Z \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 purpose, chances are +% 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 @@ -3052,7 +3052,7 @@ Z \string\file{\@stripstring#1} is used}% \fi \ifx\curout\currentpostamble - \errmessage{Declared postamble name \string#1 not allowed if + \errmessage{Declared postamble name \string#1 not allowed if \string\file{\@stripstring#1} is used}% \fi % \end{macrocode}