For my research, spreadsheets are very useful for recording data and analysis. But I usually want to use that data in a .tex document as well.

Calc2LaTeX

Calc2LaTeX

Writing tables using LaTeX can be difficult if you have a lot of data, and editing it can be a bit of a nightmare.

One quick solution I have found is using a macro that converts a table in a spreadsheet into a LaTeX table. (A macro is a set of instructions that automate a particular task.)

An alternative to using macros is working with a spreadsheet program that supports the LaTeX file format.

Of the following three options, I have tried Calc2LaTeX. I’ve found it very easy to install and use.

Calc2LaTeX

This macro works for OpenOffice Calc. After running the macro, a dialogue box appears containing the LaTeX code. You can copy that and paste it straight into your .tex file.

Excel2LaTeX

This macro works for Microsoft Excel.

Gnumeric

This is a spreadsheet program that can be used with Windows and Linux. It is possible to save a file in a number of formats including LaTeX.

\missingfigure{}

\missingfigure{}

This is a package I recently stumbled upon. It allows you to easily insert notes into a document – either inline or in the margins.

It can also create a list of to-do notes, which would be helpful when editing drafts.

I particularly like the \missingfigure{} command. This inserts a bright, bold image into your text – so you won’t forget to add the final figure to your document.

The other commands are \todo{} and \listoftodos. You can customize the colour, font size and placement of each note.

\todo{Some note or other.}

\todo{Some note or other.}

For my example document, these are the commands I included:

\listoftodos

\todo{Some note or other.}

\todo[noline]{Another note.}

\todo[inline]{And another one.}

\missingfigure{Add my picture here.}

Here is the code for my sample document: SimpleToDoNotesTex.pdf

Here is the output PDF of the document: SimpleToDoNotes.pdf

This is a new package, so there may still be some glitches with it – but I think it’s useful for editing and writing up long documents.

The todonotes package was created by Henrik Skov Midtiby.

Useful Links

It’s easy and convenient to use just one .tex file when writing short documents. But for anything larger than, say, 10,000 words, I tend to divide the document into smaller parts so each chapter is its own .tex file.

For example, you might be writing a thesis that includes three chapters (introduction, results, conclusion) and an appendix. These are called introduction.tex, results.tex, conclusion.tex and appendix.tex.

These four files are like any other .tex file except you omit the preamble (\documentclass, \usepackage, etc.) and the \begin{document} and \end{document} commands. The reason you don’t include these commands is that they are included in your main file, thesis.tex, ensuring that your formatting is consistent throughout the final output document. This also means that page numbers and footnotes will be numbered correctly all the way through.

Which Commands to Use

There are two commands you can use in your main file, thesis.tex, to insert your four chapter files: \include and \input.

The \input command slots each chapter in straight after the one before it without any pagebreaks, while \include works by starting each new chapter on a new page and ends it with a clearpage command. (Thanks to the latex-community forum for help on explaining this to me!)

In other words, ‘natural candidates for \include are whole chapters of a book but not necessarily small fractions of text,’ for which \input would be more appropriate. (Quotation from The LaTeX Companion.)

Your thesis.tex file would therefore look something like this:

\documentclass{article}
\usepackage{semtrans}

\begin{document}

\title{My Thesis}
\author{John E. Smith}
\maketitle
\clearpage

\include{introduction}
\include{results}
\include{conclusion}
\include{appendix}

\end{document}

Note: your four files (introduction.tex, results.tex, conclusion.tex and appendix.tex) must be saved in the same folder as thesis.tex, otherwise it won’t work.

Omitting Files

If you wanted to produce a PDF from the file thesis.tex without the appendix, all you have to do is comment out that particular \include command (you just add a % at the beginning of the line): %\include{appendix}

Useful Links

Students and staff at the University of Cambridge may be interested in the following courses on offer this term:

  • 10-11 February LaTeX: Introduction
  • 13 February LaTeX Follow-up Practical Using TeXshop on a Macintosh

See http://www.cam.ac.uk/cs/courses/timetable.html for course descriptions and booking information.

Eligibility: The standard programme of short courses run by the Computing Service is aimed at the staff and students of Cambridge University. Others may also be eligible to attend if from certain related institutions. For details see: http://www.cam.ac.uk/cs/courses/genreg.html#charging

I would encourage readers of this blog to submit information about other LaTeX courses being run near you. You can do this by adding a comment to this post.

A great deal of academic writing is convoluted and dull (well, at least what I’ve been reading), and the American trend of using ungrammatical jargon to dress up second-rate thinking is sadly spreading to the UK.

But it doesn’t have to be that way – Nabokov’s scientific writings on butterflies have a lyrical quality, while Russell’s works on philosophy are clear and concise.

I have found George Orwell’s rules of writing to be very helpful:

  1. Never use a metaphor, simile, or other figure of speech which you are used to seeing in print.
  2. Never us a long word where a short one will do.
  3. If it is possible to cut a word out, always cut it out.
  4. Never use the passive where you can use the active.
  5. Never use a foreign phrase, a scientific word, or a jargon word if you can think of an everyday English equivalent.
  6. Break any of these rules sooner than say anything outright barbarous.

From Politics and the English Language (1946) – http://www.k-1.com/Orwell/index.cgi/work/essays/language.html

Bertrand Russell also wrote a short essay entitled How I Write (1954) – http://www.davemckay.co.uk/philosophy/russell/russell.php?name=how.i.write

Useful Links

Using fancyhdr

Using fancyhdr

This package allows you to customize headers and footers in the LaTeX document.

You can find comprehensive information on this package in The LaTeX Companion.

Here I’ll explain how to make a simple header showing your name and the date.

This is what you need to include:

\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancyplain}

\begin{document}

\lhead{John E. Smith}
\rhead{\today}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque ut ante pulvinar mauris interdum euismod. Aliquam dui tellus, blandit at, tincidunt ac, feugiat id, nibh.

Simple Header

Simple Header

Phasellus id metus. Aliquam erat volutpat. Donec fringilla. Donec euismod, velit quis adipiscing hendrerit, enim eros tempor mi, a hendrerit ipsum eros eget leo.

\end{document}

Here is the output PDF of the document: SimpleFancyhdr.pdf

The fancyhdr package was created by Piet van Oostrum.

Useful Links

Step-by-Step Guide

Basic LaTeX Document

Basic LaTeX Document

Here are some easy instructions for creating your first LaTeX document.

1. Opening a New Document

Open TeXnicCenter and click on File > New. This will load a blank document. Select File > Save As and give your file a suitable name. I will use ‘test’.

You’ll see that this file is a .tex file (test.tex). The TEX file is the one you use to write and edit your document.

2. Preamble

Document Class

Before you can start writing, you need to specify exactly what type of document you want to create. This is done in the preamble.

LaTeX supports several different document types, such as article, report, book, beamer, etc. These are called document classes.

All LaTeX commands begin with a backslash ‘\‘ and are followed by special characters or letters. So to specify your type of document, the command is:

\documentclass[options]{class}

See section 1.4 of The Not So Short Introduction to LaTeX for basic information and section 1.6.1 for detailed information about all the options.

Packages

As I’ve mentioned in a previous post, add-on features for the LaTeX system are known as packages. If, for example, you want to use the semtrans package to display special transliteration characters in your document, you need to state that in the preamble.

The general command for specifying the package you want to use is:

\usepackage[options]{package}

Sometimes, there won’t be any options to specify (like with semtrans). You can also include a whole list of packages you want to use in the preamble, but you have to use a new command each time. For example:

\documentclass{report}
\usepackage{babel}
\usepackage{url}

3. Body Text

Now to begin the text you want to write, you start with the command:

\begin{document}

and end with the command:

\end{document}

This \end{document} command should be the very last thing in your document.  Anything that comes after it will be ignored by LaTeX.

4. Example Document

You are now ready to write your first document. Type the following into your test.tex file in TeXnicCenter (I have specified an article of 10pt type on A4 paper):

\documentclass[10pt,a4paper]{article}

\begin{document}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque ut ante pulvinar mauris interdum euismod. Aliquam dui tellus, blandit at, tincidunt ac, feugiat id, nibh.

Phasellus id metus. Aliquam erat volutpat. Donec fringilla. Donec euismod, velit quis adipiscing hendrerit, enim eros tempor mi, a hendrerit ipsum eros eget leo.
\end{document}

Save the document. Note that to start a new paragraph, you just need to leave an empty line in the text.

5. Generating a PDF

LaTeX => PDF

LaTeX => PDF

Step 1: On the toolbar, you’ll see a drop-down option. Select LaTeX => PDF. See the picture on the right.

Step 2: Click on Build > Current File > Build. The shortcut is ctrl+F7 and there is also an icon on the toolbar.

You’ll see the document compiling if you have the output bar open. If not, click on View > Output Bar. If there are any errors in your document, you will see them listed in the output bar.

Step 3: To view your PDF, click on Build > View Output. The shortcut is F5 and there is also an icon on the toolbar.

If you want to combine steps 2 and 3, you can just click on Build > Build and View. The shortcut is ctrl+shift+F5 and there is an icon on the toolbar.

N.B. If you add more text to your document, save it, and want to generate the PDF again, you must close the test.pdf file first. Otherwise it won’t work.

An alternative to using PDFs is viewing your output as a DVI file. To do this, start at step 1 again, but select LaTeX => DVI, then steps 2 and 3 are the same.

The advantage of using a DVI file during the draft stage is that you don’t have to keep closing it before generating a new version again.

test.pdf

test.pdf

Here is the output PDF of the document: test.pdf

6. A Note on File Types

If you now have a look at the folder where you saved test.tex, you’ll see test.pdf there as well.

But there are a whole lot of other files too, such as:

test.aux
test.bbl
test.blg
test.log

Just ignore these.

If you want to edit your text, click on the TEX file, test.tex. If you want to re-open the PDF or DVI files, click on test.pdf or test.dvi.

Useful Links

The Comprehensive LaTeX Symbol List

If you find yourself wondering how to create your chosen transliteration style and can’t find the right character input, this will make happy reading:

The Comprehensive LaTeX Symbol List by Scott Pakin (4.3Mb PDF)

Common Transliteration Symbols in LaTeX

PDF Preview

PDF Preview

At 152 pages, the comprehensive symbol list is a bit unwieldy.

As a quick reference, I’ve made a one-page table of the most commonly used transliteration symbols for dealing with French, German, Spanish and transliterated Arabic – along with some examples.

You can download it from here:

Common Transliteration Symbols in LaTeX (61Kb PDF)

Semtrans Package

For people working with Semitic languages, the Semtrans package can be useful.

I found this after weeks searching for how to represent the Arabic letter kha’ in the style commonly used in German scholarship (a letter ‘h’ with a little u underneath). You get this by typing \U{h}. See page 14 of the comprehensive symbol list. `Ayn is \Ayn.

N.B. When using the command \U{h} in a section heading, you need to add \protect beforehand, so the command becomes \protect\U{h}. Otherwise, you will get error messages and the symbol won’t display. Thanks to Berteun for this tip. I haven’t found any difficulties with the \Ayn command.

For people who already use LaTeX, I’ll be discussing some LaTeX packages relevant to the humanities (particularly to Middle Eastern Studies).  Hopefully this will save you trawling the internet for information.

These posts will be interspersed between more basic information that I’ve categorized ‘Getting Started’.

For newcomers to LaTeX, add-on features for the system are known as packages. For example, multicol allows you to use multiple columns in a document, while the url package lets you properly format links.

This is the program you will use to write your LaTeX files and to generate a final PDF output. The reasons for using an editor include:

  • it helps manage the file generation process – there are short-cuts to the most common commands, such as generating a PDF file
  • there are short-cuts to formatting controls
  • it has syntax highlighting
  • there are good text navigation features

For Windows, I recommend TeXnicCenter. See http://www.toolscenter.org/.

TeXnicCenter Screenshot

TeXnicCenter Screenshot

Another alternative is WinEdt. This can be downloaded and used free for a trial period of 31 days. Thereafter you have to buy it – currently $40 for educational use. See http://www.winedt.com/.

WinEdt Screenshot

WinEdt Screenshot

For Linux there is Kile. See http://kile.sourceforge.net/ for screenshots.

These are just the programs I’m familiar with – there are lots of other editors out there. And for the minimalist approach you can just use Notepad and generate a PDF from the command line…

Important Features

Here are some things to bear in mind when choosing an editor:

Can you do a word count? TeXnicCenter doesn’t have one, so I use a free PDF wordcount called Translator’s Abacus. (Beware of a program called LaTeX Word Counter – it doesn’t seem to count footnotes.)

Is there a spell-check? TeXnicCenter automatically has one for US English and German, but you can add more languages:

  • Download the dictionary you want from http://lingucomponent.openoffice.org/download_dictionary.html – it’s a .zip file (TeXnicCenter uses the spelling engine of OpenOffice).
  • Unzip the .zip file and copy the .aff and .dic files in it to C:\Program Files\TeXnicCenter\language (you’ll see the English and German files already there).
  • Restart TeXnicCenter. Select ‘Tools’ then ‘Options’. Click on the ‘Spelling’ tab and select the new dictionary you want to add.