summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/bropd/bropd.dtx
blob: d2d2282bb86bd87c4d675e84c6da9d064e978cd5 (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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
% \iffalse The license starting on line four applies to this file
%<*batchfile>
{\obeylines\obeyspaces \gdef\thepreamble{

Copyright 2014 by Benjamin Tatlock

This work may be distributed and/or modified under the conditions of the
LaTeX Project Public License, either version 1.3 of this license or (at your
option) any later version. The latest version of this license is in
  http://www.latex-project.org/lppl.txt
and version 1.3 or later is part of all distributions of LaTeX version
2005/12/01 or later.

This work has the LPPL maintenance status `maintained'.

The Current Maintainer of this work is Benjamin Tatlock.

This work consists of the file bropd.dtx and the derived files bropd.sty and
bropd.pdf.
}}
\begingroup
\input docstrip
\keepsilent
\expandafter\preamble\thepreamble\endpreamble
\askforoverwritefalse
\generate{\file{bropd.sty}{\from{bropd.dtx}{}}}
\endgroup
\documentclass{ltxdoc}
\usepackage{bropd,color,ifpdf}
\DoNotIndex{\def}
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\GetFileInfo{bropd.sty}
\title{The \textsf{bropd} package\thanks{This documentation corresponds to
\textsf{bropd}~v\fileversion, dated \filedate.}}
\def\auth{Benjamin Tatlock}
\author{\auth\thanks{\texttt{\kern2.5em\textcolor{white}
{\char101\char109\char97\char105\char108}\kern-5em\auth\kern-4em\char46\kern
3.5em\char64\textcolor{white}{bropd}\kern-1em\char108\kern-1em\char105\ 
\kern-2em\char109\char97\kern1em\char46\textcolor{white}
{\char111\char114\char103}\kern-2em\ com}}}
\begin{document}
\maketitle
\begin{abstract}
The \textsf{bropd} package simplifies the process of writing differential
operators and brackets in \LaTeX. The commands facilitate the easy manipulation
of equations involving brackets and allow partial differentials to be expressed
in alternate forms.
\end{abstract}
\section{Introduction}
The \textsf{bropd} package introduces a bracket command that automatically
selects parentheses, square brackets or braces as appropriate based on the
number of brackets. As such, brackets can be freely added and removed without
alterations to the rest of an equation. Commands for typing ordinary and partial
differentials are also created, with two optional concise forms for partial
derivatives. Equations can therefore be written in a standard form and their
style altered globally at a later date.
\section{Usage}
This section outlines the use of the three commands provided by the
\textsf{bropd} package.
\subsection{Brackets}
The bracket command replaces \verb|\left(| and \verb|\right)| with the single
command, \verb|\br| to produce brackets in a math environment. The input
\verb|\br{x}| produces\[\br{x}.\]When nested, the type of bracket is determined
automatically, for example, \verb|r=\br{\br{x-a}^2+\br{y-b}^2}^{\frac{1}{2}}|
results in\[r=\br{\br{x-a}^2+\br{y-b}^2}^{\frac{1}{2}}.\]
\subsection{Differential operators}
\subsubsection{Ordinary differential}
The \verb|\od| command produces ordinary differentials, such as \verb|\od{y}{x}|
which is displayed as\[\od{y}{x}.\]The order of the differential can be
specified as an optional argument, illustrated here with the command
\verb|\od[2]{u}{x}=-\omega^2u| which results in\[\od[2]{u}{x}=-\omega^2u.\]When
using \verb|\od| with a sans-serif font, the package should be loaded with the
optional argument \verb|sans|.
\subsubsection{Partial differential}The command \verb|\pd| follows the same form
as \verb|\od|, but instead produces partial differentials. By default,
\verb|\pd{u}{t}=6u\pd{u}{x}-\pd[3]{u}{x}|
produces\[\pd{u}{t}=6u\pd{u}{x}-\pd[3]{u}{x}.\]Loading the package with the
option \verb|pdshort| results in an alternative format for partial
differentials:\[u_t=6uu_x-u_{xxx}\]If the optional argument is not a positive
integer, the default form is reverted to, as with \verb|\pd[n]xy|:\[\pd[n]xy\]A
second alternative form is produced when the option \verb|pdalt| is
specified:\[\partial_tu=6u\partial_xu-\partial_{xxx}u\]The syntax for partial
differentials is extended to allow higher order terms such
as\[\pd{u}{x,x,t}\]to be easily typeset with \verb|\pd{u}{x,x,t}|. When applying
a partial derivative to a longer term, the first argument can be left blank and
the longer string written as an additional argument, as demonstrated by
\verb|\pd{}{z}{x+y}| which results in\[\pd{}{z}{x+y}.\]To prevent brackets from
being placed after a partial differential with an empty numerator, use
\verb|!| for the first argument, for example, \verb|\pd{!}{x}|:\[\pd{!}{x}\]
\subsection{Further examples}
Combining the commands provided by this package allows more complex terms to be
written concisely. The \verb|\br| allows equations with multiple brackets to be
constructed and manipulated quickly and easily. An example of this is
\verb|\br{x-y}\br{Q-\frac12\br{P+\br{x-1}\br{\br{a+b}\br{u+c}-\od st}}}|, which
results in\[\br{x-y}\br{Q-\frac12\br{P+\br{x-1}\br{\br{A+B}\br{u+c}-\od st}}}.\]
The form of the partial differentials written with the \verb|\pd| command can
be changed at any time. \verb|\pd Et+\sum_{i=1}^3\pd{}{x_i}{\br{E+p}u_i}|
produces\[\pd Et+\sum_{i=1}^3\pd{}{x_i}{\br{E+p}u_i}\]by default. With
\verb|pdshort|, the same input instead
creates\[E_t+\sum_{i=1}^3\br{\br{E+p}u_i}_{x_i},\]while with \verb|pdalt| the
output is\[\partial_tE+\sum_{i=1}^3\partial_{x_i}\br{\br{E+p}u_i}.\]
\StopEventually{\typeout{**************************************************}
\typeout{*}
\typeout{* To finish the installation, you have to move the}
\typeout{* following file into a directory searched by TeX:}
\typeout{*}
\typeout{* \space\space bropd.sty}
\typeout{*}
\typeout{* Documentation is in bropd.\ifpdf pdf\else dvi\fi.}
\typeout{*}
\typeout{**************************************************}\end{document}}
\clearpage
\DocInput{bropd.dtx}
\clearpage
\PrintChanges
\Finale
%</batchfile>
% \fi
% \section{Implementation}
% Announce the name, package version and \LaTeXe\ requirement
% \changes{v1.0}{2012/11/04}{Initial version}
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bropd}
[2014/10/14 1.2 automated typing of brackets and differential operators]
%    \end{macrocode}
% Initiate conditionals and counters
%    \begin{macrocode}
\newif\if@bropd@a\newif\if@bropd@b\newif\if@bropd@s\newif\if@bropd@u
\newcounter{@bropd@c}\newcounter{@bropd@d}
\newcounter{@bropd@e}\newcounter{@bropd@f}
%    \end{macrocode}
% Provide optional arguments for alternative form partial differential and
% sans-serif fonts
%    \begin{macrocode}
\DeclareOption{pdshort}{\@bropd@atrue\@bropd@ufalse}
\DeclareOption{pdalt}{\@bropd@atrue\@bropd@utrue}
\DeclareOption{sans}{\@bropd@strue}\ProcessOptions
%    \end{macrocode}
% Define character for \verb|\pd| with empty numerator and no brackets following
%    \begin{macrocode}
\def\@bropd@t{!}
%    \end{macrocode}
% \begin{macro}{\@bropd@g}
% Internal command for default partial differential form
%    \begin{macrocode}
\def\@bropd@g#1#2#3#4{\def\@bropd@h{#1}
%    \end{macrocode}
% Create numerator
%    \begin{macrocode}
\ifx\@bropd@o\@bropd@t\let\@bropd@o\empty\fi
%    \end{macrocode}
% Reset counters
%    \begin{macrocode}
\ifx\@bropd@h\empty
\setcounter{@bropd@c}0\setcounter{@bropd@d}1
\let\@bropd@h\empty
%    \end{macrocode}
% Determine order of partial derivative and display as power of partial if
% greater than one
%    \begin{macrocode}
\@for\@bropd@i:=#3\do{\stepcounter{@bropd@c}}
\frac{#4\ifnum\value{@bropd@c}>1
^{\arabic{@bropd@c}}\fi\@bropd@o}
%    \end{macrocode}
% Cycle through each term for the denominator. If a term is the same as the
% previous, add to counter, otherwise print along with counter value
%    \begin{macrocode}
{\@for\@bropd@i:=#3\do{
\ifx\@bropd@i\@bropd@h
\stepcounter{@bropd@d}
\else
\@bropd@h
\ifnum\value{@bropd@d}>1
^{\arabic{@bropd@d}}
\fi
#4\setcounter{@bropd@d}1
\fi
\let\@bropd@h\@bropd@i}
\@bropd@h
\ifnum\value{@bropd@d}>1
^{\arabic{@bropd@d}}\fi}
\else
%    \end{macrocode}
% If optional argument provided, display partial differential to stated order
% \changes{v1.1}{2012/11/08}{Fixed higher order differentials with denominators
% containing commands}
%    \begin{macrocode}
\frac{#4^{#1}\@bropd@o}{#4\noexpand#3^{#1}}
\fi}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@bropd@j}
% Internal command for brackets. Evaluate terms within brackets to determine the
% highest bracket level
% \changes{v\fileversion}\filedate{Changed \cs{bgroup} to \cs{begingroup} and
% \cs{egroup} to \cs{endgroup} to remove erroneous introduction of space before
% and after brackets}
%    \begin{macrocode}
\def\@bropd@j#1{\setcounter{@bropd@f}0
\begingroup\renewcommand{\br}[1]{\stepcounter{@bropd@e}##1
\ifnum\value{@bropd@e}>\value{@bropd@f}
\setcounter{@bropd@f}{\value{@bropd@e}}
\fi
\addtocounter{@bropd@e}{-1}}\sbox0{$#1$}\endgroup
\loop
\ifnum\value{@bropd@f}>2
\addtocounter{@bropd@f}{-3}
\repeat
%    \end{macrocode}
% Detemine bracket type for current level
%    \begin{macrocode}
\ifnum\value{@bropd@f}>0
\ifnum\value{@bropd@f}>1
\def\@bropd@k{\left\lbrace#1\right\rbrace}
\else
\def\@bropd@k{\left[#1\right]}
\fi
\else
\def\@bropd@k{\left(#1\right)}
\fi}
\if@bropd@a
\let\@bropd@l\empty
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\br}
% External command for brackets
%    \begin{macrocode}
\newcommand\br[1]{\let\@bropd@m\@bropd@l
\@bropd@j{\let\@bropd@l\empty#1\let\@bropd@l\@bropd@m}
\ifx\@bropd@l\empty
\def\@bropd@n{\@bropd@k}
\else
\let\@bropd@m\@bropd@l
\def\@bropd@n{\@bropd@k_{\@bropd@m}}
\fi
\let\@bropd@l\empty
\@bropd@n}
\if@bropd@u
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@bropd@q}
% Internal command for first alternative partial differential command
% \changes{v1.1}{2012/11/08}{Added second alternative form for partial
% differentials}
%    \begin{macrocode}
\def\@bropd@q#1#2#3{\def\@bropd@h{#1}
\ifx\@bropd@h\empty
\@bropd@bfalse
\else
%    \end{macrocode}
% Default partial differential if character provided as optional argument
% \changes{v1.1}{2012/11/08}{Allowed partial differential with empty numerator
% without need for bracket command after}
%    \begin{macrocode}
\if!\ifnum9<1#1!\else_\fi
\@bropd@bfalse
\else
\@bropd@btrue
\fi
\fi
\ifx\@bropd@o\@bropd@t
\@bropd@btrue\let\@bropd@o\empty
\fi
\if@bropd@b\@bropd@g{#1}\@bropd@o{\noexpand#3}\partial
\else
%    \end{macrocode}
% Construct alternate form partial differential
%    \begin{macrocode}
\partial_{\ifx\@bropd@h\empty
\@for\@bropd@i:=#3\do\@bropd@i\else\setcounter{@bropd@c}0
\loop
\ifnum\value{@bropd@c}<#1
#3\stepcounter{@bropd@c}
\repeat
\fi}
\@bropd@o
\fi}
\else
%    \end{macrocode}
% Internal command for second alternative partial differential command
%    \begin{macrocode}
\def\@bropd@q#1#2#3{\def\@bropd@h{#1}
\ifx\@bropd@h\empty
\@bropd@bfalse
\else
%    \end{macrocode}
% Default partial differential if character provided as optional argument
%    \begin{macrocode}
\if!\ifnum9<1#1!\else_\fi
\@bropd@bfalse
\else
\@bropd@btrue
\fi
\fi
\ifx\@bropd@o\@bropd@t
\@bropd@btrue\let\@bropd@o\empty
\fi
\if@bropd@b\@bropd@g{#1}\@bropd@o{\noexpand#3}\partial
\else
%    \end{macrocode}
% Construct alternate form partial differential
%    \begin{macrocode}
\def\@bropd@p{\ifx\@bropd@h\empty
\@for\@bropd@i:=#3\do\@bropd@i\else\setcounter{@bropd@c}0
\loop
\ifnum\value{@bropd@c}<#1
#3\stepcounter{@bropd@c}
\repeat
\fi}
\ifx\@bropd@o\empty
\let\@bropd@l\@bropd@p\else{\@bropd@o}{_{\@bropd@p}}\fi\fi}
\fi
\else
%    \end{macrocode}
% Internal command for default partial differentials
%    \begin{macrocode}
\def\@bropd@q#1#2#3{\@bropd@g{#1}{#2}{\noexpand#3}\partial}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\br}
% External command for brackets
%    \begin{macrocode}
\newcommand\br[1]{\@bropd@j{#1}\@bropd@k}
\fi
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\pd}
% \changes{v1.1}{2012/11/08}{Brackets automatically added after empty numerator}
%    \begin{macrocode}
\newcommand\pd[3][]{\def\@bropd@o{#2}
\ifx\@bropd@o\empty
\let\@bropd@v\br
\else
\let\@bropd@v\empty
\fi
\@bropd@q{#1}{#2}{#3}\@bropd@v}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\@bropd@r}
% Format ordinary differential based on font type
%    \begin{macrocode}
\if@bropd@s
\def\@bropd@r{\mathsf d}
\else
\def\@bropd@r{\mathrm d}
\fi
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\od}
% External command for ordinary differentials
%    \begin{macrocode}
\newcommand\od[3][]{\def\@bropd@h{#1}
\frac{\@bropd@r\ifx\@bropd@h\empty\else^{#1}\fi#2}
{\@bropd@r#3\ifx\@bropd@h\empty\else^{#1}\fi}}
\endinput
%    \end{macrocode}
% \end{macro}
% \endinput