LaTeX tips

From QERM Wiki
Jump to: navigation, search
LaTeX logo huge.png

This will be a repository of tips for using LaTeX. To add a tip, just create a link below, for example: Separating the Red Sea and save the page. The link will be red. Just click on the red link and you will automatically be editing the page. Nothing like a blank canvas to share your hard-gleaned wisdom!


Recommendations for downloads

  • Best Windows LaTeX compiler Miktex
  • Best Windows editor TeXnicCenter
  • Best Mac editor TeXShop
  • Best Mac compiler MacTeX
  • A Linux Integrated LaTeX Enivronment Kile
  • For any Linux/Unix system, simply use your favourite Unix editor to type the mylatex.tex file. Here is a basic list of Unix commands. To check your spellings, you can say

ispell mylatex.tex (.tex extension may be omitted) A better program for spell-checking on linux is Aspell. Replace ispell above with aspell .

Emacs also provides a great environment for LaTeX. While using Emacs, install AucTeX for best results.

  • Using (La)TeX with Gmail GmailTeX. Remember to use the F8 key to compose/read received messages and change the text formatting from "Rich Text" to "Plain Text" while composing messages.

General setup

  • Compiling the LaTeX using pdfTeX allows the creation of pdf files as the final product and the inclusion of graphics created as pdf files from some other source. For many people this is more convenient than using postscript files which may be the default for LaTeX compilers and editors. pdfTeX works nicely with images produced as pdf files (see R/General Information on Plotting).

Homework Document Class

Some QERMies have been using a special document class developed by Gregor's friend from HMC for TeXing homework assignments. Check out an example here, and if you're interested see the TeX code and of course download the hmpcset document class.

Bibliography Management

Typically we have a .bib file in the same directory as the .tex file. At end of your file add the following commands

\bibliographystyle{plain} \bibliography{bibfile}

Then run latex myfile

on your tex file and bibtex myfile twice. Repeat latex and your file should have your references.

If you want to include references from your database that are not cited in the .tex file add \nocite{*} above the two lines.

For chapter by chapter references, add \usepackage{chapterbib} to your preamble. Presumably you have a root file with \include{} for each of your chapters. Then run latex on your root file, but run bibtex on each of your included files.

Sometimes you need to modify the bibliography style file, say to meet the formatting requirements for a journal. Here is a nice set of instructions.

Converting from other formats

There are a variety of tools for converting to LaTeX from other formats, many of which are described here. For equations, the only software that QERMunists have found to be truly great is GrindEQ's Word2LaTeX. Unfortunately, that one costs $129, but they have a "fully functional evaluation/download version", so as long as you fully embrace LaTeX after converting your files, then you could get by with just the free trial.

MathType (unfortunately no longer free!, $57 or 30-day trial that might be enough to move all the way to LaTeX), will nicely convert individual equations written in Equation Editor or MathType to LaTeX. Within MathType, use the menu for Preferences > Translators, and select "Translation to other language" and pick the default, "TeX -- LaTeX 2.09 and later". Now highlight any equation in the MathType window and paste into a text file. The pasted text should appear as text in LaTeX syntax.

Anyone have any success converting using Open Office, or even seeing MathType-produced equations in Open Office?

Converting to other formats

Converting to Word

Sometimes your adviser won't want to receive a PDF, wanting the convenient track-changes functionality in Word. The PDF to Word converter works pretty well, and is free to use online or you can download a 14-day trial. It converts your equations to images and, while the fonts may be different, the result accompanied by the original PDF should satisfy your adviser. Unfortunately, after the 14-day trial the full product is over $100, so I've moved to the official Adobe ExportPDF, which you can subscribe to for a year for $20... it seems to do a better job on text but messes up PDF figures in unpredictable ways.

I've also used Zamzar, an onine file converter where you upload your file, select the output you'd like, and give it your email address, and the site emails you a link to download your converted document. You can choose to convert a pdf to .doc, .docx, and many others. Figures within your pdf do not come through very well, but the equations usually do, and it's certainly a way to solicit edits and feedback from an advisor or collaborator who wants to use Word.


latex2rtf converts .tex documents to .rtf, which can be opened in Open Office or Word and saved as a .doc. Get it here (windows) or your favorite package manager (linux/mac). Usage is as simple as latex2rtf myfile where myfile has extension .tex and has already been compiled. There are switches to control how equations are handled (see the documentation for more details), and some examples are -M3 (convert both inline and displayed equations to RTF), -M12 (convert both inline and displayed equations to bitmaps), and -M32 (insert the raw latex equation delimited by <<: and :>>). If you choose to insert the raw latex equation and you have MathType, you can convert equations to MathType equations by cutting/pasting the latex into the MathType window, or with MathType 6.5 for windows, highlight the latex equation in Word and click the TeX toggle command on the toolbar. Latex2rtf supports bibliographies.

latex2rtf for dummies (aka eileen) on a Mac

  • If you know how to install things with Unix commands, you are not a dummy.
  • Otherwise, (and this doesn't necessarily mean you're a dummy), get a package installer (i-installer or FinkCommander); make your choice here.
  • Use these to find latex2rtf. i-installer was already on my computer, and filled in the blanks as far as many of the prerequisite packages. e.g. I think I needed ImageMagick and FreeType2 to start.
  • Also find and install package netpbm. I found this with FinkCommander, but not with i-installer. This will make more of your error messages disappear.
  • Next use Terminal, available already on your Mac. It's very similar to the windows command prompt. Type:
latex mypaper
bibtex mypaper # if you use bibtex
latex2rtf mypaper

These are the same commands as above, more details available here.

  • Terminal details I don't want to look up again and you may find helpful:
    • "pwd" returns current directory.
    • "cd /Users/yourname/YourFolder/" changes the current directory to the folder YourFolder on your hard drive.
    • "cd /Volumes/Cruzer/MyFolder/" changes the current directory to the folder MyFolder on a thumb drive that calls itself Cruzer.
    • To run latex2rtf on a .tex file, use the "cd" command to put yourself in the right directory, then follow the steps above.
    • Error messages will be shown in Terminal, and generally correspond either to programs or packages not installed, or to LaTeX functions not recognized. Check the documentation link above to see if your referenced function has any hope of being found by latex2rtf or if it will simply be ignored.
    • To find if there are hidden files on your computer, e.g. in /usr/local/bin/, which may be referenced by some of the source code, type "open -a finder /usr/local/bin/". I ran into a few error messages that led me to believe I was missing files either in this folder or in /usr/bin/. Use i-installer or FinkCommander to find any more necessary packages.
  • Finally, when you have run latex2rtf and you want to see the results, make sure to open your newly created .rtf file in Word. None of the bitmaps or rtf math conversions will show up if you let the default program (TextEdit on my computer) open the file.


GrindEQ LaTeX-to-Word is a windows-only product that converts .tex to .doc. It costs €49 but the evaluation version comes with 10 launches.

Adobe Acrobat Pro

Acrobat Pro will export .pdf files to Word. It does alright with the text portions, but the equation conversion is pretty awful. Unfortunately, some of the converted documents hang Word, YMMV.

Open Office

Open Office 3 can import .pdf files and then save them as Word files. Equations look OK, but seem to be a collection of images, rather than any editable equation format.

Compatibility with R

Sweave is a great way to embed R output in LaTeX. Pdf10.png Here is a GREAT example, and perhaps everything you need to start.

xtable is a nice R function (thanks EliG) to produce latex style tables in R

Useful Links

  • Great resource to get started and have questions answered: LaTeX WikiBook
  • A quick cheat sheet of all the things you forget. Cheat Sheet

Word Count

You can count words after compiling to pdf with the following command. More details here.

ps2ascii mydocument.pdf | wc -w

Additional Pages

Topics include:

Personal tools