# 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, MacOS, and Linux (all 64-bit only). The 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 can automatically download it from an online repository and continue typesetting.

MiKTeX also comes with MiKTeX Console, a utility to manage and update your installed style packages and program components. Choose Updates: Check for Updates 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”. This box defaults to “pdfLaTeX…” for backward compatibility, but today pdfLaTeX has been essentially obsoleted by XeLaTeX.

Unlike pdfLaTeX and similar older (La)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 also import existing PDF documents as images using `includegraphics`. This used to bloat the resulting PDF output quite a bit, but the current version achieves the same file size as Adobe Acrobat’s File: Save As: Optimized PDF command.

### 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 109 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\­MiKTeX 2.9\`. Usually there is additional specialized documentation for each package in the same subdirectory.

Note: With a system-wide installation, only style packages that ship with MiKTeX or were explicitly installed using MiKTeX Console are placed under the MiKTeX installation path. Any packages that were automatically downloaded on request during typesetting are instead placed under `C:\­Users\­UserName\­AppData\­Roaming\­MiKTeX\­2.9\`

### 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. 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!

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.

### 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).
• graphicx (`doc\­latex\­graphics\­graphicx.pdf`) — additional optional arguments for the `\includegraphics` command.
• 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.