I want an option in a package I'm writing to activate all other options. What I want is something like \usepackage[all]{mypackage}
which will activate all options in mypackage
(including options added later). Is there an easy way to do this? Currently, my best way to do this is to create an if for every option and setting all the ifs to true for the all
option. However, this means I cannot activate the options that don't use ifs. Here is a MWE:
\documentclass{article}
\begin{filecontents}[overwrite]{mypackage.sty}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mypackage}
\newcommand{\mycommand}{\LaTeX\ }
\makeatletter
% Some options:
\newif\if@firstoption
\DeclareOption{option1}{\@firstoptiontrue}
\newif\if@secondoption
\DeclareOption{option2}{\@secondoptiontrue}
\DeclareOption{option3}{\renewcommand{\mycommand}{\LaTeX\ is \textit{awsome}}}
% Activate all options:
\newif\if@all
\DeclareOption{all}{\@alltrue}
% Unknown options:
\DeclareOption*{\PackageWarning{mypackage}{No option ‘\CurrentOption’}}
\ProcessOptions\relax
\if@all
\@firstoptiontrue
\@secondoptiontrue
\fi
\RequirePackage{lipsum}
\if@firstoption
\newcommand{\foo}[1]{\textit{#1}\par \lipsum[2]}
\fi
\if@secondoption
\newcommand{\bazbaa}{\lipsum[1]}
\fi
\makeatother
\endinput
\end{filecontents}
\usepackage[all]{mypackage}
\begin{document}
This is a test.
\mycommand
\foo{dummy text:}
\bazbaa
\end{document}
As you can see, I can activate option 1 and 2 this way since they use ifs, but not option 3. Is there a way to activate option 3 without having to use an if? Also; is there a way to automaticually include new options? Say I write a new option 4:
\newif\if@fourthoption
\DeclareOption{option4}{\@fourthoptiontrue}
Is there a way to automaticually activate this when using all
without having to manually adjust the \if@all
like this:
\if@all
\@firstoptiontrue
\@secondoptiontrue
\@fourthoptiontrue % added this line manually
\fi
Also related: Say you want an option to activate most options, but not all options. Is it possible to activate all options with the exeption of one or more options? For example: say I want a package option most
which is eqvivalent to all options (including options added in the future) except the first option. \usepackage[most]{mypackage}
= \uspackage[option2,option3,option4]{mypackage}
. Is this feasable?
I realised that some options might not be comatible with each other. Lets say that the fourth option is:
\if@fourthoption
\newcommand{\bazbaa}{Hello there!}
\fi
which would clash with option 2 (in this case the clash can be avoided by using \providecommand
instead, but you may not be able to fix all options clashes easaly). Is there a way to not include options that would clash with other options? Perhaps by an if or something?
\DeclareOption{all}{\ExcuteOptions{option1,option2,option3,option4}}
?for option: \ExecuteOptions{option}
Then maybe I can tag options that clash in some way as to not include them in the for loop?\newcommand\myopt[2]{\xdef\myoptlist{\ifx\myoptlist\@empty\else\unexpanded\expandafter{\myoptlist},\fi\unexpanded{#1}}\DeclareOption{#1}{#2}}
and then do\expandafter\ExecuteOptions\expandafter{\myoptlist}
.