Multiple LaTeX Document Versions Using Switches

LaTeX is great for typesetting equations and figures to look just the way you want. There are plenty of options for alignment and spacing. However, what if you regularly make major changes and need to keep multiple latex document versions? In this post, I’ll talk about how to do this using switches.

Why would you need multiple versions? For example, I often use the IEEEtran class for writing papers. If you are writing a journal manuscript, then usually there are two versions. The manuscript is reviewed in single-column format but published as double-column. Some IEEE journals even require that you submit both versions at the same time. Personally, I much prefer reading the double column version, so I regularly switch between single and double column while writing. This creates issues for proper equation alignment and sometimes figure placement (especially if the single column version is supposed to keep the figures at the end).

In the Beginning …

I had a couple of initial solutions to this problem:

  1. Assume double column everywhere. If you make all your equations fit in double column, then they will also fit in single column. Two potential problems: 1) paper length is often defined for the single column version, so you might be wasting space if you have a lot of math. 2) This method doesn’t help if the figure placement rules are different.
  2. Write two versions and comment out the one you’re not using. If you don’t have many differences between the two versions (e.g., only one really long equation), and you don’t need to change very often, then this might work for you. But this method gets frustrating if you often go back and forth.

Getting LaTeX Document Versions with Switches

I saved myself a lot of effort once I realized that LaTeX lets you create if/else statements with custom switches within your document (more generally, this is a TeX feature). Using a custom switch (or self defined conditional) makes it easy to maintain two (or more) LaTeX document versions. The general strategy is this:

  1. Use newif to create the switch. Syntax is “newififMY_VAR”. By default, it will be false.
  2. Add the line “MY_VARtrue” to make the switch true.
  3. Use the syntax “ifMY_VAR … else … fi” wherever you need to differentiate between the versions.

Here is a simple tex-file showing variations for single and double column versions of the same document (the image file in this example is here):

This document has single and double column versions, and shows examples of using text, an equation, and a figure differently for the two versions. Here are the compiled PDF files:

3 thoughts on “Multiple LaTeX Document Versions Using Switches

  1. Thanks, Adam. This makes life much simpler!

    BTW, why do journals ask for single-column format when they only publish the double-column one?

    Like

    1. I’m glad you found it helpful, Gautham!

      Single column format usually has more spacing between lines and larger margins. This makes it easier to read and mark in comments, which is very helpful for reviewers (especially if they print it!). Double column formats have much less space to fit in annotations because they fit more content on each page. So, single column is preferred for the review stage, but double column format is preferred for publication.

      Or at least this is what makes sense to me.

      Like

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s