2

Is there a way to get some of the functionality of a class without the document being based on that class?

I use the exam class a good bit to typeset exams and problem sets. I'm trying to format a book (still not sure whether book, amsbook, tufte-book, or whatever class) and I'd like to include exercises. It seems (maybe just because I'm used to it) that the exam class handles exercises in the way I would like, so I'd really like to use its tools for setting up questions and answers, but I don't want the entire book to be in the exam class.

Timothy
  • 23
  • 1
    You can copy the relevant code into your own .sty file and just load that. – jon Oct 10 '15 at 21:04
  • You can copy parts of the class code (but mind the copyright issue) to a package or preamble of your own -- the exam.cls is based on article.cls, so it's possible to keep most of the exercise specific stuff, but this requires a check. Some classes define importer .sty files to provide the functionality without adapting the outer class features. In principle, any package can modify the outer class behaviour –  Oct 10 '15 at 21:04
  • The greatest problem in my point of view would be the class options which drive the exam macros behaviour (somehow). You should specify what should be used from exam.cls at all –  Oct 10 '15 at 21:20
  • 1
    you can save exam.cls as myexam.sty change line \ProvidesClass{exam} into \ProvidesPackage{myexam} then delete line \LoadClass{article} I think this will be fine. – touhami Oct 10 '15 at 21:45
  • @touhami: Not quite -- the options aren't handled correctly (in my point of view) and there are a lot of geometry related settings done in exam.cls which are still active unless \usepackage{geometry} is used with a store/save way. –  Oct 10 '15 at 21:59
  • @ChristianHupfer I don't think so, no problem with options. Indeed the margins and text area are changed but I think geometry package is universal now a day so one can load it after myexam and set the margins proprely. in my point of view the important problem is related to somefeature that oblige the user to use questions environment only once by document. – touhami Oct 10 '15 at 22:13
  • 1
    @touhami: Yes, but perhaps that restriction could be patched out. But the question itself isn't very clear so far –  Oct 10 '15 at 22:15
  • 1
    @touhami: You deleted the link ;-) Well, in fact together with that link and the geometry package it's much better to keep exam.cls as the underlying class as long as \chapter isn't needed –  Oct 10 '15 at 22:19
  • What exavtly do you need? The exam class takes care of automated headers (not needed that way in a book), summing up points of a sheet (not needed that way in a book), hiding/printing of answers (not needed that way in a book) and numbering questions (very, very easy). You can have a look at packages exsheets and tasks that might be handy for your project. I don't see any point i fiddling with exam here, it will be a constant head-ache for you. – Johannes_B Oct 11 '15 at 08:22
  • @Johannes_B: There's plenty of stuff in exam that I don't care about for the book: points and headers as you point out. I do want questions and answers together rather than in separate files. Since I won't actually want to print them together in the book, exam might not be the best way to do that.

    The only clear-cut benefits of exam over alternatives are: (a) I'm already familiar with it, and (b) It will be easy to share things between the book and exams / problem sets. (b) is actually a pretty big benefit.

    – Timothy Oct 11 '15 at 20:08
  • 1
    If you want to print questions and answers separatly, you might be interested in How to defer content to a later part of the document? ;-) – Johannes_B Oct 11 '15 at 20:20

1 Answers1

1

The basic problems are \ProvideClass and \Loadclass -- those must be deactivated. Since those are used by .cls files only, following .sty won't get in trouble.

More work is to be done for the special options (not done yet).

I don't claim this will work in any case!

  • exam.cls changes several lengths
  • exam.cls changes page styles

etc.

In principle, it should be possible to catch those changes but perhaps it's really easier to copy the question etc. related code to an own .sty file (and ask the class author beforehand ;-))


examimport.sty

\ProvidesPackage{examimport}

\RequirePackage{xparse}

\RenewDocumentCommand{\ProvidesClass}{mO{}}{%
}

\RenewDocumentCommand{\LoadClass}{O{}mO{}}{%
}

\input{examcopy.cls}

\endinput

Driver file (the example for \begin{questions}... is take from the exam documentation.

\documentclass{article}
\usepackage{examimport}

\begin{document}

\begin{questions}
\question[10]
Why is there air?
\question[15]
How much wood would a woodchuck chuck if a woodchuck could chuck
wood?
\question[10] Compute $\displaystyle\int_0^1 x^2 \, dx$.
\end{questions}


\end{document}
  • 1
    It might be polite to ask the author, but there is no need to, that is a basic reason for the LPPL licence (under which exam is distributed) anyone can take any part (or all) of the code and use in another package. – David Carlisle Oct 10 '15 at 22:33
  • @DavidCarlisle I'd be astonished if somebody asked me for permission when they only planned to use the stuff privately. If they were going to publish a derivative, sure - it would be nice to ask, though not, as you say, required - but for personal use? I wouldn't really know how to respond. 'So what?' seems rude! – cfr Oct 10 '15 at 22:43
  • @cfr yes agreed, the politeness comment was just a hook to the answer's comment saying that you should ask. The point of my comment was that asking is never necessary. – David Carlisle Oct 10 '15 at 22:55
  • @DavidCarlisle Oh, I know. I was asserting a somewhat stronger claim: that, for private use, politeness did not require it either. – cfr Oct 10 '15 at 22:57
  • @DavidCarlisle: You know me... I am not polite only if it concerns your packages :-P –  Oct 11 '15 at 07:30
  • @ChristianHupfer: Thanks! But, sadly, no. It doesn't work. For a barest-bones document it does, but as soon as I put in \chapter{Introduction}, it chokes with: \begin{fullwidth} on input line [line for \chapter] ended by end{list}. – Timothy Oct 11 '15 at 20:14
  • @Timothy: \chapter{Introduction} works for me without problems –  Oct 11 '15 at 20:17
  • @ChristianHupfer: Huh! Goes to show I should think more about having a minimal working example. When I used \class{tufte-book} I got the error. Using \class{book}, I don't. I'll try this out some more, thanks! – Timothy Oct 11 '15 at 20:38
  • @Timothy: I used book (Personally, I am not very fond of tufte) –  Oct 11 '15 at 20:38
  • @ChristianHupfer: Thanks! This seems to be doing the trick nicely. – Timothy Oct 16 '15 at 15:59