0

I'm writing a class for a course guide, and basing it on the standard book class. Following the answer by egreg to Passing (just) other options, when using pgfopts, I started working on my own class. Yet somehow, while it doesn't complain about the extra options, and seems to have the correct options when calling LoadClass, none of those options affect the behaviour of the book class.

\begin{filecontents}{courseguide.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{courseguide}
\RequirePackage{pgfopts}

%%%% PGF options \def\Course@classoptions{10pt}

%% Academic year \newcounter{AY} \setcounter{AY}{\the\year}

\pgfkeys{ /Course/.cd, %%% This is the academic year AY/.code=\setcounter{AY}{#1}, AY/.default=\the\year, .unknown/.code={ \message{mwe found unknown key: \pgfkeyscurrentname} \edef\Course@classoptions{\Course@classoptions,\pgfkeyscurrentname} } }

\ProcessPgfOptions{/Course}

\message{MWE Current \Course@classoptions: \Course@classoptions}

\LoadClass[\Course@classoptions]{book} \end{filecontents}

\documentclass[AY=2026,letterpaper,landscape,12pt]{courseguide} \usepackage{lipsum} \begin{document}

The academic year is \theAY-{\the\numexpr\theAY+1}

\end{document}

Here's a non-working MWE. The options appear to be passed, but it's always in 10pt, a4, portrait. I expect this is trivial, but I'm stumped.


Addendum. After the first answer (which helps a lot) I'm puzzled by what happens if I remove the \usepackage{showframe} from the (fixed) test document. The printed content is still the same:

The academic year is 2026-2027.

The document uses paper of size W=11.00215 in, H=8.50166 in.

The document font size is 12.

But the actual document is (by checking the PDF properties in evince) A4 paper.

Conflict between dimensions in latex and evince

If instead of removing that line I replace it with \usepackage[noframe]{showframe}, The dimensions and orientation are the same.

GTK
  • 1,510
  • 1
    No, it is 12pt (as you can see in the log, because of loading bk12.clo). And it is letterpaper and landscape, but the standard classes do not setup, e.g., the PDF lengths on there own, so you need, e.g., to load a package, that do, to see it. For example add \DocumentMetadata{} before \documentclass or add \usepackage{showframe} and maybe add in \csname f@size\endcsname{} on paper of size W=\the\paperwidth, H=\the\paperheight to the test text. – cabohah Aug 06 '23 at 06:37

1 Answers1

2

The are some wrong assumptions in your questions.

It is a strange feature of the standard classes not to setup backend specific lengths for the paper size. So, e.g., using PDFLaTeX to compile

\documentclass[a4paper]{book}
\begin{document}
Test
\end{document}

and

\documentclass[a4paper,landscape]{book}
\begin{document}
Test
\end{document}

both would result in PDFs with the same document information about page size, usually (using pdfinfo):

Page size:       595.276 x 841.89 pts (A4)

Nevertheless, the documents would differ, as you can see, if you add more text:

\documentclass[a4paper]{book}
\usepackage{lipsum}
\begin{document}
\lipsum
\end{document}

enter image description here

vs.

\documentclass[a4paper,landscape]{book}
\usepackage{lipsum}
\begin{document}
\lipsum
\end{document}

enter image description here

So not to see the correct size in the PDF does not mean, that book has not processed options letterpaper (which is already the default of book) or landscape.

To see the real paper size in the PDF, you could either use the pdfmanagement-testphase (see the manual for more information), adding \DocumentMetadata{} before \documentclass or load a package like hyperref or showframe.

If you'll look into the font information of the generated PDF you would see (using pdffonts): AKGSOO+CMR12. The part CMR12 means, that 12pt is used. And in the log file you would find, that bk12.clo is loaded, not bk10.clo. So your assumption about still using 10pt is also wrong.

To see the correct PDF dimension and also the used font size, I would recommend to use another test file:

\begin{filecontents}{courseguide.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{courseguide}
\RequirePackage{pgfopts}

%%%% PGF options \def\Course@classoptions{10pt}

%% Academic year \newcounter{AY} \setcounter{AY}{\the\year}

\pgfkeys{ /Course/.cd, %%% This is the academic year AY/.code=\setcounter{AY}{#1}, AY/.default=\the\year, .unknown/.code={ \message{mwe found unknown key: \pgfkeyscurrentname} \edef\Course@classoptions{\Course@classoptions,\pgfkeyscurrentname} } }

\ProcessPgfOptions{/Course}

\message{MWE Current \Course@classoptions: \Course@classoptions}

\LoadClass[\Course@classoptions]{book} \end{filecontents}

\documentclass[AY=2026,letterpaper,landscape,12pt]{courseguide} \usepackage{lipsum} \usepackage{showframe} \usepackage{printlen} \begin{document}

The academic year is \theAY-{\the\numexpr\theAY+1}.

\uselengthunit{in} The document uses paper of size W=\printlength{\paperwidth}, H=\printlength{\paperheight}.

The document font size is \csname f@size\endcsname.

\end{document}

enter image description here

As you see, the options are all processed as expected.

However, note, that options of book are processed in the order, they are defined not in the order they are used. So if you'd use:

\begin{filecontents}[overwrite]{courseguide.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{courseguide}
\RequirePackage{pgfopts}

%%%% PGF options \def\Course@classoptions{12pt}% CHANGED!!!

%% Academic year \newcounter{AY} \setcounter{AY}{\the\year}

\pgfkeys{ /Course/.cd, %%% This is the academic year AY/.code=\setcounter{AY}{#1}, AY/.default=\the\year, .unknown/.code={ \message{mwe found unknown key: \pgfkeyscurrentname} \edef\Course@classoptions{\Course@classoptions,\pgfkeyscurrentname} } }

\ProcessPgfOptions{/Course}

\message{MWE Current \Course@classoptions: \Course@classoptions}

\LoadClass[\Course@classoptions]{book} \end{filecontents}

\documentclass[AY=2026,letterpaper,landscape,10pt]{courseguide}% FONT SIZE OPTION CHANGED \usepackage{lipsum} \usepackage{showframe} \usepackage{printlen} \begin{document}

The academic year is \theAY-{\the\numexpr\theAY+1}.

\uselengthunit{in} The document uses paper of size W=\printlength{\paperwidth}, H=\printlength{\paperheight}.

The document font size is \csname f@size\endcsname.

\end{document}

You would still have 12pt, because book defines the font size options using:

\if@compatibility
  \renewcommand\@ptsize{0}
\else
  \DeclareOption{10pt}{\renewcommand\@ptsize{0}}
\fi
\DeclareOption{11pt}{\renewcommand\@ptsize{1}}
\DeclareOption{12pt}{\renewcommand\@ptsize{2}}

and therefore 12pt would be processed last always. So setting defaults in the definition of \Course@classoptions could be problematic.

cabohah
  • 11,455
  • Thanks! That helps a lot. I added an addendum to my question using your test file, for which there is (for me) a strange dependency on \usepackage{showframe} – GTK Aug 06 '23 at 08:47
  • 2
    @GTL I've explained that dependency already in my answer (and also in the comment). It is because, book does not set the backend dependent lengths. Some packages set them, e.g., hyperref, graphicx (and therefore showframe), typearea … and pdfmanagement-testphase. – cabohah Aug 06 '23 at 09:08
  • Thank you, I misunderstood the dependencies. – GTK Aug 06 '23 at 13:20