% \iffalse meta-comment %<*internal> \iffalse % %<*internal> \fi \def\nameofplainTeX{plain} \ifx\fmtname\nameofplainTeX\else \expandafter\begingroup \fi % %<*install> \input docstrip.tex \keepsilent \askforoverwritefalse \preamble \endpreamble \ifx\fmtname\nameofplainTeX \generate{ \file{\jobname.sty}{\from{\jobname.dtx}{copyright,package}} } \fi % %\endbatchfile %<*internal> \ifx\fmtname\nameofplainTeX \expandafter\endbatchfile\else \expandafter\endgroup\fi % %<*copyright> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% spdef.sty package, 2012-01-22 %% %% Copyright (C) 2012 D. P. Story %% %% dpstory@uakron.edu %% %% %% %% This program can redistributed and/or modified under %% %% the terms of the LaTeX Project Public License %% %% Distributed from CTAN archives in directory %% %% macros/latex/base/lppl.txt; either version 1 of the %% %% License, or (at your option) any later version. %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % %\NeedsTeXFormat{LaTeX2e} %\ProvidesPackage{spdef} % [2012/08/20 v1.2 Defines a switch for smartphone] %<*driver> \documentclass{ltxdoc} \begin{document} \DocInput{\jobname.dtx} \end{document} % % \fi % %\GetFileInfo{\jobname.sty} % %\title{The \textsf{spdef} Package} %\author{D. P. Story} %\date{Released \today} % %\maketitle % %\StopEventually{^^A % \PrintChanges % \PrintIndex %} % % \begin{macrocode} %<*package> % \end{macrocode} % \textbf{Description and Usage.} This is a short package to create the % \cs{ifsmartphone} switch. The package is designed to be introduced early in the % file, even before \cs{documentclass}. I use \cs{RequirePackage}, like so. %\begin{verbatim} % \RequirePackage[ph]{spdef} % \documentclass[\ifsmartphone12pt\else10pt\fi]{article} % \usepackage[fleqn]{amsmath} % \usepackage[pdf,myconfigi,nopoints,answerkey]{eqexam} %\ifsmartphone % \usepackage[smartphone,nomaketitle,useforms]{aeb_mobile} %\fi %\end{verbatim} % When you use \cs{usepackage}, there is an error which says no class file has been % used, but apparently it is file to have \cs{RequirePackage} before a class file; % consequently, it can be used to adjust the point size of the document. % % Version 1.2 of \textsf{aeb\_mobile} works better with \textsf{spdef}. Now if % \cs{ifsmartphone} is false, \textsf{aeb\_mobile} does an early exit; consequently, % surrounding it with the construct \cs{ifsmartphone}\dots\cs{fi} is no longer needed: %\begin{verbatim} % \RequirePackage[ph]{spdef} % \documentclass[\ifsmartphone12pt\else10pt\fi]{article} % \usepackage[fleqn]{amsmath} % \usepackage[pdf,myconfigi,nopoints,answerkey]{eqexam} % \usepackage[smartphone,nomaketitle,useforms]{aeb_mobile} %\end{verbatim} % See Section~\ref{phOpts} for more details and additional options. % % Another feature of this package is the automatic creation of Boolean switches. If you say %\begin{verbatim} % \RequirePackage[use=myswitch]{spdef} %\end{verbatim} %a new switch \cs{ifmyswitch} is created and given a value of true. If you say %\begin{verbatim} % \RequirePackage[!use=myswitch]{spdef} %\end{verbatim} %a new switch \cs{ifmyswitch} is created and given a value of false. See % Section~\ref{s:onthefly} for more details. % % Of course, if you do not need to introduce \textsf{spdef} before the % class in included, you can use the standard \cs{usepackage} command. % % \section{The Code} % We begin by requiring \texttt{kvoptions}, this package does not test the the presence % of a class file, so we can use it. It allows us to define key-values as options of the % package. % \begin{macrocode} \RequirePackage{kvoptions}[2009/07/21] % \end{macrocode} % The package is primarily intended for use with the \textsf{aeb\_mobile} % package, for formatting document for the \textsf{smartphone}, but I've since developed % other applications of a package that is introduced early, see the definition % of the \texttt{use} key. % \begin{macrocode} \newif\ifsmartphone \smartphonefalse % \end{macrocode} % \section{\textsf{smartphone} options}\label{phOpts} % We offer two options \texttt{ph} and \texttt{pa}, additional options for other devices may be % defined. %\begin{itemize} % \item \texttt{ph} sets the \cs{ifsmartphone} switch to true. The name \texttt{ph} % stands for \underbar{ph}one. % \item \texttt{pa} sets the \cs{ifsmartphone} switch to false. % The name of the option, \texttt{pa}, stands for \underbar{pa}per. %\end{itemize} % \begin{macro}{ph} % Option for phone: sets the switch \cs{ifsmartphone} to \texttt{true}. % \begin{macro}{pa} % Option for paper: sets the switch \cs{ifsmartphone} to \texttt{false}. % \begin{macrocode} \DeclareVoidOption{ph}{\smartphonetrue} \DeclareVoidOption{pa}{\smartphonefalse} % \end{macrocode} % It's easy enough, lets do negatives of the two option above. \DescribeMacro{!ph}\texttt{!ph} % is the same as \texttt{pa} and \DescribeMacro{!pa}\texttt{!pa} is the same as \texttt{ph}. % \begin{macrocode} \DeclareVoidOption{!ph}{\smartphonefalse} \DeclareVoidOption{!pa}{\smartphonetrue} % \end{macrocode} % % \section{Defining Boolean switches on the fly}\label{s:onthefly} % Based on my own work, I've added in two more options \texttt{use} % and \texttt{!use}. Suppose we want to create a switch, say \cs{ifforinstr}, % we can say, %\begin{verbatim} % \usepackage[use=forinstr]{spdef} %\end{verbatim} % The \textsf{spdef} package would create a new Boolean \cs{ifforinstr} and assign it a % value of \texttt{true}. If you want to compile the document with \cs{ifforinstr} having % a value of \texttt{false}, we would modify the above options like so, %\begin{verbatim} % \usepackage[!use=forinstr]{spdef} %\end{verbatim} % \begin{macro}{use} % The \texttt{use=} is a way to define/use a switch early in the % compiling of the document, even before the document class is declared. % The code below creates the switch % \cs{if}, and sets it to \texttt{true}. The document that uses % this switch should have this code in it: %\begin{verbatim} %\@ifundefined{if}{\newif\if\false}{} %\end{verbatim} % We can set this switch to \texttt{true} through the \textsf{spdef} package, otherwise, its % value is \texttt{false}. % \begin{macro}{!use} % Given my last remarks on the \texttt{use} key, as a convenience, we declare the option \texttt{!use}. % It does the same as \texttt{use}; it creates the switch but sets it to \texttt{false}. % That way, you can say \texttt{use=useendnotes} and \cs{ifuseendnotes} is \texttt{true}, % or, by prefixing \texttt{use} with an \texttt{!}, like so, \texttt{!use=useendnotes}, % \textsf{spdef} defines/sets \cs{ifuseendnotes} to \texttt{false}. % \begin{macrocode} \define@key{spdef}{use}{\@ifundefined{#1}{% \expandafter\newif\csname if#1\endcsname}{}\csname#1true\endcsname} \define@key{spdef}{!use}{\@ifundefined{#1}{% \expandafter\newif\csname if#1\endcsname}{}\csname#1false\endcsname} % \end{macrocode} % If the key is not used, back in the document that uses the switch, %\begin{verbatim} %\@ifundefined{if}{\newif\if\false}{} %\end{verbatim} % will set this value to \texttt{false}; in this case, you need to explicitly set % the value of the switch yourself. % \end{macro} % \end{macro} % \begin{macrocode} \ProcessKeyvalOptions{spdef} % \end{macrocode} % \end{macro} % \end{macro} % \DescribeMacro{\ifsp} \cmd{\ifsp}\meta{TRUE}\meta{FALSE} is a convenience command for the \cs{ifsmarphone} switch. It takes % two arguments, the first one if the \cs{ifsmartphone} is true, the second one if not. % \begin{macrocode} \def\ifsp@default#1#2{\ifsmartphone \expandafter\def\csname sp@next\endcsname{#1}\else \expandafter\def\csname sp@next\endcsname{#2}\fi\sp@next} \def\ifsp@expand#1#2{\ifsmartphone#1\else#2\fi} \let\ifsp\ifsp@default % \end{macrocode} % \DescribeMacro{\expexe} is used to expand optional arguments that can be controlled % using the switches defined by the \texttt{use} option. For example %\begin{verbatim} % \expexe{\usepackage[designiv\ifbw,forpaper\fi]{web}} %\end{verbatim} % A \cs{noexpand} is inserted before \texttt{\#1} and is intended to suppress the % expansion of the \cs{usepackage} or \cs{documentclass}. % \changes{v1.2}{2012/08/20}{Added \cs{expexe}} % \begin{macrocode} \newcommand{\expexe}[1]{\edef\sp@expexe{\noexpand#1}\sp@expexe} % \end{macrocode} % \begin{macrocode} % % \end{macrocode} %\Finale