0

I want to write a LaTeX-TeX parser to manipulate .tex files for a program. I found this question here How does a TeX engine read and render the input stream? which explains how everything works under the hood for TeX.

How is this process implemented in a LaTeX/TeX engine (for instance PDFTeX) ?

I want to know where I could find the source code for this particular part of a tex engine (LuaTeX or XeTeX would do the job too).

[UPDATE] I found some answer here too : Four TeX processors (as described in TeX by Topic)

12
  • 1
    See stackoverflow.com/questions/2731266/…. It provides a link to a pdf file with the source code. Jun 25, 2022 at 16:16
  • 1
    There's TeX Live on GitHub for the source code of the engine, but it's quite difficult to find out the correct part. Then there's texdoc tex which is the documentation of the original TeX engine's source code, but it's still difficult to parse. The most accessible one would be TeXbook. (or TeX by Topic which covers the primitives.) See also package writing - Where do I start LaTeX programming? - TeX - LaTeX Stack Exchange
    – user202729
    Jun 25, 2022 at 16:35
  • 4
    Although... for your initial question -- I don't think it's a good idea to do what you intend to do (figure out how TeX parses the input exactly), the only way to parse TeX "in general and correctly" is to run TeX. Which is most of the time not what you want, so just make some assumptions and implement your own (or use something existing. For Python there's TeXsoup etc. I think?
    – user202729
    Jun 25, 2022 at 16:37
  • 2
    Are you aware that the "parsing-behavior" of LaTeX can be changed in many ways while LaTeX is running? How things are parsed by LaTeX also depends on how the LaTeX-engine is initialized before starting reading the .tex-input-file in question.With LaTeX many things were changed in the recent past in this regard, e.g., loading of inputenc with utf-8-option by default with 8-bit-engines affecting catcode-settings, e.g., making control-sequences of xparse/expl3 available by default, ... What about utf-8-engines like XeTeX/LuaTeX? ... What about Lua-extensions? .. Jun 25, 2022 at 20:14
  • 1
    You may want to have a look at my answer to Macro for mass hyper-reference?/Detect phrase in tex input file just to see in what weird ways the parsing-behavior of LaTeX can be changed due to directives occurring in some .tex-input-file while LaTeX is running. Jun 25, 2022 at 20:14

0

You must log in to answer this question.

Browse other questions tagged .