## Friday, November 4, 2011

### XeLaTeX for Indian and Analytic Philosophy

Recently I have begun to use XeLaTeX to compose and typeset my papers, handouts, and presentations. I've benefited from a presentation to the grad students here at UT Austin by Josh Dever, and some personal correspondence with Dominik Wujastyk. Because I had some difficulty getting started, I thought I'd write up a blog post explaining what I've learned for others in a similar position.

Prior to XeLaTeX, I used Scrivener and LibreOffice for composing documents. I still use Scrivener for note-taking, but I'm moving away from LibreOffice. Scrivener has the added advantage of a function which exports to LaTeX. I've begun to use Zotero for keeping track of my bibliography. I use Mac OS X (Version 10.6.8).

My main desiderata in a typesetting program include:
• Ability to easily include Devanāgarī and diacritical marks
• Incorporation of Zotero for bibliography and footnotes
• Formal notation and lexical trees
About a year ago, when I began writing my prospectus, I tried to learn LaTeX, but I was focused on exporting from Scrivener to LaTeX and ran into some technical problems. I decided it was a time-waster rather than a time-saver, at least then. Now that I'm in the beginning dissertation stages, I want to start with a program and stick with it, rather than expend a lot of energy transforming a large document (or several documents) into another format. Further, UT Austin has a package for LaTeX which will allow me to make sure my final dissertation is in the right format (it's a little outdated as of this writing, but is at least a start).

There are a glut of resources on the Internet about using LaTeX. Mathematicians, logicians, and linguists in particular have written extensive help guides. The sheer number of places to go to help is part of what was daunting in beginning, so I've written this guide in part as a way for me to organize what I've found for myself.

What is LaTeX?
LaTeX is a markup language that allows you to make stylistic changes at a global level, rather than going through your entire document and changing things like margins, italics, and so on. It relies on the user loading certain packages that drive the way your document looks and the kinds of formatting choices you can make (like bullet point lists, syntax trees, mathematical symbols, and etc.) I'm not going to weigh in on who should use LaTeX, since a lot has already been written on that. Charlie Tanksley has a guide for philosophers which covers some of this territory.

LaTeX and XeLaTeX differ mostly in their ability to accept Unicode. XeLaTeX relies on some different packages (fontspec, for instance) and commands, but since it seems like it is becoming the standard for scholars working with Devanagari, I've decided to use it rather than LaTeX.

What does this choice amount to? Well, not too much, practically.

Installation. The way to get either LaTeX or XeLaTeX for Mac is to download MacTeX. This will give you everything you need to create and compile documents using XeLaTeX. Installation is simple, and once you have the distribution on your machine, you just need to choose how you'll create your documents.

I use TexWorks, but there is also TexShop included. The basic idea for either one is that they're a way for you to enter your document, apply formatting, citations, and so on, and then compile it so you can see what the resulting PDF will look like. I say "compile" because once you're essentially writing code (although it's not too complicated once you get started), and then running that through a program that turns it into a document (or a bibliography, which comes later).

Getting started is not too difficult in TexWorks. You can choose the "New From Template" command, and then select "article-fontspec.tex" to get a nice blank document. One very important thing you need to do if you are going to use XeLaTeX is to choose "XeLaTeX" in the drop-down box at the top left to make sure you're compiling with this engine.

You can also go to Preferences > Typesetting and then make sure XeLaTeX is selected as your default:

The new, blank document will start with something like:
\documentclass{article}
and then it will proceed through a series of commands like
\usepackage{fontspec} % standard for XeLaTeX
\usepackage{polyglossia} % allows for multiple languages
\usepackage{xltxtra} % standard for XeLaTeX
I make it a practice to include next to the package a comment to explain what the package is for, using the percent symbol (%) to tell the compiler that my comment is a note, and not a command. The nice thing about TexWorks is it will automatically color code, like I've shown, so you can distinguish between package calls, comments, and document commands.

The document itself is set off by the instruction to begin and end it:
\begin{document}
\end{document}
Everything you want to create goes in between these commands. Information about the document goes before the \begin{document} command. To figure out how to setup a document that would let me write in Devanagari, I emailed Dominik Wujastyk and he suggested a simple setup:
\documentclass{article}
\usepackage{polyglossia}
\setmainfont[Script=Devanagari]{Nakula}
\begin{document}
Your Devanāgarī looks like this: आसीद्राजा नलो नाम and your romanized stuff looks like this: āsīd rājā nalo nāma.
\end{document}
I haven't gone through all of the entries tagged "TeX" at Dominik Wujastyk's blog (Cikitsā entries on TeX) but it looks like there is also a nice way to switch between Devanāgarī and Roman having only entered Romanized script into XeLaTeX.

The biggest problems I've encountered so far are:
• Making sure all the packages and settings "play nice" together. It seems like loading some packages interferes with others and cause compilation errors, and so I've learned to only install one new one at a time. I will often remove them not by deleting the line, but by entering the "%" symbol temporarily. Compiling in TexWorks is quick (CMD + T) and you can command-click on a line in the PDF document and see what line of code generated it, and vice versa.
• Making a bibliography with Zotero. Zotero lets me export my bibliography into a *.bib database format, which is how TeX works with it. Then there are two options for creating a bibliography:
• Manually enter the bibliography and refer to it in the body of the document with the \cite{} command.
• Generate a bibliography through the BibTeX compiler as a stand-alone document.
• I've looked at some detailed discussion of the process, and although I've been able to create the in-document bibliography by using the \begin{thebibliography}{1} \bibitem{label} commands (where "label" is a name you use to refer to the bib entry in the document), I have not been able to create a stand-alone document. At the step where I compile my document using BibTeX, I get only a blank document. This is despite using the \cite{} command in the body of the document, which should form the basis for generating \bibitem entries in the bibliography. I think this has something to do with XeLaTeX.
• Learning packages on the fly. There's a learning curve involved with things like creating tables (still haven't mastered them, even though I used to make HTML tables quite easily years ago) and figuring out which packages are needed to allow which mathematical symbols. I'm doing quite a lot of Googling and scouring help forums. As I find useful sites, I bookmark them. Eventually I will probably have a page devoted to such guides.

#### 1 comment:

1. Hear, hear! XeLaTeX makes everything a bit better!