[OS X TeX] Test whether an option has loaded
David Craig
dac at panix.com
Fri Mar 2 18:45:28 CET 2012
On Mar 2, 2012, at 9:47 AM, Chris Goedde wrote:
> On Mar 2, 2012, at 1:27 AM, David Craig wrote:
>> This actually works whether or not I include the backslash. What function does it serve?
>>
> Are you sure you can actually fall through both branches using @classoptionslist and not \@classoptionslist? I don't see that (using my version); it only ever falls through the non-preprint case. Of course it 'works' in the sense that there's no error.
>
> I'm pretty sure that \@classoptionslist is a command, so the backslash is necessary. Otherwise you're just searching the string '@classoptionslist' for the string 'preprint', and that always fails. At least, if I google '@classoptionslist', all the examples I find are using it as a command, with the backslash.
Well ... I was quite sure when I wrote that email. Oops [:-)] However, now I agree that it does not work without the backslash -- which is comforting, because that makes sense to me within the context of LaTeX.
The stackexchange post from which I learned about the existence of \@classoptionslist is in fact missing the leading backslash early in the post. On another reading I see it re-appears further down the post, which I had not noticed. So there were several reasons my initial attempts were not working.
To summarize this thread, appended is a minimal working example using both the method I tried originally, and Chris' suggestion using versions. Thanks very much for the guidance! This is new territory for me insofar as LaTeX is concerned, and it's going to be very useful.
Thanks,
David Craig
<http://www.panix.com/~dac/>
%% Minimal working example of alternative structures for executing
%% different code depending on which class options are set
%%
%% CAVEAT EMPTOR: Some packages deliberately alter the value of
%% \@classoptionslist!
\documentclass[aps,prd,%
preprint,%
]{revtex4}
\usepackage{ifthen,version,xstring}
\makeatletter%
% Solution using versions package:
\IfSubStr{\@classoptionslist}{preprint}%
{\includeversion{preprintv}\excludeversion{finalv}}%
{\includeversion{finalv}\excludeversion{preprintv}}%
%
% Solution using switch:
\newcommand{\pp}{1} % Defaults to preprint code option if something goes wrong
\IfSubStr{\@classoptionslist}{preprint}%
{\renewcommand{\pp}{1}}%
{\renewcommand{\pp}{0}}%
%
\makeatother%
\begin{document}
This is the solution using the ``versions'' package:
\begin{preprintv}
This is the preprint version text.
\end{preprintv}
\begin{finalv}
This is the final version text.
\end{finalv}
\vspace{\baselineskip}
This is the version using a switch:
\ifthenelse{\pp=1}{%
Print this if \textbackslash{pp}=1; the value of \textbackslash{pp} is \pp.
}{%
Print this if \textbackslash{pp}=0; the value of \textbackslash{pp} is \pp.
} %
\end{document}
More information about the macostex-archives
mailing list