Transform a tex source so that all macros are replaced by their definition

前端 未结 5 1490
说谎
说谎 2021-01-18 11:10

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

相关标签:
5条回答
  • 2021-01-18 11:28

    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
    
    0 讨论(0)
  • 2021-01-18 11:30

    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>-private.tex, which is the same as your original, but with your private macros replaced by their more basic things.

    0 讨论(0)
  • 2021-01-18 11:35

    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 }
    
    0 讨论(0)
  • 2021-01-18 11:37

    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.

    0 讨论(0)
  • 2021-01-18 11:40

    Try the Selective Macro Expander.

    0 讨论(0)
提交回复
热议问题