转换 tex 源,以便所有宏都被其定义替换

发布于 2024-08-25 10:53:47 字数 96 浏览 4 评论 0原文

是否可以看到 TeX“预处理器”的输出,即? e.实际输出完成之前的中间步骤,但所有用户定义的宏都被替换,只留下 TeX 原语的子集?

或者说没有这样的中间步骤?

Is it possible to see the output of the TeX ‘pre-processor’, i. e. the intermediate step before the actual output is done but with all user-defined macros replaced and only a subset of TeX primitives left?

Or is there no such intermediate step?

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

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

发布评论

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

评论(5

桃扇骨 2024-09-01 10:53:47

Write

\edef\xxx{Any text with any commands. For example, $\phantom x$.}

然后用于在日志文件中输出

\show\xxx

或在文档中输出

\meaning\xxx

Write

\edef\xxx{Any text with any commands. For example, $\phantom x$.}

And then for output in the log-file

\show\xxx

or for output in your document

\meaning\xxx
叹梦 2024-09-01 10:53:47

TeX 中没有“预处理器”。任何阶段任何控制序列的替换文本都可能有所不同(这用于很多事情!)。例如,

\def\demo{\def\demo{cde}}
\demo

将首先以一种方式定义 \demo,然后更改它。以同样的方式,您可以重定向 TeX 原语。例如,LaTeX 内核将 \input 移动到内部位置并更改它。简化版本:

\let\@@input\input
\def\input#1{\@@input#1 }

There is no "pre-processor" in TeX. The replacement text for any control sequence at any stage can vary (this is used for a lot of things!). For example

\def\demo{\def\demo{cde}}
\demo

will first define \demo in one way and then change it. In the same way, you can redirect TeX primitives. For example, the LaTeX kernel moves \input to an internal position and alters it. A simplified version:

\let\@@input\input
\def\input#1{\@@input#1 }
雨的味道风的声音 2024-09-01 10:53:47

TeX 内置了很多差异跟踪工具,包括跟踪宏扩展。这仅在实际扩展时跟踪实时宏,但它仍然非常有用。完整详细信息请参阅 The TeXbook 以及其他地方。

当我尝试调试宏问题时,我通常只使用锤子:

\tracingall\tracingonline

然后我在输出或 .log 文件中挖掘我想知道的内容。

TeX has a lot of difference tracing tools built in, including tracing macro expansion. This only traces live macros as they are actually expanded, but it's still quite useful. Full details in The TeXbook and probably elsewhere.

When I'm trying to debug a macro problem I generally just use the big hammer:

\tracingall\tracingonline

then I dig in the output or the .log file for what I want to know.

陈甜 2024-09-01 10:53:47

在 tex.SE 的这个问题上有很多关于这个问题的讨论,并且这个问题。但我会借此机会指出,最好的答案 (IMO) 是使用 de-macro 程序,它是 TeXLive 附带的 python 脚本。它的功能非常强大,可以处理参数以及简单的替换。

要使用它,请将要扩展的宏移动到 -private.sty 文件中,并使用 \usepackage{-private 将其包含到文档中},然后运行de-macro。它会输出 -clean.tex,这与您的原始内容相同,但您的私有宏被更基本的内容替换。

There's a lot of discussion of this issue on this question at tex.SE, and this question. But I'll take the opportunity to note that the best answer (IMO) is to use the de-macro program, which is a python script that comes with TeXLive. It's quite capable, and can handle arguments as well as simple replacements.

To use it, you move the macros that you want expanded into a <something>-private.sty file, and include it into your document with \usepackage{<something>-private}, then run de-macro <mydocument>. It spits out <mydocument>-clean.tex, which is the same as your original, but with your private macros replaced by their more basic things.

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