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.

Werner
  • 603,163

1 Answers1

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.

Werner
  • 603,163