LaTeX:如何查找命令所属的包?

发布于 2024-08-25 14:01:05 字数 167 浏览 3 评论 0原文

这是一个简单的问题,我无法找到答案:

给定一个 LaTeX 命令,我如何找出它属于或来自哪个从?

例如,给定 \qquad 水平间距命令,它来自哪个包?特别麻烦,因为它不需要任何包就可以工作!

It is a simple question to which I am not able to find the answer:

Given a LaTeX command, how do I find out what package(s) it belongs to or comes from?

For example, given the \qquad horizontal spacing command, what package does it come from? Especially troublesome since it works without including any package!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

水中月 2024-09-01 14:01:05

给定一个 LaTeX 命令,我如何找出它属于或来自哪个包?

查阅您的参考资料:

  1. 如果它位于 TeXbook 的索引中,则它是从 TeX(驱动 LaTeX 的引擎)继承的。
  2. 否则,如果它位于 LaTeX 手册的索引中,则它可能是在 latex.ltx 或标准类文件之一中定义的,而不是在包中。
  3. 否则,如果它位于 The LaTeX Companion 的索引中,则页码可能会告诉您它来自哪个包。
  4. 否则,您可以对 find /usr/share/texmf -name '*.sty' 的结果进行一些奇特的 grep 操作,但要做好痛苦练习的准备。
  5. 或者,您可以在 http://stackoverflow.com 上询问。但随后有些白痴会回答你为什么想知道......

Given a LaTeX command, how do I find out what package(s) it belongs to or comes from?

Consult your references:

  1. If it's in the index to the TeXbook, it's inherited from TeX, the engine that drives LaTeX.
  2. Otherwise, if it's in the index to the LaTeX manual, it's probably defined in latex.ltx or in one of the standard class files, not in a package.
  3. Otherwise, if it's in the index to The LaTeX Companion, the page number probably tells you what package it's from.
  4. Otherwise, you could do some fancy grepping on the results of find /usr/share/texmf -name '*.sty', but be prepared for a painful exercise.
  5. Or, you could ask on http://stackoverflow.com. But then some idiot will respond by asking why you want to know...
冷情 2024-09-01 14:01:05

您可以搜索 http://www.ctan.org/tex-archive/info /symbols/compressive/ 了解该信息及更多信息。

请记住,LaTeX 是一种基于 TeX 的宏语言,所有宏都是由 TeX 组成的,无需导入。 \qquad 属于该类别。

You can search http://www.ctan.org/tex-archive/info/symbols/comprehensive/ for that information and more.

Remember that LaTeX is a macro language on top of TeX, and all the macros are made up of TeX which doesn't need to be imported. \qquad is in that category.

三生池水覆流年 2024-09-01 14:01:05

据我所知,对此没有真正好的通用答案。但是对于任何给定的命令,您都可以尝试多种技术。对于 \qquad 来说,它是基本 TeX 的一部分。请记住,您始终可以在交互模式下使用 TeX:

$ tex '\show\qquad'
This is TeX, Version 3.141592 (Web2C 7.5.6)
> \qquad=macro:
->\hskip 2em\relax .
 \show\qquad

? x
No pages of output.

一些宏是由 LaTeX 在 TeX 之上添加的,例如 \begin

 $ tex '\show\begin'
This is TeX, Version 3.141592 (Web2C 7.5.6)
> \begin=undefined.
 \show\begin

? x
No pages of output.

$ latex '\show\begin'
This is pdfTeXk, Version 3.141592-1.40.3 (Web2C 7.5.6)
 %&-line parsing enabled.
entering extended mode
LaTeX2e 
Babel  and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, greek, monogreek, ancientgreek, ibycus, pinyin, loaded.
> \begin=macro:
#1->\@ifundefined {#1}{\def \reserved@a {\@latex@error {Environment #1 undefine
d}\@eha }}{\def \reserved@a {\def \@currenvir {#1}\edef \@currenvline {\on@line
 }\csname #1\endcsname }}\@ignorefalse \begingroup \@endpefalse \reserved@a .
 \show\begin

? x
No pages of output.

其他所有内容都来自包。如果您确实想知道宏来自哪个包(除了通过 google 或 grep texmf 树),您可以在加载每个包后检查它是否已定义。尝试在任何 \usepackage 命令之前定义它:

\let\oldusepackage\usepackage
\renewcommand\usepackage[1]{
  \oldusepackage{#1}
  \ifcsname includegraphics\endcsname
    \message{^^Jincludegraphics is defined in #1^^J}
    \let\usepackage\oldusepackage
  \fi}

然后,当您在 .tex 文件上运行 latex 时,在输出中查找一行: includegraphics 在graphicx 中定义。这不太可能,但一些狡猾的包可能会用 \usepackage 做坏事,所以这可能不起作用。另一种选择是在加载任何包之前简单地定义您感兴趣的命令:

\newcommand\includegraphics{}

然后,当加载定义该命令的包时,您可能会收到一条错误消息。这实际上不如前一种方法可靠,因为许多包使用 \def\let 来定义它们的宏而不是 \newcommand,从而绕过了“已定义”检查。您也可以在每次加载之间手动插入一张支票:

\ifcsname includegraphics\endcsname\message{^^Jdefined after graphicx^^J}\fi

As far as I know, there is no really good general answer to this. But there are a number of techniques you might try for any given command. In the case of \qquad, it's part of basic TeX. Remember that you can always use TeX in interactive mode:

$ tex '\show\qquad'
This is TeX, Version 3.141592 (Web2C 7.5.6)
> \qquad=macro:
->\hskip 2em\relax .
 \show\qquad

? x
No pages of output.

Some macros are added by LaTeX on top of TeX, such as \begin:

 $ tex '\show\begin'
This is TeX, Version 3.141592 (Web2C 7.5.6)
> \begin=undefined.
 \show\begin

? x
No pages of output.

whereas

$ latex '\show\begin'
This is pdfTeXk, Version 3.141592-1.40.3 (Web2C 7.5.6)
 %&-line parsing enabled.
entering extended mode
LaTeX2e 
Babel  and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, greek, monogreek, ancientgreek, ibycus, pinyin, loaded.
> \begin=macro:
#1->\@ifundefined {#1}{\def \reserved@a {\@latex@error {Environment #1 undefine
d}\@eha }}{\def \reserved@a {\def \@currenvir {#1}\edef \@currenvline {\on@line
 }\csname #1\endcsname }}\@ignorefalse \begingroup \@endpefalse \reserved@a .
 \show\begin

? x
No pages of output.

Everything else comes from packages. If you really wanna know which package a macro comes from (other than by google or grepping your texmf tree), you can check after each package you load whether it's defined. Try defining this before any \usepackage commands:

\let\oldusepackage\usepackage
\renewcommand\usepackage[1]{
  \oldusepackage{#1}
  \ifcsname includegraphics\endcsname
    \message{^^Jincludegraphics is defined in #1^^J}
    \let\usepackage\oldusepackage
  \fi}

Then when you run latex on your .tex file, look for a line in the output that says includegraphics is defined in graphicx. It's not likely, but some devious packages might do bad things with \usepackage so there's a chance this might not work. Another alternative would be to simply define the command you're interested in before loading any packages:

\newcommand\includegraphics{}

Then you might get an error message when the package that defines the command is loading. This is actually less reliable than the former approach, since many packages use \def and \let to define their macros rather than \newcommand, bypassing the "already-defined" check. You could also just insert a check by hand in between each load:

\ifcsname includegraphics\endcsname\message{^^Jdefined after graphicx^^J}\fi

夏日落 2024-09-01 14:01:05

由于缺乏声誉,我无法评论史蒂夫的回答,这对我很有帮助,但我想扩展一下。

首先,在他的第二种方法(摆弄usepackage)中,没有处理usepackage具有可选参数的情况。其次,包通常由其他包通过 RequirePackage 加载,这使得很难找到命令定义的实际位置。所以我对 Steve 的答案的改进是:

\usepackage{xargs}
\let\oldusepackage\usepackage
\let\oldRequirePackage\RequirePackage
\renewcommandx{\usepackage}[3][1,3]{
  \oldusepackage[#1]{#2}[#3]
  \ifcsname includegraphics\endcsname
    \message{^^Jincludegraphics is defined in #2^^J}
    \let\usepackage\oldusepackage
    \let\RequirePackage\oldRequirePackage
  \fi}
\renewcommandx{\RequirePackage}[3][1,3]{
  \oldRequirePackage[#1]{#2}[#3]
  \ifcsname includegraphics\endcsname
    \message{^^Jincludegraphics is defined in #2^^J}
    \let\usepackage\oldusepackage
    \let\RequirePackage\oldRequirePackage
  \fi}

这里使用 xargs 包来获取 usepackage 的不寻常选项(第一个和第三个参数是可选的)。

将其直接放在 documentclass 之后应该可以告诉 includegraphics 的定义位置。

Due to lack of reputation I cannot comment on Steve's answer, which was very helpful to me, but I would like to extend it a bit.

First, in his second approach (fiddling with usepackage) the case where usepackage has optional arguments is not dealt with. Secondly, packages are often loaded by other packages via RequirePackage which makes it hard to find the actual place of definition of a command. So my refinement of Steve's answer is:

\usepackage{xargs}
\let\oldusepackage\usepackage
\let\oldRequirePackage\RequirePackage
\renewcommandx{\usepackage}[3][1,3]{
  \oldusepackage[#1]{#2}[#3]
  \ifcsname includegraphics\endcsname
    \message{^^Jincludegraphics is defined in #2^^J}
    \let\usepackage\oldusepackage
    \let\RequirePackage\oldRequirePackage
  \fi}
\renewcommandx{\RequirePackage}[3][1,3]{
  \oldRequirePackage[#1]{#2}[#3]
  \ifcsname includegraphics\endcsname
    \message{^^Jincludegraphics is defined in #2^^J}
    \let\usepackage\oldusepackage
    \let\RequirePackage\oldRequirePackage
  \fi}

The xargs package is used here to get the unusual options of usepackage right (first and third parameter are optional).

Putting this directly after documentclass should tell where includegraphics is defined.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文