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:
- 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.
- 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:
- Use newif to create the switch. Syntax is “newififMY_VAR”. By default, it will be false.
- Add the line “MY_VARtrue” to make the switch true.
- 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: