0

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?

5
  • 3
    \DeclareOption{all}{\ExcuteOptions{option1,option2,option3,option4}} ? Nov 24, 2022 at 13:36
  • Thanks @DavidCarlisle ! Is there maybe a way to do some sort of for loop to automaticually include the options? I was thinking something like: for option: \ExecuteOptions{option} Then maybe I can tag options that clash in some way as to not include them in the for loop?
    – Vebjorn
    Nov 24, 2022 at 13:50
  • or write a local wrapper for DeclareOption that adds to the list you declare. Nov 24, 2022 at 13:53
  • How do you write a local wrapper @DavidCarlisle ? I've not heard about it before.
    – Vebjorn
    Nov 24, 2022 at 16:01
  • 1
    @Vebjorn \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}.
    – Skillmon
    Nov 24, 2022 at 23:06

1 Answer 1

0

I found the comment from David Carlisle very helpful. I did something like:

\DeclareOption{all}{\ExcuteOptions{option1,option2,option3,option4}}

You must log in to answer this question.

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