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 would like to be able to detect if the standalone package was used with [preview=false] or [preview=true]. Not too concerned if this setting was a default or user defined.

Based on How can one undefine an already processed class option?, the macro @classoptionslist is supposed to be a comma separated list of options passed to the class. I attempted to detect if this macro had the string preview=true in it, but this does not yield the correct results. The following always prints Package Option: [preview=false].

\documentclass[preview=true]{standalone}% Does not work
%\documentclass[preview=false]{standalone}% works


Package Option: [preview=\DetectPreviewOption].
share|improve this question
And the test \newcommand*{\DetectPreviewOption}{% \ifsa@preview\relax true\else false\fi% }% isn't the right one? – Marco Daniel Sep 4 '11 at 21:07
@Marco: Yep that is the correct one, seems to work great. – Peter Grill Sep 4 '11 at 21:14
up vote 5 down vote accepted
  \ifsa@preview true\else false\fi}

Package Option: [preview=\DetectPreviewOption].
share|improve this answer
@Peter: to elaborate: the preview option of the standalone class is stored as the if-switch \ifsa@preview, so you can simply use this switch. – Martin Scharrer Sep 4 '11 at 21:11
It's a bit harder to undo the effect of preview=true: the preview package would be already loaded. – egreg Sep 4 '11 at 21:14
@Martin: as already done ,-) – Herbert Sep 5 '11 at 6:01
@Herbert: Yes, I just wanted to state it explicitly. Some beginners might have issues reading it from the source code alone. – Martin Scharrer Sep 5 '11 at 6:39
@Martin: using directly the switch implies the makeatletter...\makeatother which is annoying ... Creating another name makes sense! – Herbert Sep 5 '11 at 13:58

Normally, you would be right and \@classoptionlist would have this information in (try your example using the article class). The behaviour you are seeing is a 'feature' of the standalone class, which includes the lines


which will remove all of the known options from \@classoptionslist.

I see that Herbert has proposed a solution: I'm answering here to point out why the approach you've tried is not working in this case.

share|improve this answer
Thanks, that is useful to know. – Peter Grill Sep 4 '11 at 21:09
\sa@classoptionslist loads only undeclared options (\DeclareDefaultOption); \@classoptionslist is made equal to it so the undeclared options are passed to the packages as usual. The declared options, among which is the boolean preview, are dealt with \ProcessKeyvalOptions (and are not passed to packages, I guess). – egreg Sep 4 '11 at 21:10
@egreg: That's what I meant by 'remove the known options', as it copies the unknown ones only 'over' the full list. – Joseph Wright Sep 4 '11 at 21:16

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.