# Can't set a toggle based on class option value

I'm trying to toggle linenumbers when the class option man is passed. So far I've tried the recommended answer from this answer but it doesn't work. LaTeX complains with an Undefined Control Sequence error.

Here's my code:

\documentclass[a4paper,man]{article}
\usepackage{lineno}
\usepackage{etoolbox}
\newtoggle{manu}

\makeatletter%
\newcommand*\DetectManuscriptOption{%
\ifsa@man \toggletrue{manu}\else \togglefalse{manu}\fi}
\makeatother%

\begin{document}
\maketitle

\DetectManuscriptOption
\iftoggle{manu}{%
\linenumbers
}

\end{document}


The result is that line numbers are not shown. How can I fix this so that linenumbers are shown when the man option is specified?

\ifsa@preview from the other answer is an internal command of standalone, not a general hook.

You could do something like this.

\documentclass[a4paper,man]{article}
\usepackage{lineno}
\usepackage{etoolbox}
\newtoggle{manu}

\DeclareOption{man}{\toggletrue{manu}}
\ProcessOptions

\begin{document}

\iftoggle{manu}{%
\linenumbers
}
blblb
\end{document}


But it looks a bit unusual to use \DeclareOption and \ProcessOptions outside of a package. I'm not completly sure that it has no side effects.

A more standard method would be to check \@classoptionslist:

\documentclass[a4paper,man]{article}
\usepackage{lineno}
\usepackage{etoolbox,expl3}
\newtoggle{manu}
\ExplSyntaxOn
\makeatletter
\clist_set:NV  \l_tmpa_clist{ \@classoptionslist }
\clist_if_in:NnT
{ \l_tmpa_clist } { man }
{ \toggletrue{manu} }
\makeatother
\ExplSyntaxOff

\begin{document}

\iftoggle{manu}{%
\linenumbers
}
blblb
\end{document}