Skip to content

Commit

Permalink
Gh1150 docstrip (#1595)
Browse files Browse the repository at this point in the history
* fix for #1150

* try again

* Apply suggestions from code review

Co-authored-by: Yukai Chou <[email protected]>

* Update base/docstrip.dtx

Co-authored-by: Yukai Chou <[email protected]>

---------

Co-authored-by: Yukai Chou <[email protected]>
  • Loading branch information
FrankMittelbach and muzimuzhi authored Dec 29, 2024
1 parent 17df2c8 commit cd9093f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
6 changes: 6 additions & 0 deletions base/changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>

* 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 <[email protected]>

* ltcmdhooks.dtx (subsection{Patching or delaying}):
Expand Down
12 changes: 12 additions & 0 deletions base/doc/ltnews41.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
35 changes: 32 additions & 3 deletions base/docstrip.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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%
Expand Down

0 comments on commit cd9093f

Please sign in to comment.