为什么从文档 3 开始使用 \PrintChanges 时我不能再删除“General:”?

为什么从文档 3 开始使用 \PrintChanges 时我不能再删除“General:”?

从版本 3 开始,该doc软件包提供了reportchangedates显示日期和软件包更改的选项。我想从更改列表中删除单词“General”及其后面的冒号。删除“General”很简单,\renewcommand{\generalname}{}但删除冒号更难。之前doc 3我一直在使用基于此解决方案的 hackhttps://tex.stackexchange.com/a/283894/218142并且它工作得很好,现在仍然如此。这个 hack 没有解决这个reportchangedates选项,事实上让它变得多余。我想我可以使用新的doc 3代码进行类似的 hack

\def\changes@#1#2#3{%
  \protected@edef\@tempa{\noexpand\glossary{#1%
                   \ifdoc@reportchangedates
                     \space -- #2\fi
                   \levelchar
                   \ifx\saved@macroname\@empty
                      \quotechar!%
                      \actualchar
                      \generalname
                   \else
                      \saved@indexname
                      \actualchar
                      \string\verb% % to fool emacs highlighting
                      \quotechar*%
                      \verbatimchar\saved@macroname
                      \verbatimchar
                   \fi
                   :\levelchar #3}}% <- I NEED TO CHANGE THIS LINE
  \@tempa\endgroup\@esphack}

但是当我这样做时,我收到一个未定义的控制序列错误\saved@indexname。我尝试过定义和重新定义它,但都不起作用。tcolorbox documentation如果这很重要,我会使用该库(我查看了它的源代码,没有发现任何明显的问题)。我看到doc 3源代码中\saved@indexname最初是空的,我看到它最终有条件地重新定义为哪里,\expandafter\@gobble\saved@macroname但这种改变似乎没有帮助,因为我收到一个\saved@macroname未定义的错误,但它表面上被初始化为空,我看不出它是如何被改变的。

我在下面整理了一个 MWE.dtx文件,必须命名才能sample.dtx正常工作。旧的 hack 工作方式已被注释掉;新的尝试是功能性的。将仅创建.pdf.sty文件(无文件)。.ins

% \iffalse meta-comment
% !TEX program = lualatexmk
% \fi
%
% \iffalse
%
%<*internal>
\iffalse
%</internal>
%
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\usedir{tex/latex/sample}
\preamble
Big Premamble
\endpreamble

\generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}}}

\obeyspaces
\Msg{*************************************************************}
\Msg{*                                                           *}
\Msg{* To finish the  installation, open a command line and      *}
\Msg{* type the following, repeating 2-4 until there are no      *}
\Msg{* warnings:                                                 *}
\Msg{*   2. lualatex sample.dtx  (lualatex is required)          *}
\Msg{*   3. makeindex -s gind.ist -o sample.ind sample.idx       *}
\Msg{*   4. makeindex -s gglo.ist -o sample.gls sample.glo       *}
\Msg{* Move the *.sty file into a directory searched by TeX.     *}
\Msg{*                                                           *}
\Msg{*************************************************************}
%</install>
%<install>\endbatchfile
%
%<*internal>
\usedir{tex/latex/sample}
\generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}}}
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%</internal>
%
%<*driver>
\documentclass[10pt,letterpaper,nohyperref]{ltxdoc} % let tcolorbox load hyperref
%\documentclass[10pt,letterpaper]{article}
%\usepackage[nohyperref]{doc}
\SetupDoc{reportchangedates}
\usepackage{\jobname}
\PassOptionsToPackage{listings,documentation}{tcolorbox}
\usepackage[listings,documentation]{tcolorbox}
\hypersetup{colorlinks=true}
\tcbset{%
  index german settings,%
  color hyperlink = blue,%
}%
%  See https://tex.stackexchange.com/q/156383/218142
\newcommand*{\pkg}[1]{\textsf{#1}}
\newcommand*{\sample}{\textsf{sample}}

%%%%% Local Hack That Works
^^A\renewcommand{\generalname}{} % gets rid of General
^^A\makeatletter
^^A\renewcommand*{\changes@}[3]{%
^^A \protected@edef\@tempa{%
^^A  \noexpand\glossary{#1 -- #2\levelchar % formatted as in doc v3
^^A   \ifx\saved@macroname\@empty
^^A    \space\actualchar\generalname
^^A   \else
^^A    \expandafter\@gobble\saved@macroname
^^A    \actualchar
^^A    \string\verb\quotechar*\verbatimchar\saved@macroname\verbatimchar
^^A   \fi
^^A    #3}}% <-- IT'S THIS LINE I CHANGED
^^A \@tempa
^^A \endgroup
^^A \@esphack
^^A}%
^^A\makeatother
%%%%% End Local Hack That Works
%%%%% Local Hack That Doesn't Work
\renewcommand{\generalname}{} % gets rid of General
\makeatletter
\renewcommand*{\changes@}[3]{%
  \protected@edef\@tempa{\noexpand\glossary{#1%
                   \ifdoc@reportchangedates
                     \space -- #2\fi
                   \levelchar
                   \ifx\saved@macroname\@empty
                      \quotechar!%
                      \actualchar
                      \generalname
                   \else
                      \saved@indexname
                      \actualchar
                      \string\verb% % to fool emacs highlighting
                      \quotechar*%
                      \verbatimchar\saved@macroname
                      \verbatimchar
                   \fi
                   #3}}% <-- IT'S THIS LINE I CHANGED
  \@tempa\endgroup\@esphack}
\makeatother
%%%%% End Local Hack That Doesn't Work

\DisableCrossrefs
\PageIndex
\CodelineNumbered
\RecordChanges
\begin{document}
  \DocInput{\jobname.dtx}
  \newpage
  \PrintIndex
  \PrintChanges
\end{document}
%</driver>
% \fi
%
% \IndexPrologue{\section{Index}Page numbers refer to page where the 
%   corresponding entry is documented and/or referenced.}
%
% \changes{v1.0.0}{2022-06-29}{Initial release}
% \section{Introduction}
% The \sample{} package is silly and does absolutely nothing useful.
%
% \subsection{Nothing Much}
% There's not much to say here.
%
% \subsection{The first command}
%\iffalse
%<*example>
%\fi
\begin{docCommand}{sampleversion}{}
  Typesets the current version and build date.
\end{docCommand}
\begin{dispExample*}{sidebyside = false}
  The version is \sampleversion{} and is a stable build.
\end{dispExample*}
%\iffalse
%</example>
%\fi
%
% \MaybeStop{}
%
% \section{\sample\ Source Code}
% This is the complete source code to the \sample{} package.
%
% \iffalse
%<*package>
% \fi
%
%    \begin{macrocode}
\def\sample@version{1.0.0}
\def\sample@date{2022-06-29}
\NeedsTeXFormat{LaTeX2e}[2020-02-02]
\DeclareRelease{v1.0.0}{2022-06-29}{sample.sty}
\DeclareCurrentRelease{v\sample@version}{\sample@date}
\ProvidesPackage{sample}
  [\sample@date\space v\sample@version\space A silly sample]
%    \end{macrocode}
%
% Define a convenient package version command.
% \changes{v1.0.0}{2022-06-29}{Added a macro.}
%    \begin{macrocode}
\newcommand*{\sampleversion}{v\sample@version\space dated \sample@date}
%    \end{macrocode}
%
%    \begin{macrocode}
\RequirePackage{iftex}          % needed for requiring LuaLaTeX
\RequirePackage{unicode-math}   % needed for Unicode support
\RequireLuaTeX                  % require this engine
%    \end{macrocode}
%
% \iffalse
%</package>
% \fi
% \Finale

答案1

我不喜欢回答自己的问题,但我知道重新定义changes@在直.tex文件中起作用,并且简单地删除:并且\levelchar不可能更改任何 catcode。

进一步的实验表明,解决方案是将修改后的changes@定义放在文件的注释部分中.dtx,我并不完全理解这一点,因为之前doc 3我不需要这样做。我还必须删除该<字符,因为它似乎也会导致问题,可能与保护语法有关。如果有人能解释为什么这个修复有效,我会很乐意接受这个答案。

尽管如此,这里是修正后的 MWE。

% \iffalse meta-comment
% !TEX program = lualatexmk
% \fi
%
% \iffalse
%
%<*internal>
\iffalse
%</internal>
%
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\usedir{tex/latex/sample}
\preamble
Big Premamble
\endpreamble

\generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}}}

\obeyspaces
\Msg{*************************************************************}
\Msg{*                                                           *}
\Msg{* To finish the  installation, open a command line and      *}
\Msg{* type the following, repeating 2-4 until there are no      *}
\Msg{* warnings:                                                 *}
\Msg{*   2. lualatex sample.dtx  (lualatex is required)          *}
\Msg{*   3. makeindex -s gind.ist -o sample.ind sample.idx       *}
\Msg{*   4. makeindex -s gglo.ist -o sample.gls sample.glo       *}
\Msg{* Move the *.sty file into a directory searched by TeX.     *}
\Msg{*                                                           *}
\Msg{*************************************************************}
%</install>
%<install>\endbatchfile
%
%<*internal>
\usedir{tex/latex/sample}
\generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}}}
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%</internal>
%
%<*driver>
\documentclass[10pt,letterpaper,nohyperref]{ltxdoc} % let tcolorbox load hyperref
%\documentclass[10pt,letterpaper]{article}
%\usepackage[nohyperref]{doc}
\SetupDoc{reportchangedates}
\usepackage{\jobname}
\PassOptionsToPackage{listings,documentation}{tcolorbox}
\usepackage[listings,documentation]{tcolorbox}
\hypersetup{colorlinks=true}
\tcbset{%
  index german settings,%
  color hyperlink = blue,%
}%
%  See https://tex.stackexchange.com/q/156383/218142
\newcommand*{\pkg}[1]{\textsf{#1}}
\newcommand*{\sample}{\textsf{sample}}

\DisableCrossrefs
\PageIndex
\CodelineNumbered
\RecordChanges
\begin{document}
  \DocInput{\jobname.dtx}
  \newpage
  \PrintIndex
  \PrintChanges
\end{document}
%</driver>
% \fi
%
% \IndexPrologue{\section{Index}Page numbers refer to page where the 
%   corresponding entry is documented and/or referenced.}
%
% \makeatletter
% \renewcommand{\generalname}{}
% \renewcommand{\changes@}[3]{%
%   \protected@edef\@tempa{\noexpand\glossary{#1%
%     \ifdoc@reportchangedates%
%       \space -- #2\fi%
%     \levelchar%
%     \ifx\saved@macroname\@empty%
%       \quotechar!%
%       \actualchar%
%       \generalname%
%     \else%
%       \saved@indexname%
%       \actualchar%
%       \string\verb% % to fool emacs highlighting
%       \quotechar*%
%       \verbatimchar\saved@macroname%
%       \verbatimchar%
%     \fi%
%     #3}}%
%  \@tempa\endgroup\@esphack}%
% \makeatother
%
% \changes{v1.0.0}{2022-06-29}{Initial release}
% \section{Introduction}
% The \sample{} package is silly and does absolutely nothing useful.
%
% \subsection{Nothing Much}
% There's not much to say here.
%
% \subsection{The first command}
%\iffalse
%<*example>
%\fi
\begin{docCommand}{sampleversion}{}
  Typesets the current version and build date.
\end{docCommand}
\begin{dispExample*}{sidebyside = false}
  The version is \sampleversion{} and is a stable build.
\end{dispExample*}
%\iffalse
%</example>
%\fi
%
% \MaybeStop{}
%
% \section{\sample\ Source Code}
% This is the complete source code to the \sample{} package.
%
% \iffalse
%<*package>
% \fi
%
%    \begin{macrocode}
\def\sample@version{1.0.0}
\def\sample@date{2022-06-29}
\NeedsTeXFormat{LaTeX2e}[2020-02-02]
\DeclareRelease{v1.0.0}{2022-06-29}{sample.sty}
\DeclareCurrentRelease{v\sample@version}{\sample@date}
\ProvidesPackage{sample}
  [\sample@date\space v\sample@version\space A silly sample]
%    \end{macrocode}
%
% Define a convenient package version command.
% \changes{v1.0.0}{2022-06-29}{Added a macro.}
%    \begin{macrocode}
\newcommand*{\sampleversion}{v\sample@version\space dated \sample@date}
%    \end{macrocode}
%
%    \begin{macrocode}
\RequirePackage{iftex}          % needed for requiring LuaLaTeX
\RequirePackage{unicode-math}   % needed for Unicode support
\RequireLuaTeX                  % require this engine
%    \end{macrocode}
%
% \iffalse
%</package>
% \fi
% \Finale

相关内容