在“book.cls”中定义的命令的“texdef”产生了意外结果

在“book.cls”中定义的命令的“texdef”产生了意外结果

当请求texdef定义的命令时,book.cls我们得到的响应是“未定义”。

$ texdef -t latex -s \chapter

\chapter:
undefined

但是如果命令定义在,article.cls我们会得到有效的结果:

$ texdef -t latex -s \section
% article.cls, line 302:
\newcommand\section{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\normalfont\Large\bfseries}}

如何查询中定义的命令book.cls

答案1

这是预期行为。当未明确提及类时,使用的默认类是article,并且由于该类未定义,\chapter因此它会正确报告。

-class要检查另一个类中的命令,您需要使用或选项明确说明该类-c

texdef -t latex -c book -s \chapter

% book.cls, line 350:
\newcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
                    \thispagestyle{plain}%
                    \global\@topnum\z@
                    \@afterindentfalse
                    \secdef\@chapter\@schapter}

如果您不知道定义特定命令的软件包,并且您拥有最新的 TeXLive 或 MikTeX,则可以尝试该texfindpkg实用程序。它可以查找(并安装)软件包依赖项以及查找给定命令名称的软件包。以下是一个例子:

$ texfindpkg query '\Soprano'

[tfp] you are using texlive
[tfp] found package file recorder-fingering.sty
[tfp] finding dependencies for recorder-fingering.sty
[tfp] finding dependencies for tikz.sty
[tfp] finding dependencies for pgf.sty
[tfp] finding dependencies for pgfrcs.sty
[tfp] no dependency info for everyshi.sty
[tfp] no dependency info for tikzlibrarycalc.sty
[tfp] finding dependencies for graphicx.sty
[tfp] finding dependencies for keyval.sty
[tfp] finding dependencies for trig.sty
[tfp] please install texlive package recorder-fingering pgf pgf pgf graphics graphics graphics

它正确地发现该\Soprano命令是由recorder-fingering包定义的。

如果您搜索多个包定义的命令,它将为您提供所有相关的包和依赖项:

$ texfindpkg query '\Tree'
[tfp] you are using texlive
[tfp] ================================================
[tfp] found package file logicpuzzle.sty with command \Tree
[tfp] building dependency tree for logicpuzzle.sty:
[tfp] ------------------------
[tfp] logicpuzzle.sty (from logicpuzzle)
[tfp] |- xkeyval.sty (from xkeyval)
[tfp] |- ifthen.sty (from latex)
[tfp] |- ragged2e.sty (from ragged2e)
[tfp]    |- footmisc.sty (from footmisc)
[tfp] |- marginnote.sty (from marginnote)
[tfp] |- tikz.sty (from pgf)
[tfp]    |- pgf.sty (from pgf)
[tfp]       |- pgfrcs.sty (from pgf)
[tfp]          |- everyshi.sty (from everyshi)
[tfp] |- tikzlibrarydecorations.pathmorphing.code.tex (from pgf)
[tfp] |- tikzlibrarydecorations.pathreplacing.code.tex (from pgf)
[tfp]    |- tikzlibrarydecorations.code.tex (from pgf)
[tfp] |- tikzlibrarycalc.code.tex (from pgf)
[tfp] |- tikzlibraryshapes.geometric.code.tex (from pgf)
[tfp] ------------------------
[tfp] texlive packages needed: logicpuzzle xkeyval latex ragged2e footmisc marginnote pgf everyshi
[tfp] these packages are already installed
[tfp] ================================================
[tfp] found package file qtree.sty with command \Tree
[tfp] building dependency tree for qtree.sty:
[tfp] ------------------------
[tfp] qtree.sty (from qtree)
[tfp] |- pict2e.sty (from pict2e)
[tfp]    |- trig.sty (from graphics)
[tfp] ------------------------
[tfp] texlive packages needed: qtree pict2e graphics
[tfp] these packages are already installed
[tfp] ================================================
[tfp] found package file tikz-qtree.sty with command \Tree
[tfp] building dependency tree for tikz-qtree.sty:
[tfp] ------------------------
[tfp] tikz-qtree.sty (from tikz-qtree)
[tfp] |- tikz.sty (from pgf)
[tfp]    |- pgf.sty (from pgf)
[tfp]       |- pgfrcs.sty (from pgf)
[tfp]          |- everyshi.sty (from everyshi)
[tfp] |- pgftree.sty (from tikz-qtree)
[tfp]    |- pgffor.sty (from pgf)
[tfp]       |- pgfmath.sty (from pgf)
[tfp]    |- pgfsubpic.sty (from tikz-qtree)
[tfp] ------------------------
[tfp] texlive packages needed: tikz-qtree pgf everyshi
[tfp] these packages are already installed
[tfp] ================================================
[tfp] texlive packages not yet installed in total: 

然而,这意味着如果你寻找很多包或类定义的东西(比如你原来的例子,\chapter它实际上会返回很多事物。信息会在那里,但是要找到它需要相当多的搜索。例如:

$ texfindpkg query '\chapter'

返回 1039 行输出。

可以使用以下方法进行更全面的搜索grep

$ grep -r '\Tree' /usr/local/texlive/2023/texmf-dist/tex/latex

但这也需要进行一些挖掘来找到实际定义特定命令的包。

相关内容