kaashif's blog

Programming, software freedom and Unix

What is LaTeX?

You probably have not heard of LaTeX before now. If you have, then it is likely that you have no idea what LaTeX is, save for a vague feeling that it relates to documents in some way. By the end of this short post, you will not only know what LaTeX is, but be able to understand why people use it, and what its advantages are. While you probably won’t switch to LaTeX immediately, you might

be able to see yourself doing it if you ever have to write a non-trivial document. Non-trivial means, in this context, something longer than a few dozen pages, or something requiring a considerable amount of formatting which may take a while in your WYSIWYG editor of choice.

What is LaTeX?

LaTeX is a document preparation system, in the words of latex-project.org. That seems a bit vague, so I’ll say that it’s the name of a system involving two things: the writing of source “code” files in the LaTeX “language” and the compilation of that source into a final, prepared document. So you’d have your text file (referred to as LaTeX source) which may look something like this:

\title{My Article}
This is my document.

Then you’d run a LaTeX compilation command, like pdflatex myarticle, resulting in something like this:

The result

The result

Why use LaTeX?

It appears very pointless and silly to install a suite of document preparation programs and learn how to use a very large set of typesetting commands just to be able to write documents. Despite what you may think, it is not. LaTeX confers several advantages to the document writer.

The process of writing a document then compiling it divorces formatting and content. This means that, if you just want to write a 10,000 word essay, you will only have to type the 10,000 words into your favourite text editor and you won’t have to worry about faffing around with fonts, margins and whatnot. You might argue that the defaults in a WYSIWYG office program (such as LibreOffice Writer) are good enough that you won’t have to faff around anyway. You’d be wrong. When you are writing a title, for example, you must first center the text, make it bold or underlined, maybe increase the font size. This is all pointless and gets in the way of creating the content, which is what actually matters. With LaTeX, you write all of the content then worry about formatting. Even better, you could leave that to someone else.

The clear divide between source files and final documents allows you to write one source file and compile it into any of a variety of formats. This is not possible with formats such as Microsoft’s OOXML. It is impossible to 100% accurately convert documents to and from this format. That is a rather extreme example, but it is clear that the plain text standards (ASCII, Unicode) are completely open and that thousands of plain text editors exist. This allows you to write LaTeX source in whichever editor you want, and to compile it into whichever format you require, whether it be PDF, HTML, PostScript, or any other format.

The vast number of packages available for LaTeX online is staggering. Visiting the LaTeX website tells you that packages for everything from mathematical formula rendering to bibliography generation exist and are available freely. In LibreOffice Writer, for example, to create a section, you’d have to create a human readable line of text with some sort of formatting to distinguish it from the surrounding text. In LaTeX, you’d use a section command, like so:

\section{Why I love LaTeX}

\section{Why I hate clouds}
More reasons.

These commands are machine-readable, thus readable to the LaTeX compiler you are using. This means it is possible for a list of sections, subsections and subsubsections to be generated - this uses a simple \tableofcontents command from one of LaTeX’s packages. The flexibility and power of LaTeX becomes obvious when you start dealing with generating glossaries and indexes of thousand-page books.

How do I learn LaTeX?

I’m not going to write a sub-par LaTeX tutorial just for the sake of it. It’d be a waste of both my time and yours. Instead, I’ll point you to this site, which is a far better intro to LaTeX than I could ever write. There is also substantial documentation of many LaTeX features on that Wikibook, making it useful as a reference as well as a tutorial.