summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/bropd/bropd.dtx
blob: 0d809486e869a0a3a88eb5770f35ceedc3e83861 (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
% \iffalse The license starting on line four applies to this file
%<*batchfile>
{\obeylines\obeyspaces \gdef\thepreamble{

Copyright 2012 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
\generate{\file{bropd.sty}{\from{bropd.dtx}{}}}
\endgroup
\documentclass{ltxdoc}
\usepackage{bropd,ifpdf}
\GetFileInfo{bropd.sty}
\title{The \textsf{bropd} package\thanks{This documentation corresponds to
\textsf{bropd}~v\fileversion, dated \filedate.}}
\author{Benjamin Tatlock}
\newenvironment{verba}{\begin{verbatim}}{\end{verbatim}}
\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 an alternate form.
\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 an equation. A command for writing ordinary and partial
differentials is also created with an optional concise form for typesetting
partial derivatives. This allows equations to be typed 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}\]Note that when using this form, the
\verb|\br| function \emph{must} follow \verb|\pd| when the first argument is
left empty, as demonstrated by \verb|\pd{}{z}\br{x+y}| which results
in\[\br{x+y}_z.\]If the optional argument is not a positive integer, the default
form is reverted to, as with \verb|\pd[n]xy|:\[\pd[n]xy\]The syntax for partial
differentials is extended to allow the second order term such
as\[\pd{u}{x,t}\]to be easily typeset with \verb|\pd{u}{x,t}|.
\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}-t}}}|, which
results in\[\br{x-y}\br{Q-\frac12\br{P+\br{x-1}\br{\br{A+B}\br{u+c}-t}}}.\]
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{\br{E+p}u_i}|
produces\[\pd Et+\sum_{i=1}^3\pd{}{x_i}\br{\br{E+p}u_i}\]
or, with \verb|pdshort|,\[E_t+\sum_{i=1}^3\br{\br{E+p}u_i}_{x_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
\Finale
%</batchfile>
% \fi
% \section{Implementation}
% Announce the name, package version and \LaTeXe\ requirement
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{bropd}
[2012/11/04 1.0 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
\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}
\DeclareOption{sans}{\@bropd@strue}\ProcessOptions
%    \end{macrocode}
% Internal command for default partial differential form
%    \begin{macrocode}
\newcommand\@bropd@g[4]{\def\@bropd@h{#1}
\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#2}
%    \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
%    \begin{macrocode}
\frac{#4^{#1}#2}{#4#3^{#1}}
\fi}
%    \end{macrocode}
% Internal command for brackets.  Evaluate terms within brackets to determine
% the highest bracket level
%    \begin{macrocode}
\newcommand\@bropd@j[1]{\setcounter{@bropd@f}0
{\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$}}
\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}
% External bracket command
%    \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}
%    \end{macrocode}
% External command for alternative partial differential command
%    \begin{macrocode}
\newcommand\pd[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
\if@bropd@b\@bropd@g{#1}{#2}{\noexpand#3}\partial
\else
%    \end{macrocode}
% Construct alternate form partial differential
%    \begin{macrocode}
\def\@bropd@o{#2}
\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{#2}{_{\@bropd@p}}\fi\fi}
\else
%    \end{macrocode}
% External command for default partial differentials
%    \begin{macrocode}
\newcommand\pd[3][]{\@bropd@g{#1}{#2}{\noexpand#3}\partial}
%    \end{macrocode}
% External command for brackets
%    \begin{macrocode}
\newcommand\br[1]{\@bropd@j{#1}\@bropd@k}
\fi
%    \end{macrocode}
% Format ordinary differential based on font type
%    \begin{macrocode}
\if@bropd@s
\newcommand\@bropd@r{\mathsf{d}}
\else
\newcommand\@bropd@r{\mathrm{d}}
\fi
%    \end{macrocode}
% 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}
% \endinput