निरंजन
I want to write a class file for which I load the standard class `book`, but I want to load it conditionally. I want to create a class option `digital`, which will load the `book` class with `oneside` option and else the normal book class. I have tried the following, but it doesn't seem to work. Any help?
```
\newif\ifdigital
\DeclareOption{digital}{\ifdigital}
\ProcessOptions
\ifdigital
\LoadClass[oneside]{book}
\else
\LoadClass{book}
\fi
```
Top Answer
Phelype Oleinik
The only issue with your code is the line `\DeclareOption{digital}{\ifdigital}`, which should have been `\DeclareOption{digital}{\digitaltrue}`. When you declare an `\if<name>` command with `\newif`, it creates three commands:
- `\if<name>`: the conditional itself
- `\<name>true`: sets `\if<name>` equal to `\iftrue`
- `\<name>false`: same, but equal to `\iffalse`
so your option code needs `\digitaltrue` rather than `\ifdigital`.
---
That said, if your only purpose with the `digital` option is to pass `oneside` to `book` you can do instead:
```latex
\DeclareOption{digital}{\PassOptionsToClass{oneside}{book}}
\ProcessOptions
\LoadClass{book}
```
which has the advantage that if you have more options to pass to `book` you don't need intricate nestings of conditionals. For example, if you had another `bigpaper` option that would pass `a3paper` to `book`, with conditionals you'd have to do
```latex
\newif\ifdigital
\newif\ifbigpaper
\DeclareOption{digital}{\digitaltrue}
\DeclareOption{bigpaper}{\bigpapertrue}
\ProcessOptions
\ifdigital
\ifbigpaper
\LoadClass[oneside,a3paper]{book}
\else
\LoadClass[oneside]{book}
\else
\fi
\ifbigpaper
\LoadClass[a3paper]{book}
\else
\LoadClass{book}
\fi
\fi
```
With `\PassOptionsToPackage` that would be a single line more:
```latex
\DeclareOption{digital}{\PassOptionsToClass{oneside}{book}}
\DeclareOption{bigpaper}{\PassOptionsToClass{a3paper}{book}}
\ProcessOptions
\LoadClass{book}
```
Of course you can also have the conditionals if you need them further down in your code:
```latex
\newif\ifdigital
\DeclareOption{digital}{\digitaltrue
\PassOptionsToClass{oneside}{book}}
\ProcessOptions
\LoadClass{book}
```