Friday, March 28, 2014

How to Begin Learning and Applying LaTeX

I recently started working with LaTeX based on a colleague's recommendation. To be honest, it was a little steeper learning curve installing it and initially learning it than I've become used to when installing and using new software development products and I hope in this post to provide some basic tips to help others who want to investigate this "document preparation system." The main LaTeX project page describes it as "a high-quality typesetting system" that "is designed for the production of technical and scientific documentation."

An introduction to LaTeX helps to understand what LaTeX is at a high-level and is probably the best place to start when trying to determine whether to invest more time in learning LaTeX. This page emphasizes that LaTeX is "not a word processor!" This page provides a simple example to demonstrate a driving principle of LaTex: "LaTeX is based on the idea that it is better to leave document design to document designers, and to let authors get on with writing documents."

Mike Unwalla's LaTeX: an introduction is a single-page PDF that also introduces LaTeX and provides another simple example of LaTeX code with the corresponding output. This article emphasizes how to pronounce LaTeX (it's NOT pronounced like the the rubber product latex that might dominate an initial Google search for this term).

A person interested in LaTeX after reading An introduction to LaTeX and LaTex: an introduction might want to next see the ubiquitous Hello World example so familiar to software developers applied to LaTeX. The best resource for this is the initial tutorial in Andrew Roberts's excellent series Getting to Grips with LaTeX. Tutorial #1 in the Getting to Grips with LaTeX tutorial series is called Absolute Beginners and provides a bare-bones Hello World example in LaTeX.

At this point, the person investigating LaTeX probably wants to try it out. The main LaTeX project page references the Obtaining LaTeX page for information on acquiring LaTeX. My recommendation for LaTeX first-timers is to download the appropriate distribution for their operating system from the top "LaTeX for the impatient" section of this page. In this post, I'll talk more about downloading and installing proTeXt for Windows.

proTeXt can be downloaded from the proTeXt - MiKTeX-based distribution for Windows page. This page states that "proTeXt aims to be an easy-to-install TeX distribution for Windows, based on MiKTeX" (Joseph Wright compares MiKTeX to TEX Live in TEX on Windows: MiKTEX or TEX Live?). The page warns that this file is large (well over 1 GB in size). Once this large download is complete, click on the setup.exe file that appears as part of the download. That will lead to the appropriate extraction of proTeXt into a specified directory. At that point, click on the protext.exe file to install proTeXt. Clicking on (running) protext.exe brings up an installation pop-up that allows you to click buttons to install MiKTeX (version 2.9 currently) and TeXstudio (version 2.5.2 currently). MiKTeX is large and its installation takes a considerable amount of time while the much smaller TeXstudio installs very quickly.

With MiKTeX and TeXstudio installed, we are ready to try a LaTeX example out. To do this, I will run TeXstudio in Windows. The next two screen snapshots show this in two different ways (one from selecting from "All Programs" and one from selecting it after it's been used and is pinned to the Startup Menu).

Once I have started up TeXstudio, I will see something like that shown in the next screen snapshot.

You can click on the icon in the top left corner that looks like a page of paper with a white plus sign inscribed within a green circle to create a new TeX source file. After doing this, pasting code from the Getting to Grips with LaTeX Absolute beginners Hello World example, adapting that example slightly, and saving the file as hello.text, I see the following (with the "About" popup included):

At this point, we have specified the content of our file and now need to convert it to the presentation format of our choice. In this case, I am going to use the downloaded MiKTeX to convert this hello.tex file to a PDF. I do this by opening a DOS command prompt and navigating to the directory where I told TeXstudio to save the hello.tex file (C:\latex\examples in this case). The next screen snapshot shows that file in that location.

At this point, I want to run the MiKTeX tools against this file. I can verify that the MiKTeX installation has placed MiKTeX in my path on Windows by typing echo %PATH% and looking for something like "C:\Program Files\MiKTeX 2.9\miktex\bin\" in the output. That directory has numerous executable (.exe) files including pdflatex.exe which I am going to use her to generate a PDF from hello.tex. This is demonstrated in the next screen snapshots which show the command-line generation process and a snapshot of the resultant PDF.

The next screen snapshot indicates that we now have four files in the directory in which the hello.tex file was the original sole occupant. The new three files are the PDF output file just shown, a text-based log file, and a text-based .aux file.

With the appropriate LaTeX distribution downloaded, a useful LaTeX editor with code completion and color syntax available, and the ability to run the LaTeX distribution executables against generated LaTeX source code, one can now start to experiment with the numerous commands that LaTeX supports. There are numerous listings and "cheat sheets" for these numerous commands, including Scott Pakin's The Comprehensive LaTeX Symbol List, LaTeX Command Summary, and TeX Reference Card. Basic LaTeX Commands has a nice brief introduction to some of the most important LaTeX commands.

One of the best ways to quickly learn LaTeX commands is to apply styling and structure via the graphical TeXstudio tool. The tool has icons for bold, italics, basic math operations, miscellaneous symbols, etc. The next screen snapshot shows an edited file in TeXstudio in which I almost randomly applied LaTeX commands entirely via TeXstudio. The screen snapshot after that shows the PDF generated with pdflatex.exe.


The most difficult aspect of learning LaTeX is dealing with so many options. The numerous options for LaTeX implementations/distributions can make it a bit overwhelming deciding which to download and use. Once that obstacle has been overcome, the large number of commands that LaTeX supports can be a bit daunting. Fortunately, I found that I have been able to start apply LaTeX by following the steps outlined in this blog post.

Additional Resources

No comments: