Open Source Musings The thoughts, ideas, and opinions of an open source guy

A brief introduction to LaTeX

The LaTeX logo

It comes as a suprise to some people when they learn that I’ve been using the LaTeX typesetting system for a number of years. It’s one of the most powerful tools in my writing and publishing toolkit. While I’m no LaTeX wizard, I do know enough about it to create some nice-looking documents.

But over the last few years, people have asked me what LaTeX is and why I think it’s such a great tool. To be honest, I’ve gotten a bit tired of climbing up on to my soapbox. So, for those of you who don’t know what LaTeX is and want to learn more, I’ve written this blog post.

So, let’s take a little trip into the world of typesetting with a twist. LaTeX is definitely not your parents’ (or your) publishing tool.

Origins and such

Once upon a time, a mathematician and computer scientist named Donald Knuth was annoyed and disappointed with the way in which his books on math and computer science were being typeset. So, taking matters into his own hands, Knuth learned about typography and typesetting and created TeX (pronounced tek). The result was a typesetting system that produces high-quality documents with the minimum of effort.

TeX itself is a freely-available group of programs, fonts, supporting files, and processes that produce beautifully typeset pages. It handles various aspects of a document’s layout – like justification, inter-word spacing, hyphenation, etc. – automatically. You don’t need to do any manual fiddling.

The problem with TeX is that it can be very difficult to learn and more difficult to learn how to control. That’s where LaTeX comes in.

Enter LaTeX

While TeX is fairly difficult to learn, LaTeX (pronounced lay-tek) makes things easier. LaTeX does that by adding a layer on top of TeX . It bundles additional features in packages that can consist of document classes (which are like templates or canned page layouts) and macros (sets of code that simplify more complex tasks).

Out of the box, LaTeX comes with a few document classes – book, report, article, and letter. They’re usable but a bit bland. You can download other classes that give you more advanced layouts and more control over those layouts. Take, for example, one of my favourites: memoir. It offers alternatives to the stock book layout.

Macros, for example, make it easier for you to add graphics and tables to a document; to include headers, footers, marginal notes and tables of contents; or to modify the layout of a page. While TeX often requires a long sequence of commands to do any of that, LaTeX can do the job with just one or two commands.

Creating documents

To typeset a page, you have to fashion an input file containing the text to typeset, as well as the commands that tell LaTeX how the document will look. These commands do the same thing as the tag in HTML. Best of all, it’s done in plain text entered into a text editor.

Here’s a sample of a report typeset using LaTeX document:

Example of a LaTeX document

I won’t go into what all that means. You can find a good explanation in this tutorial.

So you have a file with all that nice formatting code in it (and your words, too). What next? Run it through LaTeX to generate something called a DVI (DeVice Independent) file. The DVI file contains instructions that tell devices like document viewers and printers and photo typesetters how the document looks and feels. But you’re not limited to DVI, which a lot of software doesn’t support. There are tools for converting LaTeX files Postscript, PDF, and HTML. I usually skip building a DVI file and generate a PDF using the LaTeX command pdflatex.

Why use it?

LaTeX’s greatest strength (besides being free) is that it’s portable. Most publishing tools only have Windows or Mac version. LaTeX on the other hand, runs on Linux, Windows, MacOS, and other operating systems. Many Linux distributions come with LaTeX already installed.

And you don’t need a cutting-edge computer packing a lot of memory, a speedy processor, and a huge hard drive in order to get publishing. For the longest time, I worked with LaTeX on a computer with 1 GB of memory and a 300 MHz processor. In fact, my early forays into the world of LaTeX were on a 386 PC with 8 MB of memory. Yes, my documents did compile!

As I mentioned earlier, LaTeX files aren’t in format that only the application that created them can read. They’re plain text. You can edit LaTeX documents using any text editor on any operating system. Unlike, say, Microsoft Word (whose file format seems to change with every release or two), the format of LaTeX document and output files probably won’t change between now and the year 2099. You should be able to write, typeset, view, and print documents that produced with LaTeX now and in the future.

Because of its power and flexibility, LaTeX is widely used in scientific publishing. But you’re not limited to science and math. You can use LaTeX to write and publish articles, brochures, letters, reports, books, and business cards. There are even packages of layouts and macros that allow you to produce sheet music and slides for presentations.

You can view and print DVI files on any operating system without losing the formatting of the document. You only need the right fonts, which you should already have — they’re part of a LaTeX system.

And if you don’t want to install LaTeX on your computer, there’s another option: go to the web. Services like ShareLaTeX, Papeeria, and Overleaf bring the LaTeX experience to your browser. You can use LaTeX anywhere as long as you have an internet connection.

On the downside

LaTeX is great, but it isn’t perfect. It has a few drawbacks, the biggest of which is that it’s somewhat difficult to learn. Not quite as difficult as TeX (the system from which LaTeX is derived), but it’s not as easy to learn as LibreOffice Writer. It can take a while to come to grips with LaTeX.

Working with graphics isn’t the easiest the easiest task. If you’ve used a WYSIWYG tool like a word processor, then you know how easy it can be to insert images into a document. LaTeX is missing that simplicity. You have to use a separate macro to be able to include an image, and then you often need to tell LaTeX the image’s height, width and position on the page. This is tricky and takes a bit of fiddling.

On top of that, LaTeX demands a bit of knowledge from you. You need to know some basic typesetting terminology and have to learn a bit of LaTeX-specific terminology like badness, boxes and glue, and control sequence. Knowing what these terms mean will come in handy when you have to read a LaTeX error log if your document fails to build.

As I mentioned earlier, LaTeX isn’t WYSIWYG. To see whether or not you’ve done you job correctly you need to typeset and view your document. This gets tedious after a while. Having said that, some LaTeX editors have a live preview, which updates the typeset document as you make changes.

Final thoughts

LaTeX isn’t for everyone. But those who like it, like it a lot. Often, more than a lot. It’s a powerful and flexible way to write and publish just about anything. Best of all, as a Linux user you already have what you need to get using LaTeX.

Thoughts? Let's start a conversation on Twitter.

Did you enjoy this post or find it useful? Then please consider supporting this blog with a micropayment via Liberapay. Thanks!