LaTeX Typesetting with MiKTeX

This page describes my own setup for LaTeX typesetting on Microsoft Windows using the MiKTeX system. I’m going into less detail here than in my DITA tutorials for FrameMaker and Oxygen because modern LaTeX is relatively straightforward and well-documented. There are few pitfalls, and most questions are easily answered by a web search. Moreover, Leslie Lamport’s LaTeX: A Document Preparation System (2nd ed., Addison-Wesley 1994) is still an excellent user’s guide. Every beginning LaTeX user should read this book, and I’ll assume you have done so.

Overview

MiKTeX by Christian Schenk is a polished all-in-one installation package for TeX and LaTeX on Windows. I recommend you get the 32-bit version of the “Basic Installer”. This package contains TeX engines, an editor, and various style packages. Moreover, whenever your LaTeX documents reference a style package that’s not yet installed, MiKTeX will automatically download it from an online repository and continue typesetting.

MiKTeX also comes with a utility that automates updating your installed style packages and program components. Choose Maintenance (Admin): Update (Admin) in your MiKTeX Start Menu folder, and let the wizard check the nearest TeX repository for available updates. I recommend you do this right after installing MiKTeX as new updates arrive quite frequently.

MiKTeX includes TeXworks, a straightforward TeX editor that’s preconfigured for use with MiKTeX. This editor is very simple, so eventually you’ll want to migrate to a more advanced program such as TeXstudio. However, I recommend that beginners stick with TeXworks for a while, due to its sheer simplicity and the fact that it works (almost) without configuration.

Choose XeLaTeX!

There’s just one configuration item you need to adjust. Start TeXworks, choose Edit: Preferences: Typesetting, and change the drop-down box Default to “XeLaTex+MakeIndex+BibTeX”. The original default value “pdfLaTeX…” is an obsolete engine, preselected for backward compability.

Unlike pdfLaTeX and similar older TeX engines, XeLaTex is internally built with Unicode text processing. This means you can type non-ASCII characters such as accented letters (äòû) or proper quotation marks (“”) directly into your LaTeX input files, encoded in UTF-8. There’s no need to use the cumbersome TeX workarounds (\"{a}\`{o}\^{u}``'') or input encoding translation packages.

Moreover, XeLaTeX offers built-in support for Windows font files in all common formats: Adobe Type 1, TrueType, and both OpenType variants. Using the fontspec package (see below) you can directly select Windows fonts by name, without any manual conversion or complicated declaration. On top of that, typographic niceties such as ligatures and real small caps are automatically supported for all fonts that offer these features.

XeLaTeX can import existing PDF documents as images using includegraphics, but note that importing multiple PDF images can bloat the resulting PDF output quite a bit. I use Adobe Acrobat’s File: Save As: Optimized PDF command to strip redundant data from XeLaTeX’s PDF output and achieve a more reasonable file size.

Where’s the Manual?

LaTeX tools and packages generally offer exceptionally good documentation, often better than Adobe’s FrameMaker manuals and far better than the useless non-documentation of the DITA Open Toolkit. The problem is finding the documentation. TeX packages do not usually create Start Menu shortcuts, with the exception of MiKTeX itself. However, the MiKTeX manual is really just a command reference for its specific TeX implementation, aimed at people already familiar with TeX systems. Most people will rarely need to consult it.

As mentioned above, your first LaTeX manual should be LaTeX: A Document Preparation System. Beyond that, you’ll need to know the features of any style packages you might be using. Their manuals are usually located somewhere within the doc subdirectory tree in your MiKTeX installation folder. Unfortunately, that tree is so big – currently 291 subfolders on my system! – that you’ll want to use a file search utility to find any given package. I advise against attempting a web search as you might end up with a documentation version that does not match your installed version. I’ll state the local documentation paths explicitly when I mention individual packages later on.

Using TeXstudio

TeXstudio is a more powerful LaTeX editor than TeXworks and also works well with MiKTeX. As of version 2.4 XeLaTeX is supported directly via Tools: Commands: XeLaTeX, but you’ll still need to change the default typesetting engine for Tools: Build & View. First, choose Options: Configure TeXstudio: Build and change Default Compiler from “PdfLaTeX” to “XeLaTeX”.

Unfortunately, as of version 2.7 this does not automatically modify any chain commands, so you need to adjust them manually. Check Show Advanced Options in the lower left corner, scroll down to PDF Chain in the updated list of Meta Commands, and manually change “txs:///pdflatex” to “txs:///xelatex”. (You can also use the Configure icon to the right but that’s slower!) Setting Build & View to “PDF Chain”, or “txs:///pdf-chain” in the advanced view, should now create PDF output via XeLaTeX.

Customization

This sections describes the LaTeX customizations and style packages I’m using. You can see the effects in my own PDF documents:

Most customizations are gathered and documented in the style file kynosarges.sty which is identical for both ZIP archives. The rest are found in the two main text files, StarChess.tex and TektosyneGuide.tex, respectively.

We’ll start with general customizations and tips that apply to all LaTeX documents, and then cover several additional style packages. User manuals for packages are indicated as file paths relative to your MiKTeX installation folder, e.g. C:\­Program Files (x86)\­MiKTeX 2.9\ for 32-bit MiKTeX on a 64-bit Windows system. Usually there is additional specialized documentation for each package in the same subdirectory.

General Customization

Always adjust the placement parameters for “floats”, i.e. figure and table environments that can “float” from their source location as required by the page layout. The default values are far too restrictive. Rob J Hyndman offers some good suggestions, although I’m a bit more aggressive in my own changes.

Never enter blank lines around stand-out environments such as itemize lists or $$ equations. You’ll get unwanted extra space before the environment, and an unwanted paragraph indentation after. If you want to leave blank lines in the source file for better readability, just put a comment sign (%) at the start.

The default tabular environment leaves too little vertical space between cell text and horizontal lines. This problem is not easily fixed – Adrian P. Robson gives an overview of available options. I’m using a brute force approach and define two new commands, cleartop and clearbtm, to manually insert more vertical space as required.

Consecutive paragraphs are indented by default – except within list environments, where item paragraphs are separated by vertical space. Again, this is not easily fixed without redefining these environments, so I’m defining another new command, paritems, that switches item paragraphs back to normal indentation.

Other simple customizations in kynosarges.sty include: altered itemize labels; increased paragraph indentation; additional vertical space between footnotes; and a handy callout command for bolded sans-serif text.

KOMA-Script & Memoir

LaTeX was a huge improvement over bare-bones TeX, but its functionality and (especially) flexibility is still rather limited. Aside from many smaller packages that address individual issues, there are two big all-in-one packages that have become quite popular.

  • KOMA-Script (German): doc\­latex\­koma-script\­scrguide.pdf
  • KOMA-Script (English): doc\­latex\­koma-script\­scrguien.pdf
  • Memoir: doc\­latex\­memoir\­memman.pdf

The respective merits of each package are subject to much debate, e.g. on Stack Exchange. Basically, Memoir attempts to be the only LaTeX package you need, integrating the functionality of many other packages. KOMA-Script provides less functionality by itself and instead attempts to be compatible with as many other packages as possible. I chose KOMA-Script because I found using additional packages a negligible encumbrance, especially given MiKTeX’s automatic download system.

Manuals — The Memoir manual takes pains to showcase a variety of the package’s finest typesetting whereas the KOMA-Script manual is formatted for screen reading… and frankly butt-ugly. Rest assured this is not representative of the capabilities of the KOMA-Script package, nor of the typographic understanding of its authors!

English speakers should also note that KOMA-Script is a German project whose documentation is excellent only in the original German. The awkward English translation is rather hard to read, and quite inferior to the English documentation for Memoir. This shouldn’t necessarily deter you since KOMA-Script is designed so that most customization is actually performed by additional packages, so you won’t need to consult the KOMA-Script manual itself all that often.

Features — One noteworthy KOMA-Script feature is its excellent page layout. It’s literally the first A4 layout I’ve ever seen in any publishing program that didn’t need manual adjustment. KOMA-Script also comes with a letter class that’s suitable for complex letterheads and window envelopes; see Letters with KOMA-Script for a sample customization.

You should also check out KOMA-Script’s new labeling environment. This is an improved description environment that lets you define separators between label and description, as well as an arbitrary indentation for all descriptions. Long labels can run past the indentation point, greatly simplifying list formatting for labels with a highly variable length.

Customization — The file kynosarges.sty contains a number of small KOMA-Script customizations: caption and labeling labels use the same bolded sans-serif font that KOMA-Script uses for all titles; footnotes are set with normal-sized numbers and greater indentation; and periods appear after chapter numbers but not after any other table-of-contents numbers.

KOMA-Script Versioning

As of May 2014, we have another case of collaboration between different open source teams breaking down. This time the KOMA-Script maintainer declared that new releases via CTAN are “a lot of work and resulted several times in annoying discussions.” So if you update your MiKTeX installation and then try to build a KOMA-Script document, you’re bound to get mysterious error messages because the available KOMA-Script is out of sync with other required packages.

To fix this, you should first remove KOMA-Script using the MiKTeX package manager, then visit the current KOMA-Script release page. Read the instructions under “Using Windows installation packages for MiKTeX” and grab the most recent executable package from the linked repository. Then execute it, hopefully putting it in a more sensible location than the default (My) Documents. The package should register itself with MiKTex, and the next document build should work.

Should the self-registration of KOMA-Script fail you’ll have to register the package manually. This was the case for me with KOMA-Script 2430 on Windows 10. Open MiKTeX Settings, switch to tab Roots, and add the directory where you installed KOMA-Script if it’s not already visible.

Title Pages & moresize

Some Examples of Title Pages (PDF) by Memoir author Peter Wilson offers an excellent selection of attractive designs, a few of which also appear in the Memoir manual. Fortunately, there’s nothing specific to Memoir about these designs, so you can basically copy the desired text fragment directly into your LaTeX document. The titles of my documents were created in this way.

There’s just one catch. Some title pages use a font size bigger than Huge, and you might get incorrect Huge sizes in 12 point mode. To fix this, you need the moresize package (doc\­latex\­moresize\­moresize.pdf) which has two basic functions:

  • Add two new size steps to LaTeX font selection, namely HUGE and ssmall.
  • Fix the size of the existing Huge step in 12 point mode, which is too small by default to accommodate obsolete Metafont limitations. Some other font sizes are also corrected.

I’m using this package because I find the increased Huge size very pleasant for title pages and chapter titles on A4 paper in 12 point mode.

Other Style Packages

We’ll finish with a rundown of other style packages I’m using, including brief notes on their purpose and any applicable customizations.

  • babel (doc\­generic\­babel\­babel.pdf) — standard multilingual support package. Specifies the primary document language.
  • fancyvrb (doc\­latex\­fancyvrb\­fancyvrb.pdf) — improved verbatim environments. Requires support code to remove extraneous vertical space around the environments, see kynosarges.sty.
  • fontspec (doc\­latex\­fontspec\­fontspec.pdf) — improved OpenType font support. Loaded implicitly by mathspec (see below).
  • hyperref (doc\­latex\­hyperref\­manual.pdf) — improved cross-references with PDF hyperlink generation. Customized to show all PDF hyperlinks in unobtrusive blue without distracting rectangles, and to set PDF document metadata (author etc.).
  • mathspec (doc\­xelatex\­mathspec\­mathspec.pdf) — adds support for mathematical typesetting to fontspec. Customized to load Minion Pro, Myriad Pro, and Consolas. Contrary to usual practice, I don’t shrink Myriad and Consolas to match Minion. Myriad is for titles and other stand-out text which benefit from a larger size, and I already squash Consolas horizontally to take up 20% less space.
  • scrpage2 — improved support for headers & footers. Ships with KOMA-Script and is described in its manual (see above).
  • titlesec (doc\­latex\­titlesec\­titlesec.pdf) — improved chapter & section titles. One of the sample designs for chapter titles is adopted in kynosarges.sty.

Letters with KOMA-Script

KOMA-Script comes with a fairly powerful letter class, scrlttr2, that offers a broad variety of predefined variables and layout positions for window envelopes. Sadly, unlike KOMA-Script’s default layout for normal documents, the default letter layout is rather ugly. The recipient address field is too close to the edges of the envelope window and shifted left relative to the body text, and the sender address is rather lamely set in a single column.

Moreover, unlike most other LaTeX classes I found very few sample customizations for scrlttr2 on the Internet, and none quite as I wanted them. So here’s my own customization, suitable for DIN/ISO A4 pages and matching window envelopes.

  • KomaLetterSample.zip contains three files: kynosarges-DIN.lco customizes lengths & positions, kynosarges-letter.sty builds the custom letter format, and Letter.tex contains enough text for two pages to show off the new format.
  • KomaLetterSample.pdf shows the resulting output.

Some notes on customizing the source files in the ZIP package:

  • kynosarges-DIN.lco — If you want to customize a page format other than A4 you’ll need to change the \LoadLetterOption command to a different base .lco file, and adjust the customized values to match that file.
  • kynosarges-letter.sty — Change the variables to your own name, address, telephone number, etc. I’m using German labels and formats here because that’s what I’m most familiar with.
  • Letter.tex — Copy this file for each new letter and change the variables to the current location, date, and recipient.

The style file also contains various customizations that I copied from my general style file described above, such as increased indentation. Keep or remove them as you like. Please see the KOMA-Script manual for more information on the available options and variables.