add tag
निरंजन
I am writing a package which needs an option disabling a global command. Let's say the package option is `xyz`. If the package is loaded with option `xyz` one global command from the package will be disabled. `DeclareOption` allows me to have a specific command if a particular option is loaded, but how to code something like "disable command `abc` if `xyz` option is loaded?"
Top Answer
samcarter
Instead of disabling a command, one could define it only if the package option xyz is not present:

```
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{foo}

\newif\iffoo@xyz
\foo@xyzfalse

\DeclareOption{xyz}{\foo@xyztrue}
\ProcessOptions

\iffoo@xyz
\else
  \newcommand{\test}{duck}
\fi
```
Answer #2
joulev
**Disclaimer:** This does *not* answer the original question. Rather it is a suggestion for a better practice (IMO) which is "too long for a comment".

---

As I mentioned in the chat, I think using a key=val interface is a better practice. For example, this is how I would implement `baseline`:

```
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{marathi}
\RequirePackage{pgfkeys}

\def\marathiset#1{\pgfkeys{marathi/.cd,#1}}

\pgfkeys{
  marathi/.is family,marathi/.cd,
  baseline/.code={\renewcommand\baselinestretch{#1}\selectfont},
  baseline=1.5,
  baseline/.default=1
}

\DeclareOption*{\expandafter\marathiset\expandafter{\CurrentOption}}
\ProcessOptions
```

Now in the document I can choose different values for `baseline`:

|Preamble|Value of `\baselinestretch`|
|---|---|
|`\usepackage{marathi}`|1.5|
|`\usepackage[baseline]{marathi}`|1|
|`\usepackage[baseline=10]{marathi}`|10|

This is a generalization of the way you want it to work. It makes your package more customizable.

Also, the user can *change* the value in the middle of the document. This is not something you can do easily if you use `\DeclareOption` without the star. The following works:

```
\documentclass{article}
\usepackage{marathi}
\usepackage{lipsum}
\begin{document}
\lipsum
\marathiset{baseline=1}
\lipsum
\end{document}
```

![blob](/image?hash=4c43e24f3e149a2094a4616b098f498c5e8aac70fe9027aae6c037efe11ab2ac)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.