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].
  • 1
    And the test \newcommand*{\DetectPreviewOption}{% \ifsa@preview\relax true\else false\fi% }% isn't the right one? Commented Sep 4, 2011 at 21:07
  • @Marco: Yep that is the correct one, seems to work great. Commented Sep 4, 2011 at 21:14

2 Answers 2

  \ifsa@preview true\else false\fi}

Package Option: [preview=\DetectPreviewOption].
  • @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. Commented Sep 4, 2011 at 21:11
  • It's a bit harder to undo the effect of preview=true: the preview package would be already loaded.
    – egreg
    Commented Sep 4, 2011 at 21:14
  • @Martin: as already done ,-)
    – user2478
    Commented Sep 5, 2011 at 6:01
  • @Herbert: Yes, I just wanted to state it explicitly. Some beginners might have issues reading it from the source code alone. Commented Sep 5, 2011 at 6:39
  • @Martin: using directly the switch implies the makeatletter...\makeatother which is annoying ... Creating another name makes sense!
    – user2478
    Commented Sep 5, 2011 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.

  • \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
    Commented Sep 4, 2011 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
    Commented Sep 4, 2011 at 21:16
  • How to print all options used within \documentclass[]{}?
    – Sigur
    Commented Nov 11, 2018 at 0:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .