1

I am looking for a way to easily define and evaluate additional global document options.

Right now I am using

\documentclass[12pt,ngerman]{scrartcl}

as the first line of my documents, I'd like to add more variables, for instance board or management and later use switches like \ifoption{management}{then text}{else text}

I have found the ifdraft package by Heiko Oberdiek which implements the desired behavior for draft and final options and was able to adjust if for the variable state:

\documentclass[state]{article}

\makeatletter
\newif\if@state
\newif\if@option@state
\DeclareOption{state}{%
\@statetrue
\@option@statetrue
}
\ProcessOptions*\relax

\newcommand*{\ifstate}{%
\if@state
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
}
\makeatother

\begin{document}

\ifstate{State was set}{State was not set}

\end{document}

Is there a way to generalize this? For example by simply defining a command \newglobal{state} and encapsulating the rest in a package?

  • 1
    \ProcessOptions should belong in a class or package, not in a document. – egreg Sep 27 '14 at 10:30
  • 1
    Why not create one extra (local) style file that processes these options via the standard mechanisms? – Andrew Swann Sep 27 '14 at 10:50
  • @egreg: Yes, the goal is to have a package that handles the definition, unfortunately it's far beyond my TeX knowledge. – Uwe Ziegenhagen Sep 27 '14 at 14:20
  • All global options are passed to the loaded packages. – egreg Sep 27 '14 at 14:29
  • If you are only interested in boolean flags \newif is pretty flexible... – Bordaigorl Sep 27 '14 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.