TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to conditionally do some things (like input a file) depending on if a specific class option was passed. For example, I'd like to have an "instructor" option to the class that would input a file of instructor notes. Something like:


Rest of stuff

Is there some code I can put in the preamble to set something (maybe an ifthen boolean?) based on if the instructor option is passed to the class?

My goal in doing this is to make it trivial for someone to change the file to include the instructor portions of the book. If what I'm trying to do above is an ugly way to do it, I'd love to hear a more elegant way!

share|improve this question
possible duplicate of Loading a package conditionally – Grigory M Sep 15 '10 at 10:15
Definitely related so it's certainly worth noting the link, but in this case I suspect that the package (if such is loaded) should be loaded in both cases but do different things depending on a class option. – Loop Space Sep 16 '10 at 11:32
up vote 11 down vote accepted

Package and class options generally have meaning just for that particular class or package. The book class doesn't have an instructor option. If you're making your own class, based on book, then it is quite simple. It'd be something like


Then you could use \if@instructor in the document (although you'd need to have used \makeatletter first, so maybe it's better to omit the @).

If you're not making your own class, then the easiest way would be to just have

\@instructortrue % or \@instructorfalse depending on which you want

in your preamble.

share|improve this answer
Perfect; thanks! – Jason Sep 15 '10 at 4:05

More as an aside, class options get passed on to packages so if you don't want to modify the class but want to simulate the situation that you describe, you could write a new package, say instructor.sty, and have it do something with the instructor option. (You'd get a warning that the class didn't know how to deal with the instructor option.)

If your goal is to make this as easy as possible for the end user, I would make a lot of commands in the instructor.sty package that did one thing if given the instructor option but did something else if not, rather than have lots of \if ... \fis in your document. So, for example, you could have a command \instructorinput{filename} which input the filename if the instructor option was given but did nothing if not. Something like:





I should say that TH's answer is probably the simplest way to do it in terms of code, though.

(Also, http://tex.stackexchange.com/questions/1482/how-can-one-undefine-an-already-processed-class-option is a slightly related question that may contain some information that may help)

share|improve this answer
I think your way is better if there's a reason to actually make a style file, which it sounds like there might be. – TH. Sep 16 '10 at 3:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.