As part of my ongoing MathTeX.NET/Syracuse project, a formal specification of the grammar for the mathematical subset of the TeX language is being drafted. The grammar is specified fully using EBNF notation.
Below is the latest version of the grammar. While I’m working on the project, I’ll try to get around to updating this on a weekly basis. Active development is however limited to whenever I can find the time at the moment.
Last Updated: 07/10/09 (day/month/year)
input = relation expr , ? EOF ? ;
relation expr = fractional expr , [ ? relational op ? , relation expr ] ;
fractional expr = expr [ "\over" , expr ] ;
expr = term , [ expr operator , signed term ] ;
expr operator = "+" | "-" | "\pm" | "\mp" ;
signed term = [ "+" | "-" ] , term ;
term = factorial value , [ term operator , term | term ] ;
term operator = "*" | "/" | "\times" | "\cdot" | "\bmod" ;
factorial value = indexed value , [ "!" ] ;
indexed value = value , indices pair ;
value = raw value | group | bracket expr | factorial | fraction | binomial | root | function | big operator | text ;
raw value = ? number ? | ? letter ? | ? greek letter ? ;
indices pair = ( [ "^" , index ] , [ "_" , index ] ) | ( [ "_" , index ] , [ "^" , index ] ) ;
index = raw value | group ;
group = "{" , fractional expr , "}" ;
bracket expr = "{" , expr , "}" | "(" , expr , ")" | "[" , expr , "]" | "\{" , expr , "\}" ;
fraction = "\frac" , group , group ;
binomial = "\binom" , group , group ;
root = "\sqrt" , [ argument ] , group ;
function = ? function name ? , indices pair , fractional expr ;
argument = "[" , expr , "]" ;
big operator = ? big operator ? , indices pair , fractional expr ;
text = "{" , { ? letter ? }- , "}" ;
Any corrections or suggestions for improvement to the existing specification are most welcome. (Do however please wait on pointing out “missing rules”, since the grammar is naturally quite incomplete at the moment.)
If you are interested in contributing to this grammar specification or to the general development of the MathTeX.NET project (see the links given above for info), do feel free to drop me a message. It’s a pretty huge task, and help is always welcome!