Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I do not undestand how to pass options to the parent class when writting a child class. I tried several possibilities but I never get flush left aligned equations.

I do understand the difference between LoadClass and LoadClassWithOptions but I think this is not the problem here. The uncommented lines correspond to what I understand from the document clsguide.pdf but it does not work.

\RequirePackage{filecontents}

% my class file
\begin{filecontents}{baz.cls}
\PassOptionsToClass{fleqn}{article}
\ProcessOptions\relax
%\LoadClass[fleqn]{article}
\LoadClass{article}
%\LoadClassWithOptions{article}
\RequirePackage{amsmath}
\end{filecontents}

\documentclass{baz} 
%\documentclass[fleqn]{baz} 

\usepackage{lipsum}

\begin{document}
\lipsum[1]
\begin{equation*}
    e^{i\pi} + 1 = 0
\end{equation*}
\lipsum[2]
\end{document}
share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

The confusion in this example is coming from the fact that it is really the amsmath package that needs to know about the fleqn option. As it stands you are passing no options to amsmath. One working set up would be:

baz.sty:

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\LoadClass[fleqn]{article}
\RequirePackage[fleqn]{amsmath}

tex file:

\documentclass[a4paper]{baz} 

\usepackage{lipsum}

\begin{document}
\lipsum*[1]
\begin{equation*}
    e^{i\pi} + 1 = 0
\end{equation*}
\lipsum[2]
\end{document}

Sample output

Here you see additional options being passed on to the class, which is loaded additionally with fleqn option. The package amsmath is loaded with the fleqn option too. In this case, it may well be the package option is unnecessary, but this mimics the effect of

\documentclass[fleqn]{article}
\usepackage{amsmath}
share|improve this answer
    
Ok, thus it was a bad example ... Is my code right for a more standard options ? and how can I be sure that options added from the documentclass will overwrite options defined into the class file –  Ger Mar 11 '13 at 14:20
    
The example is not bad - this is a common gotcha when converting a preamble to a class, you have to make sure appropriate options get passed down to appropriate packages. For options that are only for the class, your example is fine (but the \ProcessOptions is redundant), but I would probably use the shorter syntax \LoadClass[option]{class} –  Andrew Swann Mar 11 '13 at 14:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.