# How to declare several options for a package

I'm writing a package and already added two options with \DeclareOption. Then with \ExecuteOptions I set the default option. This works really well, but now I have to add a second option type and this does not seem to work.

Let me explain what I mean by option type. The first couple of options (remember, those that worked well) defined a language (I made custom translations using the translations package and this option passes the language to the translations package and to babel), so only one of them was passed, e.g. \usepackage[en]{myPackage}. What I try to do now is passing a second option to my package, where there are also two possibilities of choosing (whether the bibliography is sorted by name or by appearance), so the usepackage command should look like this: \usepackage[en, bib-by-appearance]{myPackage}.

What I've done is the following:

\DeclareOption{de}{%
% Some Code
}

\DeclareOption{en}{%
% Some Code
}

\DeclareOption{bib-by-name}{%
\bibliographystyle{abbrvnat}%
}

\DeclareOption{bib-by-appearance}{%
\bibliographystyle{template-files/custom-abbrvnat}%
}

\ExecuteOptions{en, bib-by-appearance}

\ProcessOptions\relax


This does not seem to work. How am I supposed to define the options to get my result?

### Update

I was asked to deliver an MWE and I normally also do post one, but I am unable to reproduce this behaving... I normally do my MWE's with ShareLaTeX because I find it more simple to set up a small document, well I now ended up uploading my whole project and compiling it. With ShareLaTeX it works well, while it doesn't on my machine. My computer says

Package natbib: Citation 'FooBar' on page 1 undefined.


while it should be defined (and it also does like the ShareLaTeX example shows). I also tested to simply use \bibliographystyle{template-files/custom-abbrvnat} without selecting it via an option. This also works well. So it seems that my computer has trouble to do his job if the bibstyle is set by an option.

The fail happens if I change \ExecuteOptions{en} to \ExecuteOptions{en, bib-by-appearance}. So I am able to \DefineOption the two possibilities, I am also able to use both bibstyles if called directly (without the option) but I fail when setting the default value of my package to be en, bib-by-appearance.

### Update 2

I now also tested what would happen if I directly set the language, without using the options, so the \ExecuteOptions would only contain the bib-by-appearance and this works. So I think I've located the issue. Now my question is:

Why isn't it working with the two options? How can I make it work?

Feel free to shout out any guess that comes in your mind, I'm happy to try them out. If I can deliver anything else than an MWE, let me know.

• You called the option bib-by-appearance but used \usepackage[english, by-appearance]{myPackage} without the bib- prefix. – Skillmon Oct 16 '17 at 15:18
• That's an error I made here on TeX.SE, but not in my actual code :/ – Sam Oct 16 '17 at 15:19
• Could you please post a complete MWE. The % some code stuff is fine, but this is not a working code snippet. Could you please create a compilable minimal working example? – Skillmon Oct 16 '17 at 15:22
• I'm doing my best to deliver this, but as the project consists of many different files this is quite a bit of work. What I just noticed though is that I don't get any error on ShareLaTeX... Note that I'm using the exact same code! On my computer it says: latexmk: Failure in some part of making files. and several: Package natbib: Citation FooBar on page 1 undefined.. Again, this does not happen on ShareLaTeX. – Sam Oct 16 '17 at 16:04
• @Skillmon I just updated my question, feel free to take a look. – Sam Oct 16 '17 at 16:40

The space in \ExecuteOptions is an easily solved problem; but there's another one. With the input

\documentclass{article}
\usepackage[en,bib-by-name]{sam}

\begin{document}
x
\end{document}


the .aux file will contain

\relax
\bibstyle{unsrtnat}
\bibstyle{abbrvnat}


and running BibTeX will abort loading the second bib style, which is the one the user wants!

This is BibTeX, Version 0.99d (TeX Live 2017)
The top-level auxiliary file: samtest.aux
The style file: unsrtnat.bst
Illegal, another \bibstyle command---line 3 of file samtest.aux
: \bibstyle
:          {abbrvnat}
I'm skipping whatever remains of this command


Use a conditional:

\RequirePackage{natbib}
\DeclareOption{de}{%
% Some Code
}

\DeclareOption{en}{%
% Some Code
}

\newif\ifbibbyname
\DeclareOption{bib-by-name}{%
\bibbynametrue
}

\DeclareOption{bib-by-appearance}{%
\bibbynamefalse
}

\ExecuteOptions{en,bib-by-appearance}% <--- no spaces here!

\ProcessOptions\relax

\ifbibbyname
\bibliographystyle{abbrvnat}
\else
\bibliographystyle{unsrtnat}
\fi


(I used a standard bib style instead of the custom one you have, just replace it.)

• I'll use your conditional even if I don't really see the point of it. It currently works, no matter if I set an option or let LaTeX use the default one. In all cases, the correct output is generated. But I understand, that your method will be better, so I'll use it. :) – Sam Oct 16 '17 at 17:25
• @Sam The output of BibTeX is very clear about the issue and, with your approach, the bib style used by BibTeX will always be the one corresponding to the bib-by-appearance option given in \ExecuteOption. – egreg Oct 16 '17 at 17:26
• You're totally right, after deleting all the latex compiling files it didn't work anymore. With your conditional, it works like a charm. Thanks!! – Sam Oct 16 '17 at 18:06

## Found the problem

It's unbelievable but true, the problem was the space between en and bib-by-appearance. I just tried

\ExecuteOptions{en}
\ExecuteOptions{bib-by-appearance}


which worked, then I tried

\ExecuteOptions{en,bib-by-appearance}


and that worked too. At this moment I already thought that I'm dumb. But as I added a space to write

\ExecuteOptions{en, bib-by-appearance}


it failed again.

So if anybody encounters this same problem, try removing the spaces and you should be fine...

• That's one problem, the other is that you are writing two \bibstyle commands in the aux file and BibTeX doesn't like it at all. – egreg Oct 16 '17 at 17:14
• @egreg What do you mean by that? Should I do something different? – Sam Oct 16 '17 at 17:18
• See my answer for the details – egreg Oct 16 '17 at 17:22