1

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?

1

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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