3

I've learnt how to use LaTeX at the user level, but wanted to package the recurring code (resulting mostly from the styling of the cover) in a class file. Therefore, I tried the following simple example class file:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{test}[2018/10/12 v0.1 Test class]
\PassOptionsToClass{12pt}{report}
\ProcessOptions
\LoadClassWithOptions{report}

Although this works if I pass the size I want, if I omit it, it defaults to 10pt, instead of 12pt that I want. Do you know how to make the default become the 12pt, and still work if I decide to give it another size option?

4
  • Welcome... If my answer solves your problem, then your question is a duplicate of the given link.
    – koleygr
    Commented Oct 14, 2018 at 14:12
  • Possible duplicate of How to set default font size in latex cls file?
    – koleygr
    Commented Oct 14, 2018 at 17:25
  • It seems to be after the same goal, but is very vague on what the code is.
    – tigre200
    Commented Oct 14, 2018 at 17:28
  • Did you tried my code below? do you want any explanation? I removed the close vote... Explanation: Every option is stored inside the variable \@@ptsize that has an initial value of 12pt... Then we select our default options for the report class and passing the option \@@ptsize that is 12pt if not selected 11 or 10pt in the options of the class
    – koleygr
    Commented Oct 14, 2018 at 17:29

1 Answer 1

2

From here:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{test}[2018/10/12 v0.1 Test class]
\def\@@ptsize{12pt}
\DeclareOption{10pt}{\def\@@ptsize{10pt}}
\DeclareOption{11pt}{\def\@@ptsize{11pt}}
\DeclareOption{12pt}{\def\@@ptsize{12pt}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}
\ProcessOptions\relax
\LoadClass[\@@ptsize]{report}

Then it works as you expect with a main file like:

\documentclass{test}

or

\documentclass[11pt]{test}

and:

\begin{document}
\chapter{Test}
\section{test}
Test

\end{document}
8
  • 1
    What are the @@ in \@@ptsize?
    – tigre200
    Commented Oct 14, 2018 at 17:31
  • And isn't there a way that avoids re-declaring all the font size options?
    – tigre200
    Commented Oct 14, 2018 at 17:34
  • nothing special... This character works usually inside in \makeatletter and \makeatother commands and will not work in the simple preamble or document... This way the author of the package/class, can add a protection for his command/or variable to be somehow more difficult to change its value someone by mistake etc
    – koleygr
    Commented Oct 14, 2018 at 17:36
  • 1
    The only accepted values for report are these three values.... So,it is just a declaration that will be used later to add our default value and to keep the other values still available by saving them in the same variable we will finally give to our class.... It could possibly avoided with hacks that would make the code much more difficult (like looking for options that finish in "pt" and adding commands to use them).
    – koleygr
    Commented Oct 14, 2018 at 17:40
  • But now if I want to change, for example, to a4paper, then I will have to do the same thing for the types of paper, right? Isn't this solution very brittle?
    – tigre200
    Commented Oct 14, 2018 at 17:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .