Document ClassesOptional Arguments after mandatory arguments like LoadClass

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
lgassman
Posts: 3
Joined: Tue May 26, 2015 2:54 am

Optional Arguments after mandatory arguments like LoadClass

Post by lgassman »

Hi!

I'm writing a package to help to write classes. A feature of my package is to build automatically the list of options for \LoadClass method call. I want to build a LoadClass method wrapper in order to make the list of options and delegate to LoadClass. The \LoadClass method have optional arguments before and after mandatory arguments: \LoadClass[<options>]{<className>}[<date>]. The problem is that I didn't find documentation about how to build this kind of commands. I always found how to define optional arguments just before the mandatory arguments. I wish to keep the same order used by \LoadClass. Something like \MyLoadClass{<className>}[<date>] and implement it like \LoadClass[\buildOptions]{#1}[#2]

I will be greatful for any help.

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

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: Optional Arguments after mandatory arguments like LoadCl

Post by Johannes_B »

Hi and welcome,

there is clsguide that gives a lot of information on package and class writing. Looking at how the standard classes and memoir do stuff might be a good idea as well. KOMA-classes use a key-val approach.

Usually, you simply pass options to the loaded class, instead of giving a list with the mandatory argument.

If you share some real code, maybe even on github or similar, showing what you are trying to achieve, we might find a solution more quickly.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
lgassman
Posts: 3
Joined: Tue May 26, 2015 2:54 am

Optional Arguments after mandatory arguments like LoadClass

Post by lgassman »

Thanks for your reply!

I read the cls guide, however this guide shows how to use LoadClass command but do not how to redefine it.

I know that usually We define a comma separated list at moment of load the class. But the feature of my package is to define dinamically this list.

I didn't know KOMA-classes. I reviewed it after your reply. I prefer do not use this approach because the standard LaTeX class uses a different style. I want to keep the standard class style as much to be possible.

The KOMA-scripts redefines LoadClass command, but apparently it does not use the date argument. Is it true?. This is the code that I found:
\renewcommand*{\LoadClass}[2][]{%
\begingroup
\edef\@tempc{##2}\def\@tempb{article}%
\ifx\@tempc\@tempb
\let\LoadClass\sd@saved@LoadClass
\def\@tempc{scrartcl}%
\fi
\edef\@tempc{%
\noexpand\endgroup\noexpand\sd@saved@LoadClass[{##1}]{\@tempc}}%
\@tempc
}


This is my real code in the package:
\newcommand{\LoadClassWithExclusiveOptions}[2][]{%
\LoadClass[\@ExclusiveOptionsList]{#2}[#1]%
}%


The user of my package is a cls file. For example:
\LoadClassWithExclusiveOptions[2015/5/25]{article-subclass}

But a class developer usually does:
\LoadClass{article-subclass}[2015/5/25]
Please take note about the order of parameters!

Then, I want to change my package code in order to a cls file do:
\LoadClassWithExclusiveOptions{article-subclass}[2015/5/25]

Thanks in advance!
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Optional Arguments after mandatory arguments like LoadClass

Post by Johannes_B »

KOMA does not redefine the generic LoadClass. What you have seen is code to provide the documentation of the bundle.


It seems you are looking for the powers of package xparse that make it very easy to use any given number of mandatory and optional arguments.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply