7

I want to build a package that can optionally typeset line in double-space. Something like this:

\ProvidePackage{mypackage}
% actual functional codes

Then I can use the package in this way:

\usepackage[doublespc=yes]{mypackage}

So that all line will be typeset in double-space. If I omit that optional argument in the preamble, then all line will be typeset in single-space.

3
  • Welcome to TeX.sx! Apr 4, 2013 at 6:57
  • That sounds like a class (design) not package (functionality) thing
    – Joseph Wright
    Apr 4, 2013 at 7:07
  • Is the keyval part here important, and are you going to have several keyval option? If you only have one, 'faking' keyval may be the easiest approach.
    – Joseph Wright
    Apr 4, 2013 at 7:15

1 Answer 1

9

Here is a basic implementation, following the guide LaTeX 2e for class and package writers (section 4.3 Option declaration, p 18):

enter image description here

\documentclass{article}
\usepackage{filecontents}% http://ctan.org/pkg/filecontents

\begin{filecontents*}{mypackage.sty}
\ProvidesPackage{mypackage}
\newif\if@doublespace
\DeclareOption{doublespace}{\@doublespacetrue}
\ProcessOptions
\if@doublespace\RequirePackage{setspace}\doublespacing\fi
\endinput
\end{filecontents*}

\usepackage[doublespace]{mypackage}
\begin{document}
Here is some

text in two paragraphs.
\end{document}

The package mypackage.sty declares an option doublespace which sets the condition \@doublespacetrue. If this is set to true, it \RequiresPackage{setspace} and sets \doublespacing.

1
  • Great! It's exactly what I want. A nice template for optional arguments. Apr 4, 2013 at 7:18

You must log in to answer this question.

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