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.

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}
| improve this answer | |
  • This has the effect of the paper size option not working though. I am sorry that I missed that part in my question. I should edit it now. – hpesoj626 Oct 9 '19 at 11:24
  • 1
    @hpesoj626: Changes are applied to \paperheight and \paperwidth. However, if your plan is to change the page dimensions, they won't have any effect in the preamble. See What is the difference between \paperheight, \paperwidth and \pdfpageheight, \pdfpagewidth? Instead, you should try to set \pdfpagewidth and \pdfpageheight if you're using pdfLaTeX. – Werner Oct 9 '19 at 15:20
  • That resolved the problem. Thank you for your answer and your link! – hpesoj626 Oct 10 '19 at 0:38

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.