"Linux Gazette...making Linux just a little more fun!"


TeX without Tears!

By Martin Vermeer,


LyX, an international volunteer project that started off in Tübingen, Germany, is already revolutionizing Linux word processing. It is an interactive, visual shell for LaTeX running under X, giving finger-tip access to the raw power of this world class typesetting software -- while presenting a face to the user deceptively like, e.g., Microsoft's Word for Windows. And, most amazingly, just as easy to use!


1. Historical introduction

When you tell people that you are using Linux, their first comment often is "yes, a fine and interesting operating system for programmers and scientists, but not for ordinary people. There is no good applications software for it". Unfortunately, until just a couple of years ago, this remark was all too appropriate, especially where word processing was concerned.

It is only in recent years that the situation has begun to improve, with some good packages -- commercial, to be sure -- becoming available to UNIX in general, and to Linux in particular. E.g. Applixware, a complete office suite which received very good reviews in a recent article in Linux Journal, and the freeware-like Star Office package. Both of these contain very conventional word processing modules.

And yet -- TeX/Metafont, developed by Donald Knuth, and LaTeX, an extension written in TeX's macro language, from the hands of Leslie Lamport -- both systems further extended by a host of volunteers -- have existed for over a decade: free, publicly available, and good, very good. This is not WP any more, this is typesetting. You only have to look at a LaTeX-produced document, especially mathematics, to see the difference...

Until recently, the only way to use this software was by manually editing the source code of your document using the defined mark-up language -- the manual opened by the side of the keyboard. And writing formulas was a real pain in the butt. But mathematicians loved it! The beauty of LaTeX is, that it allows you to specify on a fairly abstract level the structure of a document, without bogging you down in details of the actual formatting.

Many science journals also distributed macro packages for TeX or LaTeX to help people write their articles in the prescribed standard format; thus, TeX became also an exchange standard for scientific manuscripts. (If only my Word for Windows would agree to produce the same page layout for my papers at home as it does at the job!)

Mark-up language. We have all heard of the mark-up language of the Web, HTML. Have you ever wondered how many web pages would be published in the world, if they all had to be edited by hand in raw HyperText Mark-up Language? Not many, I daresay. Everybody uses interactive, graphic tools, that show you here and now what your becoming web page looks like while you write it.


2. Enter LyX

Several years ago, Matthias Ettrich from Tübingen University's computer science department, decided to do something about it. Also LaTeX needed an editor that was easy to use and showed you interactively, on the screen, how the document was to be structured; and then, on your order, generated the LaTeX code containing all the embedded commands needed for the typesetting job. Ettrich's first attempt was called Lyrix, but the name had to be changed to LyX for legal reasons.

Other volunteers in several countries joined the effort and, a year ago, a first beta release, 0.10.7, was published on the Web. It was in no way perfect or complete; not even all of the most common LaTeX features were supported. Yet I was interested enough to try it, and here are my first impressions.

[Click for screen shot!]

For testing, and for writing this article, I use an Intel i486sx system running at 33 MHz (yes, LyX runs somewhat sluggishly, but at my job, on a 75 MHz Pentium, it flies), with 8 MB of memory and some 1.5 GB of Linux-dedicated disc storage. Last January I had installed RedHat 4.0 ("Colgate") and LaTeX2e the version required by LyX.

At the time when I started with Linux, in February this year, the LyX documentation was still pretty poor, but last June, a much improved documentation package has been published. About myself: I have some UNIX experience from half a decade ago (those Unices are hairy dogs next to Linux today), but my only previous experience with LaTeX has been occasionally printing out files that colleagues sent me.

LyX has many sites dedicated to it around the world. We list them here shortly. At them, you can find further links.

The "home site" for posting LyX material is the French machine, where new versions of LyX-related stuff are usually found first. Also the German LyX site in Tübingen is of interest. There also can be found links to a large number of other web sites dedicated to LyX on both sides of the Atlantic. In one of them, I even found a screen shot of LyX containing Chinese text...

There exists another LaTeX editor apparently designed along similar lines as LyX, for the MS Windows environment. It is a commerical product named "Scientific Word", said to be very good by its makers (of course!). I do not know any users however. Can anyone enlighten me? I also do not know if any Linux/UNIX version exists, as I for one do not fancy much the idea of having to use TeX in a DOS/Windows environment! But perhaps I am prejudiced...



3. Installation experiences

My Linux version on CD-ROM contained a pre-version of LyX in the "Contributed" department, which did not work properly. On the Web I found the beta version 0.10.7 and downloaded it, a *.tar.gz file ("tarball").

Tip:

The utility mc (Midnight Commander), a workalike of that other famous commander for DOS, allows you to look inside *.tar.gz and *.rpm (Red Hat Package Manager) files. Useful!

Inspecting the file with mc, or more traditionally, with the command

tar -tzvf, 

is followed by unpacking it with the command

tar -xzvf

into a pre-created directory lyx.

Remark:

To the beginning user, the tar command may seem forbidding with its scores of command line options. However, when using disk files rather than tape reels, you only need to know half a dozen of them; for creating an archive, scanning it, unpacking it, optionally gzipping/degzipping (GNU tar only!) and for giving the archive filename.

For help on all these options, use the on line help by typing

man tar

or

man info

or even better, their modern GUI equivalents

tkman tar

or

tkinfo tar.

Similarly you find help for any other command that you are interested in. The last two programs are good demonstations of the power of the tcl/tk scripting language, a sort of Visual Basic like (no insult intended) freeware thing running in a variety of windowing environments. Download recommended!

I created a directory lyx under /home, and expanded the downloaded package there.

First complication: LyX expects to be in /usr/local, being a standard place. If it is somewhere else, one must add the proper definition LYX_DIR to bashrc and LyX knows where everything is.

Next problem: To tell Linux where LyX is. As the binary executable was now in /home/lyx/bin/lyx, I solved this by putting a symbolic link into the executable directory /usr/bin, located in the shell's search path:

ln -s /home/lyx/bin/lyx /usr/bin/lyx, 

and that's it. Symlinks are handy!

After that, LyX worked obediently from anywhere on the system.

One can create an alias:

lyx="lyx -width 600 -height 350", 

with whatever values may be suitable to make the LyX window fit your screen.

To make also the man system find LyX's man pages, you should edit /etc/man.config, or alternatively (mandatory for tkman) define the shell variable MANPATH. Consult the relevant documentation.

There is a file .lyxrc in your home directory (or you should copy it there from the template in the distribution), which should be edited suitably. I found e.g. that the screen font utopia was lacking, and replaced it by times. Also the T1 font encoding did not work for the Scandinavian special characters, so I chose "default" instead; and input encoding "latin1". All the other editable options in the file are provided with helpful comments.

Some more tinkering with config files is needed to make everything work together. LyX, xdvi (print pre-viewer), ghostscript/ghostview (ditto; I found version 4.03-1 satisfactory, an older version proved buggy), dvips (printing module) and /etc/printcap, the file describing, or "retrofitting" by software, the capabilities of your printer. Fortunately the new, extensive LyX manual contains lots of info on these standard chores that any Linux user has to go through in order to make the printer work under Linux, and especially with TeX -- LyX or no LyX.

There are many other things you can or perhaps ought to do to make LyX live happily on your system; e.g., add it to the menu system of TheNextLevel. Let us hope that the packagers (Red Hat and others) will "discover" LyX and proceed to do all this tinkering on our behalf, so inexperienced users will not give up too easily before the slings and arrows of complexity...


4. Does it work?

The general answer to this is, based on my preliminary experiences: Yes!

It must be said that the software is not bug-free; but a segmentation fault is a rare event running LyX.

One annoying bug is that, when running LaTeX in the background after having just opened a file in the LyX window, control may not return to the foreground and one has to kill the job by control-C. (Obviously one does not lose any data due to this bug, only time.)

Also, many features in LaTeX -- some trivial -- are not directly supported by LyX or do not quite work as they should. I had trouble, e.g., with the Bibliography environment. But the more I got to know LyX, the more I learned to like it -- especially since it supports a transparency mode in which LaTeX commands are handed through unmodified to output. All you have to do is "paint" the LaTeX command red, using the mouse and the LaTeX toolbar button, and LyX skips all the processing there. This means that all commands not available directly in LyX, can be had by brute force, through the back door, in spite of LyX -- a technique at which I rapidly became proficient.

[Do-it-yourself 'bibliography' screen shot]

In fact, it is possible to use LyX simply as a "dumb editor" for LaTeX source code -- the way scientists have been using vi, emacs and all that. In this fashion, one gains nothing and loses nothing. As an editor, LyX is quite good, allowing you to set layout details, such as indent and alignment, for individual paragraphs, and character layout, such as font shaps and sizes, empasized, small caps, etc. for selected areas of text; as well as all that for the document as a whole (of course already this basic editing is translated internally to LaTeX mark-up).

But already using one of LaTeX's many "difficult" features supported by LyX -- the formula editor, say -- results in massive gains to the user, making the editing job quite essentially easier.

Anecdotical evidence: one of my German colleagues admitted that he has kept his LaTeX skills hidden from his university employer, because he hates writing -- nay, programming -- formulas and does not want to be ordered to do that.

We computer people should never underestimate the difficulty that programming (and mark-up language is a programming paradigm) poses to computer-naive users!


5. Formulas (formul\ae ?)

As a scientist I have to be able to write formulas easily and correctly. Therefore of course I wanted to put the math editor through its paces. The competition, MS Word for Windows, has a very good math editor (apparently sublicenced from a smaller company) and the litmus test for LyX is measuring up to this standard. Here follow some formulas that I often use in my work, first of all the expansion into spherical harmonics of the Earth's gravitational potential (W.A. Heiskanen and H. Moritz: Physical Geodesy, W.H. Freeman & Cy., 1967, p. 107):

[The formula on-screen]

...and in the print previewer (xdvi).

Another formula frequently encountered in physical geodesy is the Stokes integral, named after G.G. Stokes, the famous mathematician who in 1849 discovered this relationship between the global field of gravity anomalies (delta-g) and the undulations of mathematical mean sea level or the geoid N:

[Stokes on-screen]

where the Stokes function S is defined by the same picture

So, what should the conclusion be? I did not write these two formulas as fast as I would have done in the WfW Equation Editor; but faster than when I did that for the first time, many years ago (Übung macht den Meister). And it most certainly beats manual LaTeX coding in both speed and convenience!

The Math Editor is good, intuitive, interactive and a fine piece of programming. Some small additions would be needed still. A few of the weirder mathematical symbols are still lacking -- they could be added to the math panel in their raw LaTeX form --, and one does not get the integration domain placed straight underneath the integral sign, like with the summation limits to the big Sigma sign. In display mode, these limits, which are entered as "index" and "exponent" -- nice touch! -- end up straight underneath and above the Sigma, see above.

To number equations, just push "insert label" inside the equation box and follow the crowd. You may use symbolic names for the formulas which will appear when you try to insert a cross-reference. Just take your pick. LaTeX will replace the references by numbers in the right sequence.

The standard functions sin and cos should be entered in "macro mode" prefixing them by a backslash. They are correctly displayed in roman. But you have to remember the function and symbol LaTeX names... not hard for sines and cosines, though. Placing them somewhere in the math panel would be a good idea also.

Also plain roman text can be entered, by a keystroke sequence documented in the User's Guide. Sub- and superscripts are entered in the traditional LaTeX way by prefixing with an underscore or a "hat" symbol.

One way in which LaTeX math mode is superior to Word for Windows is in changing the font size. If you change the default font size in a LaTeX document, all fonts, including those inside formulas, change proportionally along, without any special effort from your side. In WfW you have to separately change the standard font size inside the formula editor, and then click on every formula... I like it more the LaTeX way.


6. Section headers and friends

Perhaps formulas and equations are a too specialized property to convince the ordinary user to switch to LyX. But what about something more down-to-earth, such as section, subsection, subsubsection etc. headers?

In short: excellently supported. LyX shows the header numbers on-screen, changing them if material is added or removed. What's more, you can open a table-of-contents panel where you can quickly navigate within large documents. (In Word for Windows, this would correspond to "outline mode". But you do not have to switch modes in LyX, just click on the right header in the TOC panel.)

Like we discussed above for formulas, also section headers etc. may be referred to by embedding labels in them. These labels appear in a label panel that pops up whenever you want to insert a reference; nifty. One can refer either to the (sub-) section itself, or to the page it is on, like in "see Section 3 on Page 7". If you move material around, the numbers in the printed output may change, but not the labels.

[Using section and page references]

If you want a section header without a number, you use the alternative form section* (and equivalent sub- and subsub- forms) from the styles menu. These headers will then also not appear in the table of contents. If you want the header to appear there after all, you'd better open your LaTeX Companion, page 36, and add the command

\addcontentsline{toc}{section}{Section headers and friends}

painted in LaTeX red, of course.


7. Figures and tables (and footnotes)

Also nicely supported. These can be put into a "float", to be positioned suitably on the page (as LaTeX) does. The figure can contain a caption; captions are numbered and collected into a List of Figures/Tables. They can also be referred to -- you guessed it -- by embedding a label into the caption text.

LyX 0.10.7 shows *.eps (encapsulated postscript) figures on the screen, and so does the print previewer xdvi. I have noticed, however, that LyX does not display large pictures, which do come out nicely in print.

[The EPS popup for embedding graphics]

EPS pictures can be drawn using the facility xfig, which has a complex and somewhat cumbersome user interface that takes some time to learn. (Anyway, it beats the drawing tool packaged with WfW 6, which was a great disappointment after the nice one packaged with WfW 2.) Also bitmapped pictures can be generated in EPS format, e.g. by using the screen grabber facility import, part of the ImageMagick package (recommended!). In this way, the screen shots for this article were produced, in a bitmapped graphics mode, though.

One weakness I noticed in LyX was the lacking support for the LaTeX figure* and table* commands, which place a figure or table float across the full width of a two column page. (But, then, one easily inserts these commands manually, painting them red...)

[A do-it-yourself full-width figure float, with labeled caption]

And footnotes, of course. (But no thanks command support!)


8. Nested environments

One of the well known niceties of LaTeX is also the three "nested environments" (enumerate, itemize, description) for making numbered/bulleted/labeled lists. LyX supports these on-screen roughly as they will be on paper, with the numbers or letters showing for the enumerate environment. And they can be freely nested, four levels deep. Great!

[Nested environments example]


9. Tables ("tabular")

Tables are nicely supported, with a fully functional (IMHO) table editor hanging from the right mouse button. The LyX team claims that this editor is buggy/incomplete/both, but it has satisfied at least my modest needs. The tables intelligently expand and contract depending on what they contain, just like in the LaTeX paper output. You can add and remove columns, put horizontal and vertical lines in the table or suppress them, and even join neighbouring cells. Text alignment can be set column-wise, like in LaTeX: left, right or centred.

[A table example, from the Users Guide]


10. Keyboard shortcuts, and other things

All the main menus given on the menu bar can be activated by pressing M-<letter>, the letter being the underlined one. Pretty logical, "Windows-like" and also documented somewhere in the set of documents in the 0.10.7 distribution.

What can be discovered by trial and error -- and is now also in the documentation --, is that M-<letter> followed by <space> pulls down the menu in question. A clever compromise saving CPU time on slow machines. And the submenu letters are given in the status line below the text screen anyway, if you hesitate... excellent design!

I was happy to find that my left hand finger reflex "Alt-F S" also here saved the file to disc. Use it frequently!

There are two different key binding maps available, the PC-like one (preferred by me, at least) and an emacs-like one for the aficionados.

LyX has also a good Find (and Find/Replace) facility

Cut and paste works within a document, and between two simultaneously open documents (only one of them is always visible). Also import from other applications works; export not yet.


11. Extending LyX

LyX 0.10.7 as distributed supports almost all the standard LaTeX2e textclass types: article, report, book, letter and amsart ("American Mathematical Society article"). Furthermore, a special mode for Linuxdoc SGML format is provided, used here to produce this text. Making overhead transparencies and slides is semi-supported.

This is of course only the tip of a substantial iceberg: according to The LaTeX Companion (M. Goossens, F. Mittelbach, A. Samarin, Addison-Wesley 1994) there exist over 150 packages catering for the most varied publishing needs -- from sheet music to Feynman diagrams, and everything in between. It will be some time before LyX catches up!

Adding new textclasses is not difficult. First, the textclass file for LaTeX should be found (on the web, usually) and installed, if not already on your distribution; these files have the extension .cls. Then, a so-called layout file must be created -- usually based on an existing one such as article.layout -- in which the known properties of all the major commands and environments for that textclass are described. If this is done properly, LyX will make these styles behave on-screen in ways similar to LaTeX on the printed page. In other words, the near-WYSIWYG property.

I wrote myself a few such layout files for journals I contribute to; One thing I discovered the hard way, is that to make LaTeX recognise a new class file, you have to run

texhash

and to make LyX find a new class and layout file pair, you have to first edit the file chkconfig.ltx, and then run

latex chkconfig.ltx

One learns by doing.


12. The future of LyX

After bringing out the 0.10.7 version, the LyX team proceeded to develop successive versions of 0.11. Unfortunately they have had no end of trouble with bugs; only now, 0.11.X is starting to be relatively clean and fully functional again. They replaced XForms, a library of graphic elements to be used under the X windowing system to produce user interfaces, by a similar but supposedly better library Qt; also many messy though functioning parts of the code have been sanitized.

One change in the making is the introduction of inheritance between .layout files; then you can say that a new texclass in LyX has all the properties of e.g. article, but with some added and some modified. In this way the work of writing new layout files, and of maintaining them, can be greatly reduced. LaTeX connoisseurs will recognize this technique as a carbon copy of the corresponding LaTeX practice, and will facilitate the "catching up" job for LyX.

Currently the Layout/Document menu offers a choice between various paper sizes, and for DIN A4 also a choice between a few standard margin width alternatives. Free setting of the margins by the user is not yet supported. Also this is scheduled to change. While waiting, you can use the geometry style package, which you should activate by including the lines

\usepackage{geometry}
\geometry{various page size and margin width options}

into the preamble of the LaTeX document. This is done from within LyX through the Layout menu. You see that one can still not do without a basic understanding of LaTeX...

One thing I intend to try out still is to use the mailmerge facility which is available for LaTeX inside LyX. It can surely be done, but a day has only 24 hours...


13. Some philosophical conclusions

Concludingly I will say that the LyX system, though being still a little rough around the edges, actually works well, is, inspite of the beta label, already production quality and really makes exploiting the unique properties of LaTeX a great deal easier. In fact, I would venture to claim that, once installed, LyX 0.10.7 is no more difficult to use than the leading commercial WP packages for MS Windows -- a remarkable claim perhaps for software that does so much more.

What I like about the LyX philosophy -- and there has been some debate on this in the newsgroups also -- is that it does not try to cover up the true complexity of typesetting text, a complexity properly addressed by LaTeX; it just harnesses the built-in intelligence of this existing typesetting software to make the handling of it more easy and intuitive. And that is how it should be.

Traditional word processors -- no names mentioned -- do give you more freedom to format the text as you want; remarkably, this is not always a good thing. It is easily possible to generate documents that look precisely as tasteless on screen as they come out on the printed page!

Of course there are things which by their nature are best done in a WYSIWYG fashion, e.g. the editing of mathematical formulas which are among the most visual typographic objects known to man. Also the logical structure of a document, its division in chapters, sections etc., is an essential property that must be visually represented. But other aspects of typesetting are not intrinsically visual -- e.g. the division of a paper into pages is more a property of paper as a hardware medium than an intrinsic property of a text. Also page headers, page numbers etc. are only "programming devices" targeted at us, flesh-and-blood browsers of printed text. This surface structure of the written message is inessential, and LyX rightly tries to handle this elegantly outside the user's field of view.


14. Acknowledgements, and more...

Everything in this text above that resembles a trademark, probably is one. Contrary perhaps to the impression created above, I hold Microsoft(tm) Word(tm) for Windows(tm) to be an excellent piece of software, arguably the best in its category. I have been a happy user myself for four years. It is the market leader, a de-facto standard against which others are measured.

And that LyX, and LaTeX, measure up so well, does not reflect poorly on the Microsoft programmers' skills; the message is a positive one, about the benefits of standing on tall shoulders -- each other's shoulders. LyX, TeX, Linux, all have simply grown in a better environment, one of openness, civic spirit and genuine enthusiasm, rather than of dollars and lawsuits. That freedom makes excellent economic sense has been known since Adam Smith. Resisting its pull is futile!


15. How this document was written

When I was asked to write this article for Linux Gazette, the suggestion was made to write it with LyX and convert the LaTeX code to HTML using the conversion utility latex2html. I installed and tried out this utility at my job computer (the Pentium!) and decided against using it. It was very demanding on the CPU, especially when converting formulas into GIF pictures.

Therefore I chose the alternative of writing the text in the Linuxdoc SGML textclass, which is supported by LyX. (I should say that this support is a little sketchy still at this point. It is easy to produce SGML files by LyX that the converter chokes on, e.g. containing tscreen, supposed to indent text.)

Then, conversion by sgml2html, included in the linuxdoc-sgml package -- runs very quickly -- and possible embedded pictures can be added only after that, using the Netscape HTML editor, if you have it installed. Obtaining these pictures, screen shots, was easy enough with ImageMagick.

Finally, UNIX wouldn't be UNIX, if there was not a quicker way to change the colours of background and text of all the .html files obtained from the conversion run:

#!/bin/bash 
# 
# Add background and text colour to an HTML document 
# 
for i in *.html 
  do 
    sed -e s'/<BODY>/<BODY bgcolor=\"fff0e8\" text=\"503000\">/g' $i >temp 
    mv temp $i 
    echo $i 
  done 
exit 0


Copyright © 1997, Martin Vermeer
Published in Issue 20 of the Linux Gazette, August 1997


[ TABLE OF CONTENTS ] [ FRONT PAGE ]  Back  Next