4

I'm pretty new to advanced LaTeX coding and therefore may not have a perfectly specific question. I hope you can help me anyway: I want to maintain different preambles at once. They can be seen as templates for different styles. So I wanted to create a package(?) with options that executes the given template. My Idea was to call this Package with e.g. \RequirePackage{templates}[Wissenschaft]. I tried following code for the package templates:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{templates}[28.05.2021 templates.sty]
\RequirePackage{ifthen}

\newboolean{Wissenschaftbool}
\DeclareOption{Wissenschaft}{ \setboolean{Wissenschaftbool}{true}}

\newboolean{template1bool}
\DeclareOption{template1}{ \setboolean{template1bool}{true}}

\ExecuteOptions{Wissenschaft}
\ExecuteOptions{template1}

\ProcessOptions\relax

\ifthenelse{\boolean{Wissenschaftbool}}{%
    \RequirePackage{core/Wissenschaft}
}{}
\ifthenelse{\boolean{template1bool}}{%
    \RequirePackage{core/template1}
}{}
\endinput

My problem is, that both options are always executed. If I comment one option, the code only executes one options, exactly as I want it to. Can someone help me getting the code fixed, so that only the given options gets executed?

1
  • You are \Execute-ing both options, so you are setting them true. Remove the two \ExecuteOptions and then only the ones that will be in \RequirePackage[options]{package} will be true
    – Rmano
    May 31, 2021 at 8:50

1 Answer 1

4

You seem to want \ProcessOptions.

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{templates}[2021/05/28 templates]

\newif\iftemplates@Wissenschaft
\newif\iftemplates@templateone

\DeclareOption{Wissenschaft}{\templates@Wissenschafttrue}
\DeclareOption{template1}{\templates@templateonetrue}

\ProcessOptions\relax

\iftemplates@Wissenschaft
  \RequirePackage{templates-Wissenschaft}
\fi
\iftemplates@templateone
  \RequirePackage{templates-template1}
\fi

\endinput

The user will call

\usepackage[Wissenschaft]{templates}

to load the Wissenschaft option.

If the structure of the package has a core subdirectory, you don't need to specify it in the \RequirePackage call, because TeX systems generally do recursive search. But there's no need to use such structure. It's better to use specific names, like in the code above.

By the way, the release date should be specified in the form

YYYY/MM/DD

or

YYYY-MM-DD

otherwise LaTeX will not be able to extract it.

2
  • I can't edit the typo \iftemplate@templateone to \iftemplates@templateone. But for the rest: Thank you very much! Now it works!
    – Titanlord
    May 31, 2021 at 9:22
  • 1
    @Titanlord Sorry for the typo, which I've fixed.
    – egreg
    May 31, 2021 at 9:27

You must log in to answer this question.

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