3

I tried creating my own class based on amsart, like this one:

% file: myamsart.cls
\ProvidesClass{myamsart}
\LoadClass[fleqn]{amsart}

However, the option fleqn has no effect:

% file: test.tex
%\documentclass[fleqn]{amsart}
\documentclass{myamsart}

\begin{document}
\[ x = x \]
\begin{equation}
  y = y
\end{equation}
\end{document}

Why does it work like this?

More generally, what is the difference between passing options with \documentclass and passing them with \LoadClass? Is there a general method to load a base class from cls file with the same effect as when using \docementclass?

5
  • Note that the fleqn option in amsart is implemented rather strangely. The declared option does nothing.
    – daleif
    Commented Nov 15, 2018 at 10:46
  • What do you mean by "does nothing"? It works with \documentclass[fleqn]{amsart}.
    – Alexey
    Commented Nov 15, 2018 at 10:49
  • 1
    Look in amsart.cls and you'll find \DeclareOption{fleqn}{}, but it does something "strange" with it later on in a non standard manner.
    – daleif
    Commented Nov 15, 2018 at 11:17
  • @daleif, "but it does something "strange" with it later on in a non standard manner" -- i think, i have to agree.
    – Alexey
    Commented Nov 15, 2018 at 13:43
  • kindly observe that amsart.cls was first written before 1995, and has been used in a production capacity since then. it wasn't designed to have options passed to it except through the option to the main \documentclass line, since nobody expected it to be used that way (really, that wasn't how things like this were thought of in 1995). there are numerous classes that \LoadClass{amsart}; all of them that i know of expect the fleqn option to be specified on the \documentclass line. it's too late to change that. Commented Nov 16, 2018 at 1:22

3 Answers 3

1

The fleqn option to amsart actually does nothing at \ProcessOptions time, because of

\DeclareOption{fleqn}{}%

The class uses a nonstandard way to set and use options. You can hack it by adding the option yourself.

\ProvidesClass{myamsart}
\expandafter\g@addto@macro\csname [email protected]\endcsname{,fleqn}
\g@addto@macro\@classoptionslist{,fleqn}
\LoadClass{amsart}

The first \g@addto@macro forcibly adds fleqn to the list of options myamsart.cls is loaded with, so as to make the tests \@ifclasswith{\@classname} follow the “true” branch. The second \g@addto@macro forcibly adds fleqn to the global options, so also amsmath (and all other packages) will see and honor it.

4
  • Could you explain a bit, please, how this hack works, or at least give links or references to documentation?
    – Alexey
    Commented Dec 15, 2018 at 20:35
  • @Alexey Added some explanations
    – egreg
    Commented Dec 15, 2018 at 22:44
  • @Alexey Yes, sorry for the typo
    – egreg
    Commented Dec 16, 2018 at 1:05
  • Thanks. To make your answer complete, could you add some link to an explanation of the difference between options of a class and global options? For example, this one, but maybe you know better.
    – Alexey
    Commented Dec 16, 2018 at 9:05
0

try:

\ProvidesClass{myamsart}
\PassOptionsToPackage{fleqn}{amsmath}
\LoadClass{amsart}
6
  • Indeed, this has some effect, but not the same as when just using \documentclass[fleqn]{amsart}.
    – Alexey
    Commented Nov 15, 2018 at 11:00
  • Why passing options with \documentclass is not equivalent to passing them with \LoadClass?
    – Alexey
    Commented Nov 15, 2018 at 11:03
  • 1
    @Alexey documentcass options are global and seen by all packages, but if you use options to LoadClass the options are just passed to the class, so you are relying on the class to pass on the option to any packages rather than using the global option mechanism. Commented Nov 15, 2018 at 11:32
  • 1
    you can use \LoadClassWithOptions{amsart} and then \documentclass[fleqn]{myamsart}
    – user2478
    Commented Nov 15, 2018 at 11:48
  • @Herbert, it is more crazy than this. After glancing at amsclass source documentation and a bit of experimenting, i observed that simply using \documentclass[fleqn]{myamsart} in my example makes the option have its effect. No need to change my myamsart.cls, no need to pass any options to amsart or to use \LoadClassWithOptions. This is not what i wanted and not how a class interface should work IMHO.
    – Alexey
    Commented Nov 15, 2018 at 13:48
0

After being prompted by daleif, I glanced into amscls source documentation, and noticed that the actual behaviour of fleqn option is implemented starting with

\@ifclasswith{\@classname}{fleqn}{%

Having already experimented with different combinations of commands and options proposed by Herbert, I decided to be bold and to simplify my myamsart.cls to

\ProvidesClass{myamsart}
\LoadClass{amsart}

and then to use it with

\documentclass[fleqn]{myamsart}

This produced flushed left equations exactly as when using \documentclass[fleqn]{amsart}. (However, this is not what I wanted to do, because I did not want to pass any options to myamsart.)

1
  • IMHO, this is not how a class interface should work.
    – Alexey
    Commented Nov 15, 2018 at 14:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .