2

I'm writing a document class based on the book class. In this class I have some code as below:

\RequirePackage[total={10cm,18cm},paperwidth=16cm, paperheight=23cm]{geometry} \RequirePackage[cross,center,noinfo,a4]{crop} 

I want to define an option for my class, say, nocrop so that when I use it, the above code change into the code below:

\RequirePackage[total={10cm,18cm}]{geometry} %\RequirePackage[cross,center,noinfo,a4]{crop} 

In other words, I want the crop package to be exempted from being run and the paperwidth=16cm, paperheight=23cm to be deleted.

Is this possible? if yes, how?
Here is my MWE:

\RequirePackage{filecontents} % my class file \begin{filecontents}{myclass.cls} \NeedsTeXFormat{LaTeX2e} \ProvidesClass{myclass} \DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}} \ProcessOptions \LoadClass{book} \RequirePackage[total={10cm,18cm},paperwidth=16cm, paperheight=23cm]{geometry} \RequirePackage[cross,center,noinfo,a4]{crop} \endinput \end{filecontents} \documentclass{myclass} \usepackage{lipsum} \begin{document} \lipsum[1] \end{document} 

(I'm using XeLaTeX on a Windows machine, if it helps.)

1 Answer 1

4

A switch (\ifmyclass@crop) can be defined, that is set via the option and asked later to include the right set of packages/options:

\RequirePackage{filecontents} % my class file \begin{filecontents}{myclass.cls} \NeedsTeXFormat{LaTeX2e} \ProvidesClass{myclass} \newif\ifmyclass@crop \myclass@croptrue % default \DeclareOption{nocrop}{\myclass@cropfalse} \DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}} \ProcessOptions \LoadClass{book} \ifmyclass@crop \RequirePackage[total={10cm,18cm},paperwidth=16cm,paperheight=23cm]{geometry} \RequirePackage[cross,center,noinfo,a4]{crop} \else \RequirePackage[total={10cm,18cm}]{geometry} \fi \endinput \end{filecontents} \documentclass{myclass} \usepackage{lipsum} \begin{document} \lipsum[1] \end{document} 
2
  • Thanks for your answer, but when I use ‎‎\documentclass[nocrop]‎{myclass}, I get two errors: ! File ended while scanning use of ^^M. and ! Emergency stop.. Commented Jul 10, 2014 at 18:03
  • 2
    @VahidDamanafshan: Two minutes after the first post, I have added a missing ] in RequirePackage[total={10cm,18cm}]{geometry}. Perhaps your browser has showed you the old version. Commented Jul 10, 2014 at 18:08

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.