latex tips and tricks

LaTeX takes some getting used to, but now that I’m used to it I (usually) love it.  Part of the initial difficulty lies in understanding the syntax and how it affects typesetting, which I won’t discuss in this post.  Some of that is better now in our department – they cover LaTeX somewhat in the new grad SIG.  Instead, I’ll focus on software issues.  For example, when I started off, I was typing my documents in a text editor and using a makefile to latex/bibtex commands.  I don’t even know if it had syntax highlighting.

The best LaTeX editor I could find is TeXShop (OS X only).  The interface is intuitive and simplifies many tasks.  Command-T will pass your document through latex and display the output in another window.  Ah, so simple.  There are a number of things that helped me work more efficiently with TeXShop and I’ll just use a list for that:

  • pdflatex – except in special cases, I suggest always using pdflatex rather than the old style of latex producing a dvi file which is then later rendered to postscript or pdf.  It’s faster and nicer.
    • image includes are different in pdflatex – it will handle almost anything except eps (encapsulated postscript).  In contrast, normal latex will only accept eps.  This tends to save time because converting to eps is a pain and can be buggy depending on the program you use.
  • command-click (aka Sync) – command-click on anywhere in the source file and it’ll highlight the corresponding part of the pdf.  Likewise, command-click in the pdf to find the respective place in the source file.  This can save a lot of time, but some caveats:
    • It doesn’t really work for section headers, tables, or other complex things when going pdf to source.  Mostly it works when you click on actual article text.  Captions sometimes work.
    • The syncing isn’t exact – it’s not built into the typesetter or anything.  Instead it seems to use string matching, so it can make mistakes.  Accuracy improves by picking unique sentences to click on.  (It seems you can set it up to use a newer better method nowadays though)
    • Because it seems to use text matching, it tends to be less accurate in longer documents.  I have no problems in short articles, but more frequent problems in my dissertation.
    • It works better when everything is in the same source file, but does a decent job with multiple source files.  It even sometimes will open the correct file for you if it’s not already open.
  • Tags dropdown – uses the sections/chapters/etc for navigation in the current file.  It’s really excellent to get used to.
  • Bibliography macro – in Macros::Applescript::Bibliography.  This runs latex once, then bibtex, then latex twice.  Basically it’s doing a full build.  I can’t believe I used to run bibtex through the typeset menu.
    • Caveat:  “Trash Aux Files” doesn’t remove the bbl file.
    • I can’t remember if there’s a default keybinding for this or not – I have it set to command-ctrl-shift-t.  Even with such a silly keybind, it saves me time
  • You can keybind anything in the menus via System Preferences::Keyboard::Keyboard Shortcuts::Application Shortcuts.  I have the itemize macro bound to command-3 and split window to command-4.  I’d like to improve on this and keybind a lot more things, and especially I want to re-map buttons on my Logitech mice to allow for easier binding.
  • custom macros – honestly I don’t understand the syntax well enough to make my own macros, but I poked around enough to get the boldface macro to work.  So I just select text, press command-b, and it puts a \textbf{} around it.  I’m sure you could do a lot with this.  Boldface helped me a lot because I needed to bold the maximum value in each row in several tables.
  • font embedding – I’ve since forgotten how, but it’s a one-time setup issue to make sure that pdflatex enbeds fonts
  • notes and reminders – I define a command like \rem{text} or \frem{text} to place a reminder in the file.  The second version does it as a footnote.  One of the nice touches you can make is to use color – reminders can be in red or blue or whatever.  It isn’t a substitute for a to-do list, but it helps you quickly spot things you forgot to do (such as add a citation).  You need to include the package color if I remember right.  Here are my reminder definitions:
    \newcommand{\rem}[1]{\noindent \textcolor{red}{\textbf{Reminder:} #1}}
    \newcommand{\frem}[1]{\footnote{ \textcolor{red}{\textbf{Reminder:} #1}}}
  • backups and version control – for a while, I used Subversion (SVN) for my papers.  But honestly, it’s a pain in the butt.  The repository was on a computer where I wasn’t allowed to have a home directory, so I couldn’t avoid the need to enter my password whenever I did anything.  Beyond that, the operations were slow (they obviously weren’t local).  More modern version control systems like Mercurial or Git address this by committing to a local repository and then updating other copies of the repository later on.  I’d recommend Git to anyone that can make a macro in TeXShop to commit (or hook commits into saving somehow).  The only pain is labeling the commits.
    • If you’re using a distributed version control system and you’re not co-editing the paper, you might not think to push your repository changes to a remote repository.  The problem is that you’re not insured in case of fire/theft/disk failure.
    • Lately I’ve been going with a more low-grade solution (Dropbox):  I make a symbolic link in my Dropbox folder to my paper folder.  Dropbox follows this link and automatically backs up anything in the directory tree to my Dropbox account (2gb limit for free accounts).  All of the syncing work happens in the background.  In addition, Dropbox does versioning for your files automatically, though the free account only keeps old versions for 30 days.
      • Caveat:  If you do a lot of work offline, Dropbox will sync when you’re next connected to the Internet.  But this means your connection might seem slow at first if you get in this habit.
  • deleting columns from a table – I found two ways to deal with this annoying problem.  The first way is to remove \\ \hline from your table, then load it as a csv file with a custom separator into Excel/Google Documents/etc, delete/reorder the columns, save as csv, then add the \\ \hline stuff again.  The second way is to use the Column Macros in TeXShop, which seem to mess up my \\ \hline anyway.  Either way you can clean it up quickly with a find/replace regular expression.
  • latexdiff – If you’re wondering what’s changed in a file, use this.  Note that you need before/after copies of your latex file and it has to be a flat file (i.e., write a script to flatten books/etc).  It will highlight the differences with color and show the removed text crossed out.
  • latex beamer is an environment to use latex to make presentations – it renders to pdf and you use acrobat or powerpoint to use it as a slideshow.  I’ve seen it used several times, but it varies.  I prefer a decent Keynote talk by far, but a poor latex beamer talk is usually better than a poor Keynote/Powerpoint talk.  One of the main drawbacks is themes – beamer presentations tend to look the same, though it’s gotten a bit better.
  • CTAN is a great place to find extra packages or document classes.  For example, I use the moderncv class for my CV and I really like the look.

I’ll try to lay off long brain dumps in the future.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s