[texhax] Grammar BNF of the TEX system

Reinhard Kotucha reinhard.kotucha at web.de
Wed Feb 22 03:09:52 CET 2006

>>>>> "Patricia" == Patricia Stoffel <Daifchen at gmx.net> writes:

  > Dear, we are two students of "Université de Liège" (Belgium)
  > (www.ulg.ac.be) in third year of studies in science of
  > informatics. In the class from M PA DeMarneffe named "Compilateur
  > et systèmes d'écritures de compilateurs" (informatical page in
  > french: http://progcours.ulg.ac.be/cocoon/cours/INFO0025-1.html),
  > we have to programme a compiler.

  > Our idea is transform a Tex-file into code HTML. For this, we need
  > the BNF grammar of the TEX-langage to adapt it at our needs (we do
  > not want use all the grammar, and limit our-selves at some
  > commands) .

The ultimate reference is "The TeXbook" by Donald E. Knuth,
Addison-Wesley, ISBN 0-201-13448-9.  Please complain at the library of
your university if it's not already there.

Another good book is "TeX by Topic" written by Victor Eijkhout.  It
can be downloaded from


I'm wondering whether the BNF grammar is a good starting point for
your compiler.  It probably makes more sense to write a macro package
which defines higher level commands which can be used more
conveniently by a human creating the input files and can be parsed
more easily by your compiler (because you define the syntax yourself).

You can even change the meaning of some characters, so that you can
say $url(http://www.gutenberg.eu.org) or even
<http://www.gutenberg.eu.org> instead of
\url{http://www.gutenberg.eu.org}.  This is a nice feature of TeX
(some people hate it, though) but it's a nightmare for yacc parsers
(because you are allowed to change the meaning of characters at any
time in your document).  I suppose that this is what Martin means when
he said "there is no real BNF of TeX".

And don't try to support mathematics if you want to finish your work
in a reasonable amount of time:)

BTW, there is a program "tex4ht" which transforms LaTeX code to html.
This program redefines most of the LaTeX macros and finally scans the
dvi files.  The result is amazing but the program is quite complex.

If you want to try it, don't try to install it yourself.  Installation
is not easy, but tex4ht already is part of MikTeX and TeXLive
http://tug.org/texlive . 

I hope that you are not too disappointed when you realize that you are
not the first one who had this idea.  But it's a good exercise anyway
and if it helps to create simple html pages without the need to read
huge amounts of documentation it will certainly be quite useful.

  > Do you know some contacts, who we can contact for more information
  > at this subject.

Mails to support at tug.org are passed to the texhax mailing list, see
http://www.tug.org/mailman/listinfo .  This is a good place to ask
questions like this.  Maybe more people are listening to the
TeX-related newsgroups, like comp.text.tex.

And please look at http://www.gutenberg.eu.org .  GUTenberg (Groupe
francophone des utilisateurs de TeX) can probably help you to find out
whether there is a local TeX users group in Liège.  Maybe your
neighbour is a TeX expert and you don't know yet...  


Reinhard Kotucha			              Phone: +49-511-4592165
Marschnerstr. 25
D-30167 Hannover	                      mailto:reinhard.kotucha at web.de
Microsoft isn't the answer. Microsoft is the question, and the answer is NO.

More information about the texhax mailing list