Index


RISC World

Having fun with TeX

Paul Webb shows that there's more to the TeX text processing language than meets the eye.

Despite its customary association with mathematics and science, the TeX document proccessing language has much to offer the more adventurous user. If you play games, design fonts or need to write documents in a language other than English then TeX could be for you. The TeX community has always been a very international one (see www.tug.org if you need convincing) with the consequence that a lot of energy has been expended on improving TeX so that it could deal with the punctuation marks and hyphenation patterns of a particular language.

Plain TeX speaks in tongues

Even without improvements designed to help with other languages, it is still possible to produce documents in a variety of languages which employ the Latin script by using nothing more than Plain TeX. Plain allows English-speaking TeXnicians to avail themselves of accents like the hat, umlaut, and tilde, as well as special characters like ligatures.

Kopka and Daly - the authors of the excellent Guide to LaTeX - work at the Max-Planck-Institut für Aeronomie in Germany. The name of the institute and the title of their book, which I would recommend to the readers of RISC World, could be typeset using Plain TeX in the following manner:

Helmut Kopka and Patrick W. Daly of the {\bf Max-Planck-Institut
f\"ur Aeronomie} are the authors of the brilliant book {\sl A 
Guide to LaTeX. Document Preparation for Beginners and Advanced 
Users\/} which everyone should read.
\end

Note how the dieresis above the u in fur was produced with the \" command. Observe also how the scope of the slanted command \sl was determined by grouping the book's title in brackets and how italic correction - controlling the interword space between slanted and roman type - was activated with the \/ command.

Get the idea? If you do, try the following exercise.

Figure one - an exercise in Arabic

Figure one above shows the transcription from Arabic into the Latin script of a short passage detailing the geographical position of Egypt. Note the use of the macron or bar and of the use of the dot-under-accent character. Here's the challenge. See if you can typeset the passage using Plain TeX by using the following commands:

  • \d <letter> which produces a dot under the character.
  • \= <letter> which produces a macron.
  • \i which produces an 'i' without its dot.

It's not that difficult, honest.

Does all this sound a bit like hard work? If the answer is 'yes', then think about using LaTeX for multilingual document processing.

LaTeX and the Tower of Babel

It is probably a good idea to confine yourself to the LaTeX base system if you only intend to include a few lines from a language other than English in a document. Listing one shows the code that was needed to typeset a poem from Pablo Neruda's beautiful collection of 20 love poems and one song of despair whilst Figure two (below) shows the dvi output. Note the use of the LaTeX verse environment which separates the stanzas of a poem by a blank line and breaks the lines within each stanza by the \\ command.

Figure 2

If however, you intend to produce an entire document in a language other than English, the babel package by Johannes Braams is one possible way to go. This package was devised in order to lessen the North American feel of LaTeX documents. Babel has a number of distinctive features which include the definition of hyphenation patterns via an external file and the translation of LaTeX elements and commands from North-American English into the requisite language. Babel is also of interest because it distinguishes between dialects within a language. A user is therefore able to choose between continental Portuguese and Brazilian Portuguese or between German and Austrian German.

Babel is activated by including the language or languages that you intend to use as the argument of the \usepackage{...} command. Where you specify more than one language, the last language listed will be the default. It is also possible to switch between languages by using the \selectlanguage{<name of language>} command. If you think that babel may be what you require then refer to Goossens et al's The LaTeX Companion (see the bibliography).

Non-Latin scripts

My own journey along the path towards TeX enlightenment (still not very far advanced!!) began with the discovery that TeX could deal with scripts as diverse as Greek (both Ancient and Modern), Russian, Arabic, Chinese and Hindi. Check out Goossens et al's The LaTeX Web Companion (see bibliography) for examples of how Singhalese, Devanagari and Sanskrit can be produced with TeX.

But my personal favourite is TeX's ability to produce the Arabic script. I have always loved Arabic because of its status both as a medium of communication and as an art form. So if you share my enthusiasm take a look at the ArabTeX package from the Institut fuer Informatik, Stuttgart. ArabTeX includes a Metafont generated Naskh script - a small copybook-type script used since the tenth century to produce the Quran - and a set of macros which can be used with Plain or LaTeX. ArabTeX extends the base system's capabilities by creating the arabtext environment inside which it is possible to insert mathematics and non-Arabic quotations. It is also possible to include one-line Arabic quotations in a document which would otherwise be dedicated to another language by placing commands between the <....> symbols. Figure Three (below) shows the one-line quotation mechanism is action. Listing Three shows the code that takes advantage of ArabTeX's dedicated environments and shows how short Arabic quotations can be combined with more substantial chunks of Arabic script.

Figure 3

Your move..TeX plays chess

So you're not interested in languages. That's fine; why not use TeX to produce a game board? If this topic interests you, you'll be delighted to discover that TeX can be used to produce Go, Xiangqi, Backgammon and European chess boards. For the sake of brevity we will however limit our discussion to European chess.

A LaTeX package is available - called chess, naturally - which uses a classical-looking chess font designed by Piet Tutelaers. Tutelaers' chess font is made up of 26 characters which depict the pieces on white and black squares respectively. The game board's perimeter is not represented by the font but appears courtesy of a set of macros. The package is useful for annotating complete games, devising chess questions and for recording move updates. Figure Four (below) shows a sample chess board after the dvi file was run through dvips and viewed through Ghostview on the PC Card whilst Listing Four shows the necessary LaTeX code. I obtained my copy of Ghostview from the TeX Live CD which is freely available to all members of a national TeX Users' Group. RISC OS users can of course obtain a Ghostcript/Ghostview port for our platform from HENSA (China CD) or go for Cerilica's RiScript (www.cerilica.com).

Figure 4

An interesting addition to the chess typesetting capabilities of LaTeX is bdfchess by Frank Hassel. This was designed for people who play correspondence chess where the tradition is to play two games at the same time so that both players can play as White. Hassel has consequently devised additional environments for the typesetting of chess postcards. Figure five (below) shows one side of a sample card. The reverse side would of course contain two on-going games typeset in the style of Figure Four. Interested readers should again consult Goossen et al's The LaTeX Graphics Companion for a complete account of the chess and bdfchess packages.

Figure 5

Metafont: TeX's Indispensable Cousin

So how is it possible for Plain TeX and LaTeX to use such a wide variety of fonts? Part of the responsibility for TeX's power must be attributed to Metafont because of its ability to describe the meta-ness of a shape in terms of a number of mathematical parameters. Knuth - the creator of both TeX and Metafont - uses the analogy of a meta-recipe whose ingredients can be mixed in varying proportions in order to create a slightly different flavour. The Metafont user therefore writes a program to create each symbol of a particular typeface. A Metafont program also requires an understanding of Cartesian coordinates and of a number of commands which can be used to produce shapes. The budding Metafonter will likewise need to develop an understanding of the relationship between mf, gf and pk files before taking full advantage of the system. Interested readers are referred to the brilliant METAFONTbook by Knuth (see the bibliography for the complete reference).

A Word of Encouragement

I hope that this article has convinced you that TeX can be used for more off-beat uses. I have looked at a few extensions to Plain TeX and LaTeX which match my interests but there will certainly be a package to suit your particular needs. A good place to start is Graham Williams' on-line TeX catalogue (http://www.act.cmis.au/gjw/tex/catalogue.html) which is vital if you know what you want to do with TeX but don't know what the packages are called. I would also direct your attention to Peter Flynn's CTAN search engine which makes the process of finding that elusive TeX-related file much easier (www.tug.org).

Much of the software mentioned in this article is on the CD-ROM.

I hope that you enjoy using TeX as much as I do. So now it's over to you...

Paul Webb

 Index