summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/aeb_mobile/spdef.dtx
blob: 1ea49d5551f73e002bea48a4c754efbe014c5f86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
% \iffalse meta-comment
%<*internal>
\iffalse
%</internal>
%<*internal>
\fi
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%<*install>
\input docstrip.tex
\keepsilent
\askforoverwritefalse
\preamble
\endpreamble
\ifx\fmtname\nameofplainTeX
\generate{
  \file{\jobname.sty}{\from{\jobname.dtx}{copyright,package}}
}
\fi
%</install>
%<install>\endbatchfile
%<*internal>
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile\else
  \expandafter\endgroup\fi
%</internal>
%<*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.      %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%</copyright>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{spdef}
%<package> [2012/08/20 v1.2 Defines a switch for smartphone]
%<*driver>
\documentclass{ltxdoc}
\begin{document}
 \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \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=<switch>} 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<switch>}, and sets it to \texttt{true}. The document that uses
% this switch should have this code in it:
%\begin{verbatim}
%\@ifundefined{if<switch>}{\newif\if<switch>\<switch>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<switch>}{\newif\if<switch>\<switch>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}
%</package>
%    \end{macrocode}
%\Finale