从多个 dtx 文件导入代码时可以重置代码行编号吗?

从多个 dtx 文件导入代码时可以重置代码行编号吗?

我研究了 Will Robertson 的 DTXGALLERY 示例,现在将我的包设置为由三个包组成的包。每个包的代码都位于单独的 dtx 文件中,其中一个文件导入了两个。当我处理主 dtx 文件(导入其他两个文件)时,源代码列表在整个文档中是连续编号的。在 Robertson 的dtxgallery.dtx示例中dtxgallery.pdf,我看到源代码列表会随着每个列表重置,这就是我想要做的。我没有在文件中看到任何明显的内容dtxgallery.dtx,而且我似乎无法在此网站上找到有关它的任何信息。请注意,我正在使用tcolorbox文档库,因此这可能与它有关。

这是我的 MWE 文件。第一个是joe.dtx,它是导入其他两个的。(请注意,这些文件是从 5100 多行项目中精简而来的,仍然有点大,我真的不想发布它们,但我想我会这样做只是为了避免无处不在的 MWE 请求,所以请不要因此责备我!)

% \iffalse meta-comment
% !TEX program = lualatexmk
%
% Copyright (C) 2021 by Paul J. Heafner <[email protected]>
% ---------------------------------------------------------------------------
% This  work may be  distributed and/or modified  under the conditions of the 
% LaTeX Project Public  License, either  version 1.3  of this  license or (at 
% your option) any later version. The  latest  version  of this license is in
%            http://www.latex-project.org/lppl.txt
% and  version 1.3 or  later is  part of  all distributions of  LaTeX version 
% 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Paul J. Heafner.
%
% This work consists of the files joe.dtx
%                                 joeone.dtx
%                                 joetwo.dtx
%                                 joe.ins
%                                 joe.pdf
%                                 README.md
%
% and includes the derived files  joe.sty
%                                 joeone.sty
%                                 joetwo.sty
% ---------------------------------------------------------------------------
%
% \fi
%
% \iffalse
%
%<*internal>
\iffalse
%</internal>
%
%<*readme>
joe provides a sample package bundle. To install, open a command
line  and  type  the  following,  repeating 2-4 until there are no warnings:

  1. lualatex joe.ins  (can also use latex)
  2. lualatex joe.dtx  (lualatex is required)
  3. makeindex -s gind.ist -o joe.ind joe.idx
  4. makeindex -s gglo.ist -o joe.gls joe.glo

Move the *.sty files into a directory searched by TeX.
%</readme>
%
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\usedir{tex/latex/joe}
\preamble

 Copyright (C) 2021 by Paul J. Heafner <[email protected]>
 ---------------------------------------------------------------------------
 This  work may be  distributed and/or modified  under the conditions of the 
 LaTeX Project Public  License, either  version 1.3  of this  license or (at 
 your option) any later version. The  latest  version  of this license is in
            http://www.latex-project.org/lppl.txt
 and  version 1.3 or  later is  part of  all distributions of  LaTeX version 
 2005/12/01 or later.

 This work has the LPPL maintenance status `maintained'.

 The Current Maintainer of this work is Paul J. Heafner.

 This work consists of the files joe.dtx
                                 joeone.dtx
                                 joetwo.dtx
                                 joe.ins
                                 joe.pdf
                                 README.md

 and includes the derived files  joe.sty
                                 joeone.sty
                                 joetwo.sty
 ---------------------------------------------------------------------------

\endpreamble

\generate{\usepreamble\empty\usepostamble\empty
          \file{README.md}{\from{\jobname.dtx}{readme}}}
\generate{\file{\jobname.ins}{\from{\jobname.dtx}{install}}}
\generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}}}
\generate{\file{joeone.sty}{\from{joeone.dtx}{package}}}
\generate{\file{joetwo.sty}{\from{joetwo.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 joe.dtx  (lualatex is required)             *}
\Msg{*   3. makeindex -s gind.ist -o joe.ind joe.idx             *}
\Msg{*   4. makeindex -s gglo.ist -o joe.gls joe.glo             *}
\Msg{* Move the *.sty files into a directory searched by TeX.    *}
\Msg{*                                                           *}
\Msg{*************************************************************}
%</install>
%<install>\endbatchfile
%
%<*internal>
\usedir{tex/latex/joe}
\generate{\usepreamble\empty\usepostamble\empty
          \file{README.md}{\from{\jobname.dtx}{readme}}}
\generate{\file{\jobname.ins}{\from{\jobname.dtx}{install}}}
\generate{\file{\jobname.sty}{\from{\jobname.dtx}{package}}}
\generate{\file{joeone.sty}{\from{joeone.dtx}{package}}}
\generate{\file{joetwo.sty}{\from{joetwo.dtx}{package}}}
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%</internal>
%
%<*driver>
\ProvidesFile{joe.dtx}
%</driver>
%
%<*driver>
\documentclass[10pt]{ltxdoc}
\PassOptionsToPackage{listings,documentation}{tcolorbox} % prevent option clash
\usepackage{\jobname}                                    % load joe.sty
\usepackage{joeone}                                      % load joeone.sty
\usepackage{joetwo}                                      % load joetwo.sty
\usepackage{mwe}                                         % provides test images
\usepackage[left = 1.00in,%                              %
            right = 1.00in,%                             %
            marginparwidth = 0.70in]{geometry}           % main documentation
\usepackage[listings,documentation]{tcolorbox}           % workhorse package
\tcbset{%                                                % tcolorbox options
  index german settings,%
  index colorize = false,%
  lefthand ratio = 0.50,%
  color hyperlink = blue,%
  color command = purple,%
  color environment = purple!65!black,%
  doc left = 0.5in,%
  doc marginnote = {colframe = blue!50!white,colback = blue!5!white},%
  doc head command = {interior style = {fill,left color = blue!15!white}},%
  doc head environment = {interior style = {fill,left color = blue!15!white}},%
  doc head key = {interior style = {fill,left color = blue!15!white}},%
  docexample/.style = {%
      colback = gray!10!white,sidebyside,lefthand ratio = 0.5,center},%
}%
% Redefine tcolorbox's \tcbdocnew and \tcbdocupdated defaults.
\renewcommand*{\tcbdocnew}[1]
  {\textcolor{green!50!black}{\sffamily\bfseries N} #1}
\renewcommand*{\tcbdocupdated}[1]
  {\textcolor{blue!75!black}{\sffamily\bfseries U} #1}
\hypersetup{colorlinks=true}                      % colored links; no borders

%  See https://tex.stackexchange.com/q/156383/218142
\newcommand*{\pkg}[1]{\textsf{#1}}                    % typeset package names
\newcommand*{\joe}{\textsf{joe}}                      % typeset joe
\newcommand*{\joeone}{\textsf{joeone}}                % typeset joeone
\newcommand*{\joetwo}{\textsf{joetwo}}                % typeset joetwo
\newcommand*{\lualatex}{Lua\LaTeX}                    % typeset LuaLaTeX

% A customized internal hyperref tool to
% mimic that in tcolorbox.
\NewDocumentCommand{\setplace}{ s m }{%
  \IfBooleanTF {#1}%
    {\phantomsection}%
    {}%
  \label{#2}%    
}%
\NewDocumentCommand{\linktoplace}{ m m }{%
  \hyperref[#1]{\texttt{#2}%
    \ifnum\getpagerefnumber{#1}=\thepage\relax%
    \else%
      \textsuperscript{\ding{213}\,{P.}\,\pageref*{#1}}%
    \fi%
  }%
}%

% We need a new command for in-line listings to prevent overfull boxes.
% Anything in |...| will be in small plain text.
% Previously used !...! but that conflicts with colors.
\lstMakeShortInline[basicstyle=\normalfont\ttfamily\small]|

\DisableCrossrefs               % index descriptions only
\PageIndex                      % index refers to page numbers
\CodelineNumbered               % number source lines
\RecordChanges                  % record changes
\begin{document}                % main document
  \DocInput{\jobname.dtx}       %
  \DocInput{\jobname one.dtx}   %
  \DocInput{\jobname two.dtx}   %
  \PrintIndex                   %
\end{document}                  % end main document
%</driver>
% \fi
%
% \IndexPrologue{\section{Index}Page numbers refer to page where the 
%   corresponding entry is documented and/or referenced.}
% 
% \CheckSum{23}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \title{The \href{https://ctan.org/pkg/mandi}{\joe} Bundle}
% \author{^^A
%    Paul J. Heafner\thanks{^^A
%      Email: \href{mailto:[email protected]?subject=[Heafner]\%20mandi}
%      {[email protected]}^^A
%    }^^A
% }^^A
% \date{\today}
%
% \newgeometry{left=1.0in,right=1.0in,top=4.0in}
% \maketitle
% \thispagestyle{empty}
% \centerline{Version \joeversion}
% \centerline{\textbf{PLEASE DO NOT DISTRIBUTE THIS VERSION.}}
% \restoregeometry
%
% \newgeometry{left=1.0in,right=1.0in,top=0.5in,bottom=1.0in}
%   \tableofcontents
%   \newpage
%   \phantomsection
%   \addcontentsline{toc}{section}{Acknowledgements}
%   \section*{Acknowledgements}
%   Thank you.
%
%   \newpage
%   \phantomsection
%   \addcontentsline{toc}{section}{Change History}
%   \PrintChanges
%   \newpage
% \restoregeometry
%
% \changes{v1.0.0}{2021-05-24}{Initial release.} 
%
% \section{Introduction}
% This is the documentation for the \joe\ bundle, which is virtually useless.
%
% The \joe\ bundle consists of three packages: \joe, \joeone,
% and \joetwo. 
% 
% \section{All About the \joe\ Package}
% Load \joe\ as you would any package in your preamble. 
%
%\iffalse
%<*example>
%\fi
\begin{dispListing*}{sidebyside=false,listing only}
  \usepackage[options]{joe}
\end{dispListing*}
%\iffalse
%</example>
%\fi
%
%\iffalse
%<*example>
%\fi
\begin{docCommand}{joeversion}{}
  Typesets the current version and build date.
\end{docCommand}
\begin{dispExample*}{sidebyside=false}
  The version is \joeversion\ and is a stable build.
\end{dispExample*}
%\iffalse
%</example>
%\fi
%
% Try using the \refCom{joetwoversion} command.
%
% \StopEventually{}
%
% \newgeometry{left=0.50in,right=0.50in,top=1.00in,bottom=1.00in}
% \subsection{\joe\ Source Code}
%
% \iffalse
%<*package>
% \fi
% Definine the package version and date for global use, exploiting the fact
% that in a \pkg{.sty} file there is now no need for |\makeatletter| and
% |\makeatother|. This simplifies defining internal commands, with |@| 
% in the name, that are not for the user to know about.
%
%    \begin{macrocode}
\def\joe@Version{1.0.0}
\def\joe@Date{2021-05-24}
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\providecommand\DeclareRelease[3]{}
\providecommand\DeclareCurrentRelease[2]{}
\DeclareRelease{v1.0.0}{2021-05-24}{joe.sty}
\DeclareCurrentRelease{v\joe@Version}{\joe@Date}
\ProvidesPackage{joe}
  [\joe@Date\space v\joe@Version\space A useless package]
%    \end{macrocode}
%
% Define a convenient package version command.
%
%    \begin{macrocode}
\newcommand*{\joeversion}{v\joe@Version\space dated \joe@Date}
%    \end{macrocode}
%
% \restoregeometry
%
% \iffalse
%</package>
% \fi
%
% \Finale

这是joeone.dtx

% \iffalse meta-comment
% !TEX program = lualatexmk
%
% Copyright (C) 2021 by Paul J. Heafner <[email protected]>
% ---------------------------------------------------------------------------
% This  work may be  distributed and/or modified  under the conditions of the 
% LaTeX Project Public  License, either  version 1.3  of this  license or (at 
% your option) any later version. The  latest  version  of this license is in
%            http://www.latex-project.org/lppl.txt
% and  version 1.3 or  later is  part of  all distributions of  LaTeX version 
% 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Paul J. Heafner.
%
% This work consists of the files joe.dtx
%                                 joeone.dtx
%                                 joetwo.dtx
%                                 joe.ins
%                                 joe.pdf
%                                 README.md
%
% and includes the derived files  joe.sty
%                                 joeone.sty
%                                 joetwo.sty
% ---------------------------------------------------------------------------
%
% \fi
%
% \iffalse
%
%<*internal>
\iffalse
%</internal>
%
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%
%<*internal>
\usedir{tex/latex/joe}
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%</internal>
%
%<*driver>
\ProvidesFile{joeone.dtx}
%</driver>
%
%<*driver>
\DisableCrossrefs         % index descriptions only
\PageIndex                % index refers to page numbers
\CodelineNumbered         % number source lines
\RecordChanges            % record changes
\begin{document}          % main document
  \DocInput{\jobname.dtx} %
  \PrintIndex             %
\end{document}            % end main document
%</driver>
% \fi
%
% \CheckSum{23}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \changes{v1.0.0}{2021-05-24}{Initial release.} 
%
% \section{All About the \joeone\ Package}
% Load \joeone\ as you would any package in your preamble. 
%
%\iffalse
%<*example>
%\fi
\begin{dispListing*}{sidebyside=false,listing only}
  \usepackage[options]{joeone}
\end{dispListing*}
%\iffalse
%</example>
%\fi
%
%\iffalse
%<*example>
%\fi
\begin{docCommand}{joeoneversion}{}
  Typesets the current version and build date.
\end{docCommand}
\begin{dispExample*}{sidebyside=false}
  The version is \joeoneversion\ and is a stable build.
\end{dispExample*}
%\iffalse
%</example>
%\fi
%
% Try using the \refCom{joeversion} command.
%
% \StopEventually{}
%
% \newgeometry{left=0.50in,right=0.50in,top=1.00in,bottom=1.00in}
% \subsection{\joeone\ Source Code}
%
% \iffalse
%<*package>
% \fi
% Definine the package version and date for global use, exploiting the fact
% that in a \pkg{.sty} file there is now no need for |\makeatletter| and
% |\makeatother|. This simplifies defining internal commands, with |@| 
% in the name, that are not for the user to know about.
%
%    \begin{macrocode}
\def\joeone@Version{1.0.0}
\def\joeone@Date{2021-05-24}
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\providecommand\DeclareRelease[3]{}
\providecommand\DeclareCurrentRelease[2]{}
\DeclareRelease{v1.0.0}{2021-05-24}{joeone.sty}
\DeclareCurrentRelease{v\joeone@Version}{\joeone@Date}
\ProvidesPackage{joeone}
  [\joeone@Date\space v\joeone@Version\space A second useless package]
%    \end{macrocode}
%
% Define a convenient package version command.
%
%    \begin{macrocode}
\newcommand*{\joeoneversion}{v\joeone@Version\space dated \joeone@Date}
%    \end{macrocode}
%
% \restoregeometry
%
% \iffalse
%</package>
% \fi
%
% \Finale

最后是joetwo.dtx

% \iffalse meta-comment
% !TEX program = lualatexmk
%
% Copyright (C) 2021 by Paul J. Heafner <[email protected]>
% ---------------------------------------------------------------------------
% This  work may be  distributed and/or modified  under the conditions of the 
% LaTeX Project Public  License, either  version 1.3  of this  license or (at 
% your option) any later version. The  latest  version  of this license is in
%            http://www.latex-project.org/lppl.txt
% and  version 1.3 or  later is  part of  all distributions of  LaTeX version 
% 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Paul J. Heafner.
%
% This work consists of the files joe.dtx
%                                 joeone.dtx
%                                 joetwo.dtx
%                                 joe.ins
%                                 joe.pdf
%                                 README.md
%
% and includes the derived files  joe.sty
%                                 joeone.sty
%                                 joetwo.sty
% ---------------------------------------------------------------------------
%
% \fi
%
% \iffalse
%
%<*internal>
\iffalse
%</internal>
%
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%
%<*internal>
\usedir{tex/latex/joe}
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%</internal>
%
%<*driver>
\ProvidesFile{joetwo.dtx}
%</driver>
%
%<*driver>
\DisableCrossrefs         % index descriptions only
\PageIndex                % index refers to page numbers
\CodelineNumbered         % number source lines
\RecordChanges            % record changes
\begin{document}          % main document
  \DocInput{\jobname.dtx} %
  \PrintIndex             %
\end{document}            % end main document
%</driver>
% \fi
%
% \CheckSum{23}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \changes{v1.0.0}{2021-05-24}{Initial release.} 
%
% \section{All About the \joetwo\ Package}
% Load \joetwo\ as you would any package in your preamble. 
%
%\iffalse
%<*example>
%\fi
\begin{dispListing*}{sidebyside=false,listing only}
  \usepackage[options]{joetwo}
\end{dispListing*}
%\iffalse
%</example>
%\fi
%
%\iffalse
%<*example>
%\fi
\begin{docCommand}{joetwoversion}{}
  Typesets the current version and build date.
\end{docCommand}
\begin{dispExample*}{sidebyside=false}
  The version is \joetwoversion\ and is a stable build.
\end{dispExample*}
%\iffalse
%</example>
%\fi
%
% Try using the \refCom{joeoneversion} command.
%
% \StopEventually{}
%
% \newgeometry{left=0.50in,right=0.50in,top=1.00in,bottom=1.00in}
% \subsection{\joetwo\ Source Code}
%
% \iffalse
%<*package>
% \fi
% Definine the package version and date for global use, exploiting the fact
% that in a \pkg{.sty} file there is now no need for |\makeatletter| and
% |\makeatother|. This simplifies defining internal commands, with |@| 
% in the name, that are not for the user to know about.
%
%    \begin{macrocode}
\def\joetwo@Version{1.0.0}
\def\joetwo@Date{2021-05-24}
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\providecommand\DeclareRelease[3]{}
\providecommand\DeclareCurrentRelease[2]{}
\DeclareRelease{v1.0.0}{2021-05-24}{joetwo.sty}
\DeclareCurrentRelease{v\joetwo@Version}{\joetwo@Date}
\ProvidesPackage{joetwo}
  [\joetwo@Date\space v\joetwo@Version\space A third useless package]
%    \end{macrocode}
%
% Define a convenient package version command.
%
%    \begin{macrocode}
\newcommand*{\joetwoversion}{v\joetwo@Version\space dated \joetwo@Date}
%    \end{macrocode}
%
% \restoregeometry
%
% \iffalse
%</package>
% \fi
%
% \Finale

答案1

正如 Phelype 在他的评论中提到的,你可能并不真的想这样做。但如果你真的想这样做,你可能想遵循source2e.texsource2edoc.cls管理这一点。在这些文件中,行号会随着每个输入文件而重置,并且进行了一些黑客攻击以在索引中的行号之前包含零件号(实际上是字母),但由于 makeindex 的限制,他们将行号写为 A-47 并使用自定义 .ist 文件和一些黑客攻击来摆脱破折号。

整个过程有点儿像黑客行为,但如果你真的想继续研究,就值得深入研究。相关文件如下:

https://github.com/latex3/latex2e/blob/main/base/doc/source2e.tex https://github.com/latex3/latex2e/blob/main/base/source2edoc.cls

相关内容