4

I have a set of Beamer slides with a variety of styles coded in the preamble. There is a block of code corresponding to each style. The idea in using the slides to to select one block of code corresponding to one style in order to use that style. Rather than instructing users to comment out every line of code for all styles not wanted, is there some way to enable the user to 'switch' easily between these different blocks of code in the preamble, such as setting a variable towards the top of the TeX file to the appropriate style? Thanks for any suggestions.

Out of curiosity, is there some way of doing a similar type of switching between different blocks of code in the body of the LaTeX document? Perhaps defining a block of code in a command would be sensible for this.

2
  • You could use hyperref to either switch files or jump to a different page. Assuming hyperref is compatible with beamer (I use pdfscreen and texpower). Commented Nov 29, 2013 at 15:16
  • This sounds like it would be better handled as a package, with options passed to the package and the relevant bits of code chosen for the user.
    – Alan Munn
    Commented Nov 29, 2013 at 15:18

2 Answers 2

5

You can use \ifcase ...\or ... \or ... \fi conditional construct to do the job. In the following example, I use standalone for the sake of simplicity. Change \style definition to any positive integer (in the interval provided by \ifcase ...\or ... \fi) to switch among cases. For more details, read the following code.

\documentclass[preview,border=12pt,12pt]{standalone}
% define an interger variable
\edef\style{0}

\ifcase\style
% case 0:
\author{Donut E. Knot}
\or
% case 1:
\author{Donut Elephant Knot}
\or
% case 2:
\author{Steve Jobs}
\or
% case 3:
\author{Bill Gates}
\or
% case 4:
\author{Timothy Van Zandt}
\or
% case 5:
\author{Till Tantau}
\fi

\title{A journey to the west}

\begin{document}
\maketitle
\end{document}

enter image description here

1
  • 1
    For the purposes of being able to switch between various blocks of code in the preamble, this solution is great. Thank you very much for your help and for your clear example!
    – d3pd
    Commented Nov 29, 2013 at 22:12
5

This strategy lets you choose between two styles by changing one line at the beginning of the preamble:

\usepackage{etoolbox}
\newtoggle{production}

%\toggletrue{production}
\togglefalse{production}

Then, later in the preamble or in the document, as often as needed

\iftoggle{production}{%
   % one style here ...
}{%
   % else another ... 
}

For selection among more than two alternatives, you could use nested toggles, or wait for a better answer using more sophisticated logic.

Another alternative is to write separate preambles, then \input the right one as appropriate.

This can be done from the command line if you prefer.

2
  • While I can't select this solution because it doesn't strictly answer the question of switching between various blocks of code in the preamble, this is a great solution and you've given a clear example. Thank you very much for your help!
    – d3pd
    Commented Nov 29, 2013 at 22:18
  • I don't quite understand your objection. You can use the \iftoggle construction in the preamble to define style macros (I do). But the solution you accepted is better than mine in any case (it covers all cases). In any case thanks for the compliment. Commented Nov 30, 2013 at 0:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .