Option to documentclass{} using a class .cls

I have a problem doing my own class in latex. I want to be able to pass options inside the \documentclass{my_own_class} of my .tex document, and I thought it would be easy looking at examples on internet, but I cannot figure out how it works.

Here is a very simple example. My .cls, called baz.cls, is the following:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{baz}

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

\RequirePackage[T1]{fontenc} \RequirePackage[utf8]{inputenc}


Then the .tex file is the following:

\documentclass[12pt,twocolumn]{baz}

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


I would like to be able to change the font size and/or the option of one or two columns, and maybe more options. But as you can see, or at least it is like that for me, nothing happens when I try with 12pt and twocolums. The result is a 10pt and onecolumn document, which the default options for the article class. If I try \LoadClass[12pt]{article}, the result is indeed in 12pt, but again I cannot change it.

Does anybody know how to proceed ?

• Try to use the \DeclareOption* and \ProcessOptions before \LoadClass. – TeXnician Feb 20 '17 at 18:18

Your problem is that you load the class which configures some options for itself. Afterwards you tell it that you want it to process some extra options. The point for you is just to swap the order:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{baz}

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

\RequirePackage[T1]{fontenc} \RequirePackage[utf8]{inputenc}

• I have a question though. That way Latex takes the options of the package before loading the package itself. I thought you should first load the package, then change the options if necessary. I was wrong apparently – antoine Feb 20 '17 at 21:05
• @antoine The command \PassOptionsToSomething works another way: It gives the options to the package as soon as this is loaded the first time. To set options later on most packages have distinct commands. – TeXnician Feb 20 '17 at 21:07