[Tex/LaTex] Option to documentclass{} using a class .cls

document-classes

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}

\LoadClass{article}
\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 ?

Best Answer

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
\LoadClass{article}

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