# Can I know the class options in a document (or user-defined package)?

Edit (again). It appears that I'm not very clear. I'm looking for a technique to access the options passed to the class. The MWE below is just an example, 12pt is an example. If there is no general technique, then the specific options that I'd like to check for are 11pt, 12pt, and twoside.

Can I determine within a document whether or not the 12pt option (or other options, like twoside) was passed to the class? Something like this:

\documentclass[12pt]{article}
\makeatletter
\newif\if@myxiipt\@myxiiptfalse

% [how to set if@myxiipt ???]

\if@myxiipt
\usepackage{ebgaramond}% Lovely font, but so small I only use if 12pt
\else
\usepackage{XCharter}% Font is legible at small sizes
\fi
\makeatother

\begin{document}
It was a dark and stormy night...
\end{document}

• The font size is stored in \f@size (without the pt, i.e. in this case only 12). – Henri Menke Sep 23 '17 at 1:15
• Is there a way to test whether or not \f@size == 12 in an \if? I'm not actually trying to print the size (that's just for the MWE), I want to conditionally execute code based on it. – dedded Sep 23 '17 at 1:20

Something like this?

\documentclass[12pt,twoside,11pt]{article}
\makeatletter
\newif\if@myxiipt\@myxiiptfalse
\def\tempa{12pt}\def\tempb{11pt}\def\tempc{twoside}%
\def\mysides{one}\def\mysize{normal}
\@for\xx:=\@classoptionslist\do{%
\ifx\tempa\xx \def\mysize{biggest}\@myxiipttrue\fi
\ifx\tempb\xx \def\mysize{bigger}\fi
\ifx\tempc\xx \def\mysides{two}\fi
}

\if@myxiipt
\usepackage{ebgaramond}
\else
\usepackage{XCharter}
\fi
\makeatother

\begin{document}
The size chosen was \mysize.
The document is \mysides-sided.
It was a dark and stormy night \dots.
\end{document}


• Yes, even works for bogus options like "totallymadeupoption" (though those also yield a Latex warning). – dedded Sep 23 '17 at 2:38

Last edit

\documentclass[twoside,12pt]{article}

\makeatletter
\ifnum\f@size=12
\if@twoside
\usepackage{tikz}
\fi
\fi
\makeatother

\begin{document}

\begin{tikzpicture}
\node at (0,0) {Package loaded for 12 pt and twosided document. In other cases the compilation will fail!};
\end{tikzpicture}

\end{document}


After OP's edit a simple way since documentclass accepts only integers for fontsize

\documentclass[12pt]{article}

\makeatletter
\ifnum\f@size=12
\usepackage{tikz}
\fi
\makeatother

\begin{document}

\begin{tikzpicture}
\node at (0,0) {Package loaded for 12 pt!};
\end{tikzpicture}

\end{document}


Dimensions are real numbers and thus you have to consider check for less and greater than because not all decimal numbers can represented as binary numbers:

Here is how you can do your calculations:

\documentclass[12pt]{article}
\usepackage{anyfontsize}
\makeatletter
\newlength{\mysize}
\newlength{\testSize}
\setlength{\testSize}{12pt}
\setlength{\mysize}{\f@size pt}
\makeatother

% [how to set if@myxiipt ???]
\makeatletter
\newcommand{\testTS}[1]{
\ifnum #1=0
\ifdim\mysize>\dimexpr0.999\testSize\relax
\ifdim\mysize<\dimexpr1.001\testSize\relax
\else
\fi
\else
\fi
\else
\xdef\mycursize{\f@size pt}
\ifdim\mycursize>\dimexpr0.999\testSize\relax
\ifdim\mycursize<\dimexpr1.001\testSize\relax
This is 12pt text.
\else
This is not 12pt text.
\fi
\else
This is not 12pt text.
\fi
\fi
}
\makeatother

\begin{document}
\testTS{0}
\testTS{1}

\fontsize{11.97}{14}\selectfont

\testTS{0}
\testTS{1}
\end{document}

• So is the fact that the option itself was passed (or not) not directly available? – dedded Sep 23 '17 at 1:44
• I just show your edit. Just editing for your simple example – koleygr Sep 23 '17 at 1:49
• @dedded is it ok for you like this? You will get an error if you change the 12pt option in the documentclass... This means it works. – koleygr Sep 23 '17 at 1:53
• Thank you, but I think you're misinterpreting my MWE (a minimal example) as the question. I'm looking for a technique to access the class options, I used 12pt as an example. A different example might be twoside. In fact, the specific options I want to check for are 11pt, 12pt, and twoside. – dedded Sep 23 '17 at 1:59
• Ok... I show the title but then in the answer was about 12pt. We solved 12pt or 11pt or whatever pt. Now let's check for twoside... – koleygr Sep 23 '17 at 2:07