# Boolean option in style file does not work

a while ago, I learned on StackExchange that I could create a style file to contain my preamble and, in particular, to include Boolean switches so as to select certain parts of the preamble as needed.

This has worked perfectly so far. Yet I now encounter a problem with packages that seem incompatible with the Koma classes. Here is my preamble style file, boiled down to the essentials:

\ProvidesPackage{mypreamble}
\RequirePackage{kvoptions}

\SetupKeyvalOptions{family=MO,prefix=MO@}
\DeclareBoolOption[true]{nokoma}

\ProcessKeyvalOptions*

% THE FOLLOWING 3 PACKAGES SEEM INCOMPATIBLE WITH KOMA
\ifMO@nokoma
{
\usepackage{natbib}
\usepackage{bibentry}
\usepackage{sectsty}
}
\else
{
}
\fi

\usepackage[english]{babel}
\usepackage{lipsum}

\endinput


When I compile a Koma letter, this is ok, see the following minimal example:

\documentclass{scrlttr2}
\usepackage[nokoma=false]{mypreamble}

\begin{document}

\lipsum

\end{letter}
\end{document}


However, a standard article no longer compiles, as illustrated by this programme:

\documentclass{article}
\usepackage[nokoma=true]{mypreamble}

\begin{document}
\lipsum
\end{document}


As mentioned above, the approach adopted here is generally fine when it comes to the inclusion or exclusion of specific parts of my preamble. Yet the above interplay between the Boolean switches, the three packages in question and Koma no longer works.

I would be very grateful for any advice on how this problem can be rectified. Thanks!

You were including the packages inside a group, so all their definitions were discarded at the }

\ProvidesPackage{mypreamble}
\RequirePackage{kvoptions}

\SetupKeyvalOptions{family=MO,prefix=MO@}
\DeclareBoolOption[true]{nokoma}

\ProcessKeyvalOptions*

% THE FOLLOWING 3 PACKAGES SEEM INCOMPATIBLE WITH KOMA
\ifMO@nokoma

\usepackage{natbib}
\usepackage{bibentry}
\usepackage{sectsty}

\fi

\usepackage[english]{babel}
\usepackage{lipsum}

\endinput

• So the problem did not lie with the style file, Koma or the packages: it was my syntax that was wrong. For someone like me who is not at all versed in LaTeX programming, is there an easy way to learn about, e.g., the meaning in curly braces in style files? – Michael Jan 23 '15 at 11:54
• At another place in my style file, I have the following conditional statement: \ifMO@deutsch{\PassOptionsToPackage{german}{isodate}\PassOptionsToPackage{ngerman}{babel}} Should I remove the curly braces here as well? Thanks! – Michael Jan 23 '15 at 11:56
• @Michael yes primitive \if do not take {} arguments so they are not marking the then part of the code they are part of the then part (which is everything up to \else or \fi so they act as a tex group not as an argument delimiter – David Carlisle Jan 23 '15 at 12:01