Document ClassesPassing Option to a new Class

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
jamesm
Posts: 13
Joined: Sun Aug 09, 2009 5:01 pm

Passing Option to a new Class

Post by jamesm »

Hi

I'm writing a new class, based on 12pt article, but with one option which I'll call [large] which will load [17pt]{extarticle}. Thus:

Near the start of my class I have
\LoadClass[12pt]{article}
followed be a load of minor modifications and new definitions.

But if I start my latex file with \documentclass[large]{myclass} I need the class to execute instead
\LoadClass[17pt]{extarticle}

I have The LaTeX Companion in front of me, but I can't figure out how to do this. Any suggestions?

Thanks for any help

James
Last edited by jamesm on Tue Apr 05, 2011 1:47 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Passing Option to a new Class

Post by localghost »

I suggest to take a look at the document "LaTeX2e for Class and Package Writers", also know as the »Class Guide«.


Thorsten
jamesm
Posts: 13
Joined: Sun Aug 09, 2009 5:01 pm

Re: Passing Option to a new Class

Post by jamesm »

I had a look at the class guide but it doesn't seem to solve my problem. I can't see anywhere how to choose between two different document classes.

I want something equivalent to,

if option = large then
\LoadClass[17pt]{extarticle}
else
\LoadClass[12pt]{article}
end if

But I don't see how to do that.

James
User avatar
nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

Passing Option to a new Class

Post by nlct »

Something like the following should work (although I think extarticle also allows 12pt as an option):

Code: Select all

Code, edit and compile here:
\NeedsTeXFormat{LaTeX2e}
\newcommand*\myfontsize{12pt}
\newcommand*\parentclass{article}
\DeclareOption{large}{%
\renewcommand*\myfontsize{17pt}%
\renewcommand*\parentclass{extarticle}%
}
\DeclareOption{standard}{%
\renewcommand*\myfontsize{12pt}%
\renewcommand*\parentclass{article}
}
\ProcessOptions
\LoadClass[\myfontsize]{\parentclass}
\endinput
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Regards
Nicola Talbot
jamesm
Posts: 13
Joined: Sun Aug 09, 2009 5:01 pm

Re: Passing Option to a new Class

Post by jamesm »

Brilliant! Thanks Nicola.

James

ps Indeed, extarticle does allow the 12pt option. However, the 17pt option is only going to be used on rare occasions, so I wanted to avoid using extarticle unless necessary in case some users didn't have it installed.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Passing Option to a new Class

Post by localghost »

Then please mark the topic (not only the last post) accordingly as written in Section 3 of the Board Rules (to be read before posting) and as you already have been asked for.
Post Reply