使用@@标记私有代码并不能防止模块之间的冲突

使用@@标记私有代码并不能防止模块之间的冲突

expl3 文档说:在此处输入图片描述

在下面的代码中,pkgApkgB都定义了\@@_foo:,并且pkgB依赖于pkgA。我本以为%<@@=module>可以避免这个错误:

错误:LaTeX3 错误:控制序列\@@_foo:已定义。

为何事实并非如此?

包裹A:

% \iffalse meta-comment
% !TEX program  = pdfLaTeX
%<*internal> 
\iffalse
%</internal> 
%<*internal> 
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
\expandafter\begingroup
\fi
%</internal> 
%<*install> 
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\generate{
  \file{\jobname.sty}{\from{\jobname.dtx}{package}}
}
%</install> 
%<install> \endbatchfile
%<*internal> 
\generate{
  \file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
\nopreamble\nopostamble
\ifx\fmtname\nameofplainTeX
\expandafter\endbatchfile
\else
\expandafter\endgroup
\fi
%</internal> 
%<package> \NeedsTeXFormat{LaTeX2e}[2020/02/02]
%<package> \RequirePackage{expl3}
%<package> \ProvidesExplPackage
%<package> {pkgA}                                                                                 % Package name
%<package> {2020/04/17}                                                                           % Release date
%<package> {1.0}                                                                                  % Release version
%<package> {pkgA --- template for dtx}                                                            % Description
% 
%<*driver> 
\documentclass[full]{l3doc}
\usepackage{pkgA}
\usepackage[T1]{fontenc}% \char`[
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver> 
% \fi
% \GetFileInfo{\jobname.sty}
% \begin{documentation}
% \end{documentation}
% \begin{implementation}
%   \iffalse
%<*package>   
%   \fi
%<@@=pkgA>
%    \begin{macrocode}
\ExplSyntaxOn
\cs_new:Nn \@@_foo:{Hello, world!}
\ExplSyntaxOff
%    \end{macrocode}
% \end{implementation}
% 
% \iffalse
%</package> 
% \fi
% \Finale
\endinput

包裹B:

% \iffalse meta-comment
% !TEX program  = pdfLaTeX
%<*internal> 
\iffalse
%</internal> 
%<*internal> 
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
\expandafter\begingroup
\fi
%</internal> 
%<*install> 
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\generate{
  \file{\jobname.sty}{\from{\jobname.dtx}{package}}
}
%</install> 
%<install> \endbatchfile
%<*internal> 
\generate{
  \file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
\nopreamble\nopostamble
\ifx\fmtname\nameofplainTeX
\expandafter\endbatchfile
\else
\expandafter\endgroup
\fi
%</internal> 
%<package> \NeedsTeXFormat{LaTeX2e}[2020/02/02]
%<package> \RequirePackage{pkgA}
%<package> \ProvidesExplPackage
%<package> {pkgB}                                                                                 % Package name
%<package> {2020/04/17}                                                                           % Release date
%<package> {1.0}                                                                                  % Release version
%<package> {pkgB --- template for dtx}                                                            % Description
% 
%<*driver> 
\documentclass[full]{l3doc}
\usepackage{pkgB}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver> 
% \fi
% \GetFileInfo{\jobname.sty}
% \begin{documentation}
% \end{documentation}
% \begin{implementation}
%   \iffalse
%<*package>   
%   \fi
%<@@=pkgB>
%    \begin{macrocode}
\ExplSyntaxOn
\cs_new:Nn \@@_foo:{Jello, world!}
\ExplSyntaxOff
%    \end{macrocode}
% \end{implementation}
% 
% \iffalse
%</package> 
% \fi
% \Finale
\endinput

答案1

@@语法是设置源的惯例,以使内部函数/变量既明显又简短。但是,TeX 本身对此并不“了解”,因此如果您不执行其他任何操作,则实际上是在调用控制序列\@@_foo:。您需要做的是.dtx使用提取文件l3docstrip,而不是“原始”DocStrip。在提取代码行时,将用和适当的内部前缀l3docstrip替换。因此它将在此处的文件中生成和。@@<module>\__pkgA_foo:\__pkgB_foo:.sty

相关内容