2

I am trying to extend my class by supporting multiple paper sizes, and therefore adding some options by

\DeclareOption{a5paper}{% Paper size: 148mm x 210mm
%   \SBpaperAfivetrue
%   \SBpaperAsixfalse
}

My whole document as a MWE looks like

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{Liederbuch}[2016/02/04 version 1.00 Decoration and placement of songs]
\typeout{Book subclass: Liederbuch 2016/02/04 v 1.00}
% --- Class structure: declaration of options part
% --- 
% This class extends the book class
% Read all the documentclass options; pass them to book
\DeclareOption*{\InputIfFileExists{\CurrentOption.min}{}{%
    \PassOptionsToClass{\CurrentOption}{book}}}

% --- Class structure: execution of options part
% --- 
\ProcessOptions \relax

% --- Class structure: declaration of options part
% ---
\LoadClass{book}
%Page layout
%\RequirePackage{xcolor}
\RequirePackage{gtrcrd}
\RequirePackage{stackengine}
\RequirePackage{graphicx}
\RequirePackage[utf8]{inputenc} 
\RequirePackage[T1]{fontenc} 
\RequirePackage[dvipsnames]{xcolor} 
\RequirePackage[object=vectorian]{pgfornament}
\usetikzlibrary{calc}
\RequirePackage[left=1in, right=1in, top=1in, bottom=1in]{geometry}
\RequirePackage{fancyhdr}

% --- Page size
% --- Option declaration for page size
\DeclareOption{a5paper}{% Paper size: 148mm x 210mm
%   \SBpaperAfivetrue
%   \SBpaperAsixfalse
}

imported in a document as

\documentclass[8pt,a6paper]{Liederbuch}
%\usepackage[utf8]{inputenc}
\begin{document}
Hallo 2
\newpage
Test
\newpage
Test 3
\end{document}

If I leave the \DeclareOption, then I get the error

The package `' is defective.
It attempts to load `pdftexcmds' in the options section, i.e.,
between \DeclareOption and \ProcessOptions.

If I remove it, everything is fine. If I move the \ProcessOption option after the declaration, I get even more errors. What am I doing wrong?

9
  • You have \DeclareOption{a5paper}{...} long after \ProcessOptions.
    – egreg
    Feb 14, 2016 at 11:57
  • If I move it afterwards, then I get ! LaTeX Error: \RequirePackage or \LoadClass in Options Section.
    – arc_lupus
    Feb 14, 2016 at 12:00
  • You have to place it before \ProcessOptions
    – egreg
    Feb 14, 2016 at 12:01
  • However, \SBpaperAsixfalse will throw an error, if a5paper is used.
    – egreg
    Feb 14, 2016 at 12:04
  • 2
    Declare options, process options, then load packages.
    – Johannes_B
    Feb 14, 2016 at 12:13

1 Answer 1

6

The correct order should be

\DeclareOption{<option>}{<code>} % any number of them
\ExecuteOptions{<option list>} % optional
\ProcessOptions\relax

\LoadClass{<class>}

After this line, other setup can be added, particularly addition of packages.

0

You must log in to answer this question.

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