TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using \iftoggle to switch between a for-review (doublespaced, onecolumn) and photo-ready (singlespaced, twocolumn) layout.

I want to change the width of figures to be optimal for both, depending on the toggle. I'd also like to do this without having two copies of all the markup for the figures.

Essentially, I want the equivalent of this in CPP:

#define DRAFT 1
#define FIGWIDTH 0.45\columnwidth
#define FIGWIDTH 0.9\columnwidth

... lots of complex figure/subfigure crap
... etc

What's the best way to do this?

share|improve this question
Welcome to TeX.sx! A tip: You can use backticks ` to mark your inline code as I did in my edit. – Joseph Wright Nov 15 '11 at 21:05
What is the name of your toggle? – Werner Nov 15 '11 at 21:05
@Werner - I just called it review. Why do you ask? – Mike McCracken Nov 15 '11 at 21:08
You could use something like \newtoggle{review} \newlength{\figwidth} \iftoggle{review}{\setlength{\figwidth}{0.45\columnwidth}}{\setlength{\figwidth}‌​{0.9\columnwidth}} and then use width=\figwidth in your \includegraphics key-value. That way, the length \figwidth is set according to your toggle, and used throughout your document consistently. All figures will be resized (made smaller/larger) this way though. – Werner Nov 15 '11 at 21:14
@Werner, that works great. Exactly what I needed. Thanks! I'm new to this site - should we edit my question or should you repost that comment as an 'answer'? – Mike McCracken Nov 15 '11 at 21:19
up vote 9 down vote accepted

The \iftoogle macro of etoolbox is expandable, so you could use it directly in the width argument as long both clauses expand to a length.

You could use:


Or use a macro for this:

% ...

Or if you want different factors for different figures:

% ...

or, more general:

% ...

Just keep the macro fully expandable, e.g. don't use an optional argument.

share|improve this answer

You can define a length that is toggle-specific using

\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\newtoggle{review} \newlength{\figwidth}
%\settoggle{review}{true}% In "review" mode
  {\setlength{\figwidth}{0.45\columnwidth}}% In "review" mode/true
  {\setlength{\figwidth}‌​{0.9\columnwidth}}% Not in "review" mode/false

and then use


for your included images.

share|improve this answer

ConTeXt provides a mechanism to group multiple settings for images, including width. I'll give a different example to illustrate this. I often use the same source to generate course notes and lecture slides. For a certain class of figures, in the slides I want the figure to scale until its width equals \textwidth or its height equals \textheight; while in the handouts I want the figure width to be less the 0.5\textwidth. This can be done using


and then use


in the text file. Then, depending on whether screen mode is active or not, the \externalfigure command inherits the appropriate set of settings. This mechanism is more powerful that individually toggling each parameter of \externalfigure.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.