I cannot get my xmltex MWE running

✍️ Written on 2022-07-22 in 907 words.
Part of project typho digital-typesetting


Usually it does not make any sense to post a non-working minimal working example. However, barely anyone is using xmltex. I wanted to post a MWE, that does not work. And I don’t know why. I’d be glad about any hints.

xmltex resources

xmltex was written around 2000 by David Carlisle. Here are some resources:

XML standard compatibility:

  • xmltex claims Latin-1 and Cyrillic element names to be supported

  • xmltex claims basic support for XML namespaces

Minimal working example

I wanted to build a minimal working example and test it to explore xmltex. I never made any run.

The idea of xmltex is to redefine the Teχ parser (i.e. the set of category codes in combination with defined control sequences) such that XML elements are processed like control sequences. You can run Teχ code before and after XML elements occur. This reminds me of SAX Parsers APIs.


First of all, we need an XML file, we want to process.

  • I am explicitly using element names not found in any other contexts.

  • We have an explicit SYSTEM declaration to signal which elements we talk about.

  • I did not think of the SYSTEM declaration first, but someone hinted me then, that xmltex is sometimes peculiar about it. The overall result is the same without it.

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE dokumento SYSTEM "https://typho.org/xmltex">


Second, we need a Teχ file which points to the XML file. For this, we just define control sequence xmlfile with the name of XML file and then process the xmltex file:

  • /usr/share/… is the path to the xmltex file on my Linux system with a texlive installation. Just xmltex.tex also works for me.

\input /usr/share/texlive/texmf-dist/tex/xmltex/base/xmltex.tex


The xmltex.cfg file contains generic instructions for xmltex and in particular, it declares the SYSTEM document type and asks to load document.xmt whenever this type of XML document is processed.



So, if the SYSTEM document type https://typho.org/xmltex is used, the following Teχ file is loaded which declares what to do before/after respective elements:

\XMLelement{dokumento}{}{ \begin{document} }{ \end{document} }
\XMLelement{titolo}{}{ \section{Heading} }{ }


>> latex document

This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019/Debian) (preloaded format=latex)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2020-02-02> patch level 2
L3 programming layer <2020-02-14>
xmltex version: 2002/06/25 v1.9 (Exp)

Encoding = utf-8 (./xmltex.cfg)
No File: document.cfg (./document.xml
Document Element: dokumento
Doctype Public:
Doctype System: https://typho.org/xmltex
 <0:dokumento (./document.xmt)  >
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.

l.1 %
? X
No pages of output.
Transcript written on document.log.

>> latex -v

pdfTeX 3.14159265-2.6-1.40.20 (TeX Live 2019/Debian)
kpathsea version 6.3.1
Copyright 2019 Han The Thanh (pdfTeX) et al.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Han The Thanh (pdfTeX) et al.
Compiled with libpng 1.6.37; using libpng 1.6.37
Compiled with zlib 1.2.11; using zlib 1.2.11
Compiled with xpdf version 4.01


The test files, mentioned in the README file, yield the same error. This leads me to the conclusion that Teχlive somehow broke parts of the xmltex implementation over time. I also tried it with the newer LaTeX2e build from 2021-11 and got the same errors.

Teχ is really not a good example for backwards compatibility.