Sunday, May 12, 2013

Conlanging with LaTeX, Part Two

In the previous post I suggested a basic LaTeX tutorial you might use to get a basic command of LaTeX. I'm going to assume everyone reading this has played around a little with LaTeX.

Before you can produce any document in LaTeX, you need to tell it a little about what you intend. The very simplest trussing for this will look a lot like this:

\documentclass{article}

\begin{document}
Saluton!
\end{document}

The space between the \documentclass and \begin{document} lines is called the preamble, and this is were you can put all sorts of other declarations to change how LaTeX works, either by changing its default behavior or by adding new functionality. For this post, I'm going to mention a few things that are useful for conlangers to have in their preambles. Specifically, I'm going to focus on what LaTeX calls packages. Fortunately, if you do a web search on most LaTeX packages you can get good documentation on how to use them effectively.

The first thing you should know, is that the font size can be changed in the \documentclass line. I usually like a 12pt font, but you can also ask for 10 or 11 points. As always, you need to use other packages to get more font size options.

\documentclass[12pt]{article}

By default, LaTeX has rather large margins. I have no need for so much whitespace, so I use the fullpage package to pull out the margins to something less wasteful of paper:

\documentclass{article}
\usepackage{fullpage}

\begin{document}
Saluton!
\end{document}

And that's all you need to say. Simply by using the package, the changes you want take effect.

The next big thing is a package to manage fonts. In the old days, dealing with fonts in LaTeX was truly a nightmare — strange font names, freaky encodings, fonts themselves in a special LaTeX format, fights between different packages and font expectations, etc. These days, the XeTeX version of LaTeX has much simpler font management capabilities, though you still have to do a little work.

For XeTeX to find a TrueType or OpenType font, it needs to be installed in the usual places your OS would put the font, since it relies on local mechanisms to find them.

There is a utility package that helps manage all this, fontspec:

\documentclass{article}
\usepackage{fullpage}

\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text}
\setromanfont{Gentium Basic}
\newfontfamily\gplus{Gentium Plus}

\begin{document}
Saluton!
\end{document}

So, what I'm doing here is loading up the package, then immediately running some commands provided by that package to set some font defaults. The \defaultfontfeatures line tells XeTeX I want to use the normal, old-fashioned LaTeX digraphs and trigraphs for certain kinds of characters. For example, it will convert three consecutive minus signs into an em-dash (—), in the usual LaTeX way. If you omit this line, many examples of LaTeX you might find on the web may break in subtle ways for you.

The next line, \setromanfont picks the default font for the document. I like the Gentium family, since it has lots of accenting support, as well as Ancient Greek, which I often find myself using.

The next line lets me create a font command. It turns out, the Gentium Plus font has much better support for IPA characters, so when I want to type IPA, I can use the \gplus command to get the IPA. Note that you have to enclose the commands created that way in curly-braces to limit their effect. An example from my Kahtsaai grammar:

 \item Double \LL{ł}, \LL{łł}, is 
    pronounced [{\gplus ɮ}:]. 

So, the \newfontfamily command needs a command name, which you choose, and then a font name. Here, I picked the name \gplus (the leading backslash is required for all LaTeX command names).

The fontspec package is vast and powerful, allowing many interesting effects. You can look at the documentation to learn about more of its capabilities. I will just add that it is common for LaTeX documentation to have a large section at the end with the actual package code, with explanations. Most of the time, that is safely skipped.

I like to use different sorts of underlining in examples, for which the package ulem is very useful. Just use \usepackage{ulem}, and then you get some new LaTeX commands:

\uline{Just a normal underline.}
\uuline{A double underline}.
\uwave{A wavy underline}.

Some people will want to use the tipa package, which provides a funky encoding for IPA. I don't use it these days, since I don't always like the look of the output.

These are the most basic packages I use. There are a few more, but they are complex enough, or add such large new functionality, that I will save them for future posts.

Do experienced LaTeX-er conlangers have other basic packages to recommend, other than things like multicol, makeidx, multicol or hyperref, which I hope to talk about more in the future?

In the next post, I will talk a bit about defining your own simple macros to ease some formatting tasks, and tables tables tables...