Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  Peter Jansson May 11 '13 at 9:41
1  
For those unfamiliar with SAXON, can you clarify what you want, maybe with an example? –  Matthew Leingang May 11 '13 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 May 11 '13 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... –  David Carlisle May 12 '13 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. –  Stephan Lehmke May 12 '13 at 6:06
show 1 more comment

2 Answers

up vote 7 down vote accepted

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

\renewcommand\mysec[1]{\section{#1}}

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.

share|improve this answer
    
...Interesting. Is there any way to analyze LaTeX without expanding those macros? Thanks again! –  jackb May 12 '13 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 –  David Carlisle May 12 '13 at 13:14
add comment

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

http://www2.ph.ed.ac.uk/snuggletex/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.