Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
% This is a working example to demonstrate use of switches to maintain multiple
% versions of a single document
% Uses the IEEEtran class:
% Created 2016-10-30 by Adam Noel
% Define the switch here using "newif" and start its name with "if"
% Here, NAME_OF_SWITCH == "OneCol"
% By default, a switch is "false". Use \NAME_OF_SWITCHtrue to set to true
% Uncomment the line below to set the switch to "true"
% One column version
% Two column version
\fi % end if
\usepackage{lipsum} % Dummy text
% correct bad hyphenation here
\hyphenation{op-tical net-works semi-conduc-tor}
\title{A Sample Document with \\Multiple Versions in One \LaTeX~File}
\author{Adam Noel}
% Here's a command for a figure. We use a command
% because we want to set different options for placement and width,
% depending on whether we are compiling the 1- or 2-column version
\caption{Here's a figure. We use a command to define it, which lets us change its location in the two versions. We set its width to a fraction of the line width, so that it's size is comparable in both the single and double column versions. In single column, we place the figure where it is defined. In double column, we anchor it to the top of the page.}
This is a simple document showing how to use a switch to create multiple versions of a document with a single \LaTeX file. In this example, there is a switch \emph{OneCol} in the source file. Comment out the line ``\textbackslash OneColTrue'' to compile a double column version. Uncomment that line for single column. Throughout the source file, you will find if statements that show the differences between the two versions.
% Switch for some text. Generally not needed for formatting a document whose text doesn't change.
\textbf{This version is single column.}
\textbf{This version is double column.}
\section{A Mathematical Example}
Here's an equation that is too long to fit on one line in the double column version but will fit on one line in the single column version. The source file writes out these two versions separately, so if you need to make changes don't forget to change both!
X = A + B + C + D + E + F + G + H + I + J + K + L + M + N + O + P.
X = &\; A + B + C + D + E + F + G + H + I \nonumber \\
& + J + K + L + M + N + O + P.
Eq.~\ref{my_eqn} might give you warnings for repeated label usage, because the same label is written twice in the source file. However, only one label is used at compile-time (depending on the switch value), so there are no referencing issues.
\section{Garbage Filler Text to Make Fig.~\ref{my_fig} Anchor Somewhere Meaningful}
Skip to Section~\ref{sec_fig}.
\section{A Figure Example}
Let's say we want to place a figure. We use a command to place Fig.~\ref{my_fig} so that we can modify the figure in one location but vary the placements options in the two versions. In the double column version, we anchor the figure to the top of the page with a width equal to \textbackslash linewidth. In the single column version, we place the figure after this paragraph with a width that is 55\% of \textbackslash linewidth.
\figOne{h}{0.4} % Anchor 1-column version here
\figOne{!t}{1} % Anchor 2-column version to top of page
% that's all folks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment