[OS X TeX] Test whether an option has loaded

David Craig dac at panix.com
Thu Mar 1 21:48:09 EST 2012


How does one test whether a particular documentclass option has been loaded?  

My specific objective is to typeset certain sections of code differently depending on whether or not the document is being set in "preprint" mode or not in revtex4.

Thus, I would like to do something like:

\documentclass[aps,prd,%
preprint,%
]{revtex4} 

%% 
\usepackage{ifthen}
\ifthenelse{test for whether "preprint" option is set}{ \newcommand{\pp}{1} }{ \newcommand{\pp}{0} }
%%

\begin{document}

\ifthenelse{ \pp=1}{%
% code to set if in preprint mode
}{%
% code to set if not
} %

\end{document}

... or something to that effect.   I hope what I'm after is reasonably clear.   The code works if I set \pp by hand.   I would like to identify a means for the file to set \pp intelligently itself.


[ASIDE: So, should you care what I've tried so far ...  I HAVE discovered the existence of "\@ifpackagewith{⟨name ⟩}{⟨option-list ⟩}{⟨true ⟩}{⟨false ⟩}", as well as @classoptionslist, but I'm afraid I haven't figured out how to use them to do what I want.  The first thing I tried was

\makeatletter%
\@ifpackagewith{aps}{preprint}{\newcommand{\pp}{1}}{\newcommand{\pp}{0}}
\makeatother%

in the preamble instead of the "ifthenelse" code above, but that doesn't always sets \pp=0 i.e. always returns false.  I'm guessing that's because the options list contains more than "preprint".   Next I tried

\usepackage{xstring}
\makeatletter%
\newcommand{\pp}{%
\IfSubStr{@classoptionslist}{preprint}{1}{0}%
}%  
\makeatother%

but that gives an error ("Use of \x at footnote doesn't match its definition")  when it gets to \pp in the body of ifthenelse.   Not sure what's happening there.  If I zap the ifthenelse in the body and just have TeX print "\pp" it seems IfSubStr is always evaluating to false regardless of whether preprint is in the options list.   (Which doesn't explain the "\x at footnote" error, anyway.  Maybe that has to do with a conflict with revtex internals.)  ANYHOO, ...  googling and poring over tex.stackexchange posts has led me to try various and sundry other things, but none of them are working.]   

There are other examples where I'd like to try something like this, so solutions not too specific to revtex/preprint would be preferable, but if that's all there is, I'll take it.

Thanks,
David Craig


<http://www.panix.com/~dac/>






More information about the MacOSX-TeX mailing list