8

I am looking to develop a TEX parser, now problem is there is no Context Free Grammar and there can not be one, because its not context free language, I heard that it is some sort of macro language and that builds on its own.

So now I need direction of what kind of grammar this macro language has and how to build anything upon in c#.

I will write the tokenizer and parser, but I need some rules of macro in TEX which are quite hard to find, everywhere else there is documentation about how to use TEX macros.

1
  • 2
    Do you mean "TeX"? If you do, then the source code is available for you to translate. Also the code is comprehensively documented by volume B of Computers and Typesetting.
    – Richard
    Sep 28, 2010 at 16:20

2 Answers 2

11

TeX as a programming language is perhaps the most complex (non-esoteric) language ever created with a huge amount of "reserved words". You can remap the meaning of every character as it is read by the processor and in general do things you don't normally encounter while parsing a language.

If you really want to create your own TeX parser you will have to build on the original TeX. The source code is not only available, but it is written as a literate program using Knuth's ingenious WEB tool.

To complicate matters further you always use a macro package with TeX. The default package is Plain and the most well known is LaTeX. The macro package contains a non-trivial amount of code you will have to incorporate to be able to parse the particular "dialect" of TeX you want to parse.

1
  • Thanks, well its quite complicated for me to understand but I will try, I just want a little of TeX to be implemented, like writing little rich text with bold italics and symbols etc. Just like wiki compared to html, i prefer TeX because it can represent maths very well.
    – Akash Kava
    Sep 28, 2010 at 17:08
3

It depends on how much of TeX you actually want to implement. LaTeX2HTML is a perl project which converts LaTex to HTML. There's also MathJax which converts TeX math to HTML or MathML. If you want to see how some non-TeX programs parse TeX look at those.

1
  • I am only interested in math equations, but i don't get complete grammar to implement one for example x^2 is square of x, where else (x+2)^2 is square of x+2, but x^24 is 24th power of x, where else x^2 4 is separated by a space that makes x^2 and 4 as separate expressions. So I don't have concrete rules of what all to use as tokens and expressions.
    – Akash Kava
    Jan 16, 2011 at 10:07

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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