2

I wonder why the default font sizes won't work in the following modified class file.

\RequirePackage{filecontents}
\begin{filecontents}{example.cls}
\ProvidesClass{example}
\NeedsTeXFormat{LaTeX2e}[1996/06/01]%           
\LoadClass{article}
\DeclareOption{folio}{
    \setlength{\paperheight}{330.2mm}%
    \setlength{\paperwidth}{215.9mm}%
}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax

\end{filecontents}

\documentclass
%[10pt]
%[11pt, folio]
[12pt,folio]
{example} 
\usepackage{lipsum}

\begin{document}
\lipsum  
\end{document}

I tried the suggestion in How to set default font size in latex cls file?

\RequirePackage{filecontents}
\begin{filecontents}{example.cls}
\ProvidesClass{example}
\NeedsTeXFormat{LaTeX2e}[1996/06/01]%           


\def\@@ptsize{12pt}
\DeclareOption{10pt}{\def\@@ptsize{10pt}}
\DeclareOption{11pt}{\def\@@ptsize{11pt}}
\DeclareOption{12pt}{\def\@@ptsize{12pt}}
\LoadClass[\@@ptsize]{article}
\DeclareOption{folio}{
    \setlength{\paperheight}{330.2mm}%
    \setlength{\paperwidth}{215.9mm}%
}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax

\end{filecontents}

\documentclass
%[10pt]
%[11pt, folio]
[10pt,folio]
{example} 
\usepackage{lipsum}

\begin{document}
\lipsum  
\end{document}

but I get an error.

! LaTeX Error: \RequirePackage or \LoadClass in Options Section.

I tried putting all \DeclareOptions after the \LoadClass command but I am not seeing any effect in the document.

Edit

I should have mentioned that putting \LoadClass after \ProcessOptions, as in the answer by Werner has the effect of the paper size folio option not working.

hpesoj626
  • 17,282

1 Answers1

2

You need to load the class only after you've processed the options:

\begin{filecontents}[overwrite]{example.cls}
\ProvidesClass{example}
\NeedsTeXFormat{LaTeX2e}
\DeclareOption{folio}{%
  \setlength{\paperheight}{330.2mm}%
  \setlength{\paperwidth}{215.9mm}%
}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions
\LoadClass{article}
\end{filecontents}

\documentclass
  [12pt,folio]
  {example} 
\usepackage{lipsum}

\begin{document}
\lipsum  
\end{document}
Werner
  • 603,163