I would like to know if there exists a LaTeX processor that works similar to SAXON for XML and XSLT documents. I would need it to extract some information from source code, and define its semantics.

  • Welcome to TeX.SX! Usually, we don't put a greeting or a “thank you” in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you. Commented May 11, 2013 at 9:41
  • 1
    For those unfamiliar with SAXON, can you clarify what you want, maybe with an example? Commented May 11, 2013 at 11:14
  • My aim is to find a tool which, by analyzing the document's syntax, returns either the tree structure of the document, or at each environment or command tells you what element has been recognized. Here's an example of what I meant (lxml): lxml.de/parsing.html#comments-and-pis
    – jackb
    Commented May 11, 2013 at 12:37
  • 1
    @jackb that aim is I suspect not really related to the question you asked about the source code of latex. I updated my answer... Commented May 12, 2013 at 1:04
  • 1
    I think your best starting point would be a LaTeX-to-something converter, as it also needs to extract this information. As a start, look here or here. But converting LaTeX to anything has been a hairy task always for the reasons mentioned by @DavidCarlisle, so don't expect too much. Better start with XML and convert to LaTeX. Commented May 12, 2013 at 6:06

2 Answers 2


LaTeX is completely open source and written in TeX, you can find a documented version of the sources as the file source2e texdoc source2e in most distributions.

TeX is also open source, written in WEB, a literate programming language that produces both the (pascal, originally, but now C) source of the program and also a (TeX) document describing the source in complete detail. tex.web is also available in all TeX distributions, or you can get the fully typeset and indexed version as the published book TeX: The Program.

Given the clarification of your aims in comments I don't think the source of either LaTeX or TeX will help much.

I suspect that a more productive way forward would be to convert to XHTML using latexml or tex4ht and then analysing the resulting XML. In deriving a tree structure from a latex document you need to make a lot of more or less arbitrary choices, and existing convertors have already made them. For example you probably want to expand some macros so if the user has gone


then you see \mysec as a section marker, but you don't want to expand all macros, as LaTeX is just defined via macros so for example you want to see \section as part of the tree structure, you don't want to expand it all out and just see a weird collection of spacing and font setting commands. there can never be any hard rules about which macros to expand and which to consider as marking the document tree structure, it's all heuristics and guesswork unless you know the document author.

  • ...Interesting. Is there any way to analyze LaTeX without expanding those macros? Thanks again!
    – jackb
    Commented May 12, 2013 at 12:30
  • 1
    @jackb not really: have a look at xii.tex (which is plain tex but could be latex) analysing latex is hard it is not at all like XML which has a fixed syntax: you need to typeset it to parse it Commented May 12, 2013 at 13:14

In the meantime, I've found this project that could convert LaTeX elements into HTML+MathML, and also implements a LaTeX parser.


  • Resource in the provided link is dead. Any alternatives?
    – Arcanefoam
    Commented Mar 26 at 16:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .