2

I would like to manipulate a LaTeX document in a program, e.g. add/change used packages or their options and adding environments.

Instead of doing this purely on the text level, it would be great to know if there is some kind of abstract syntax tree that one can generate for LaTeX. I know that this probably not as easy as for "real" programming languages because the structure is less rigid. But maybe there is a representation that is more helpful than the pure text file.

  • In the general case this is not really feasible, see https://tex.stackexchange.com/questions/4201/is-there-a-bnf-grammar-of-the-tex-language for some background. However, many editors do a good job of extracting the structure of the code for a small document overview (Overleaf or TexStudio for example) or for code folding. I'm not sure how this is extracted but I guess just parsing \begin-\end pairs and \section, \subsection etc. does the trick for most cases. – Marijn May 23 '22 at 10:49
  • 1
    there are many latex-like systems that have such trees, but tex itself never parses the whole document or generates a tree of any sort. (se gellmu or latexml or tex4ht for systems that do have internal tree structures to some extent) – David Carlisle May 23 '22 at 10:51

0 Answers0