निरंजन
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
Skillmon
Disabling is actually possible, you could `\let` your command to something which is guaranteed to be undefined, or you could redefine it to throw some meaningful error.
```
\ProvidesPackage{mytestpkg}
\newcommand\mytestcmd[1]{\typeout{Test was given #1.}}
\DeclareOption{undefine}{\let\mytestcmd\mytestpkg@undefined}
\DeclareOption{error}
{%
\renewcommand\mytestcmd[1]
{%
\PackageError{mytestpkg}
{The command \noexpand\mytestcmd was disabled}{}%
}%
}
\ProcessOptions\relax
```
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}
```

Answer #3
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
```