| 1 |
% \iffalse The license starting on line four applies to this file |
| 2 |
%<*batchfile> |
| 3 |
{\obeylines\obeyspaces \gdef\thepreamble{ |
| 4 |
|
| 5 |
Copyright 2014 by Benjamin Tatlock |
| 6 |
|
| 7 |
This work may be distributed and/or modified under the conditions of the |
| 8 |
LaTeX Project Public License, either version 1.3 of this license or (at your |
| 9 |
option) any later version. The latest version of this license is in |
| 10 |
http://www.latex-project.org/lppl.txt |
| 11 |
and version 1.3 or later is part of all distributions of LaTeX version |
| 12 |
2005/12/01 or later. |
| 13 |
|
| 14 |
This work has the LPPL maintenance status `maintained'. |
| 15 |
|
| 16 |
The Current Maintainer of this work is Benjamin Tatlock. |
| 17 |
|
| 18 |
This work consists of the file bropd.dtx and the derived files bropd.sty and |
| 19 |
bropd.pdf. |
| 20 |
}} |
| 21 |
\begingroup |
| 22 |
\input docstrip |
| 23 |
\keepsilent |
| 24 |
\expandafter\preamble\thepreamble\endpreamble |
| 25 |
\askforoverwritefalse |
| 26 |
\generate{\file{bropd.sty}{\from{bropd.dtx}{}}} |
| 27 |
\endgroup |
| 28 |
\documentclass{ltxdoc} |
| 29 |
\usepackage{bropd,color,ifpdf} |
| 30 |
\DoNotIndex{\def} |
| 31 |
\EnableCrossrefs |
| 32 |
\CodelineIndex |
| 33 |
\RecordChanges |
| 34 |
\GetFileInfo{bropd.sty} |
| 35 |
\title{The \textsf{bropd} package\thanks{This documentation corresponds to |
| 36 |
\textsf{bropd}~v\fileversion, dated \filedate.}} |
| 37 |
\def\auth{Benjamin Tatlock} |
| 38 |
\author{\auth\thanks{\texttt{\kern2.5em\textcolor{white} |
| 39 |
{\char101\char109\char97\char105\char108}\kern-5em\auth\kern-4em\char46\kern |
| 40 |
3.5em\char64\textcolor{white}{bropd}\kern-1em\char108\kern-1em\char105\ |
| 41 |
\kern-2em\char109\char97\kern1em\char46\textcolor{white} |
| 42 |
{\char111\char114\char103}\kern-2em\ com}}} |
| 43 |
\begin{document} |
| 44 |
\maketitle |
| 45 |
\begin{abstract} |
| 46 |
The \textsf{bropd} package simplifies the process of writing differential |
| 47 |
operators and brackets in \LaTeX. The commands facilitate the easy manipulation |
| 48 |
of equations involving brackets and allow partial differentials to be expressed |
| 49 |
in alternate forms. |
| 50 |
\end{abstract} |
| 51 |
\section{Introduction} |
| 52 |
The \textsf{bropd} package introduces a bracket command that automatically |
| 53 |
selects parentheses, square brackets or braces as appropriate based on the |
| 54 |
number of brackets. As such, brackets can be freely added and removed without |
| 55 |
alterations to the rest of an equation. Commands for typing ordinary and partial |
| 56 |
differentials are also created, with two optional concise forms for partial |
| 57 |
derivatives. Equations can therefore be written in a standard form and their |
| 58 |
style altered globally at a later date. |
| 59 |
\section{Usage} |
| 60 |
This section outlines the use of the three commands provided by the |
| 61 |
\textsf{bropd} package. |
| 62 |
\subsection{Brackets} |
| 63 |
The bracket command replaces \verb|\left(| and \verb|\right)| with the single |
| 64 |
command, \verb|\br| to produce brackets in a math environment. The input |
| 65 |
\verb|\br{x}| produces\[\br{x}.\]When nested, the type of bracket is determined |
| 66 |
automatically, for example, \verb|r=\br{\br{x-a}^2+\br{y-b}^2}^{\frac{1}{2}}| |
| 67 |
results in\[r=\br{\br{x-a}^2+\br{y-b}^2}^{\frac{1}{2}}.\] |
| 68 |
\subsection{Differential operators} |
| 69 |
\subsubsection{Ordinary differential} |
| 70 |
The \verb|\od| command produces ordinary differentials, such as \verb|\od{y}{x}| |
| 71 |
which is displayed as\[\od{y}{x}.\]The order of the differential can be |
| 72 |
specified as an optional argument, illustrated here with the command |
| 73 |
\verb|\od[2]{u}{x}=-\omega^2u| which results in\[\od[2]{u}{x}=-\omega^2u.\]When |
| 74 |
using \verb|\od| with a sans-serif font, the package should be loaded with the |
| 75 |
optional argument \verb|sans|. |
| 76 |
\subsubsection{Partial differential}The command \verb|\pd| follows the same form |
| 77 |
as \verb|\od|, but instead produces partial differentials. By default, |
| 78 |
\verb|\pd{u}{t}=6u\pd{u}{x}-\pd[3]{u}{x}| |
| 79 |
produces\[\pd{u}{t}=6u\pd{u}{x}-\pd[3]{u}{x}.\]Loading the package with the |
| 80 |
option \verb|pdshort| results in an alternative format for partial |
| 81 |
differentials:\[u_t=6uu_x-u_{xxx}\]If the optional argument is not a positive |
| 82 |
integer, the default form is reverted to, as with \verb|\pd[n]xy|:\[\pd[n]xy\]A |
| 83 |
second alternative form is produced when the option \verb|pdalt| is |
| 84 |
specified:\[\partial_tu=6u\partial_xu-\partial_{xxx}u\]The syntax for partial |
| 85 |
differentials is extended to allow higher order terms such |
| 86 |
as\[\pd{u}{x,x,t}\]to be easily typeset with \verb|\pd{u}{x,x,t}|. When applying |
| 87 |
a partial derivative to a longer term, the first argument can be left blank and |
| 88 |
the longer string written as an additional argument, as demonstrated by |
| 89 |
\verb|\pd{}{z}{x+y}| which results in\[\pd{}{z}{x+y}.\]To prevent brackets from |
| 90 |
being placed after a partial differential with an empty numerator, use |
| 91 |
\verb|!| for the first argument, for example, \verb|\pd{!}{x}|:\[\pd{!}{x}\] |
| 92 |
\subsection{Further examples} |
| 93 |
Combining the commands provided by this package allows more complex terms to be |
| 94 |
written concisely. The \verb|\br| allows equations with multiple brackets to be |
| 95 |
constructed and manipulated quickly and easily. An example of this is |
| 96 |
\verb|\br{x-y}\br{Q-\frac12\br{P+\br{x-1}\br{\br{a+b}\br{u+c}-\od st}}}|, which |
| 97 |
results in\[\br{x-y}\br{Q-\frac12\br{P+\br{x-1}\br{\br{A+B}\br{u+c}-\od st}}}.\] |
| 98 |
The form of the partial differentials written with the \verb|\pd| command can |
| 99 |
be changed at any time. \verb|\pd Et+\sum_{i=1}^3\pd{}{x_i}{\br{E+p}u_i}| |
| 100 |
produces\[\pd Et+\sum_{i=1}^3\pd{}{x_i}{\br{E+p}u_i}\]by default. With |
| 101 |
\verb|pdshort|, the same input instead |
| 102 |
creates\[E_t+\sum_{i=1}^3\br{\br{E+p}u_i}_{x_i},\]while with \verb|pdalt| the |
| 103 |
output is\[\partial_tE+\sum_{i=1}^3\partial_{x_i}\br{\br{E+p}u_i}.\] |
| 104 |
\StopEventually{\typeout{**************************************************} |
| 105 |
\typeout{*} |
| 106 |
\typeout{* To finish the installation, you have to move the} |
| 107 |
\typeout{* following file into a directory searched by TeX:} |
| 108 |
\typeout{*} |
| 109 |
\typeout{* \space\space bropd.sty} |
| 110 |
\typeout{*} |
| 111 |
\typeout{* Documentation is in bropd.\ifpdf pdf\else dvi\fi.} |
| 112 |
\typeout{*} |
| 113 |
\typeout{**************************************************}\end{document}} |
| 114 |
\clearpage |
| 115 |
\DocInput{bropd.dtx} |
| 116 |
\clearpage |
| 117 |
\PrintChanges |
| 118 |
\Finale |
| 119 |
%</batchfile> |
| 120 |
% \fi |
| 121 |
% \section{Implementation} |
| 122 |
% Announce the name, package version and \LaTeXe\ requirement |
| 123 |
% \changes{v1.0}{2012/11/04}{Initial version} |
| 124 |
% \begin{macrocode} |
| 125 |
\NeedsTeXFormat{LaTeX2e} |
| 126 |
\ProvidesPackage{bropd} |
| 127 |
[2014/10/14 1.2 automated typing of brackets and differential operators] |
| 128 |
% \end{macrocode} |
| 129 |
% Initiate conditionals and counters |
| 130 |
% \begin{macrocode} |
| 131 |
\newif\if@bropd@a\newif\if@bropd@b\newif\if@bropd@s\newif\if@bropd@u |
| 132 |
\newcounter{@bropd@c}\newcounter{@bropd@d} |
| 133 |
\newcounter{@bropd@e}\newcounter{@bropd@f} |
| 134 |
% \end{macrocode} |
| 135 |
% Provide optional arguments for alternative form partial differential and |
| 136 |
% sans-serif fonts |
| 137 |
% \begin{macrocode} |
| 138 |
\DeclareOption{pdshort}{\@bropd@atrue\@bropd@ufalse} |
| 139 |
\DeclareOption{pdalt}{\@bropd@atrue\@bropd@utrue} |
| 140 |
\DeclareOption{sans}{\@bropd@strue}\ProcessOptions |
| 141 |
% \end{macrocode} |
| 142 |
% Define character for \verb|\pd| with empty numerator and no brackets following |
| 143 |
% \begin{macrocode} |
| 144 |
\def\@bropd@t{!} |
| 145 |
% \end{macrocode} |
| 146 |
% \begin{macro}{\@bropd@g} |
| 147 |
% Internal command for default partial differential form |
| 148 |
% \begin{macrocode} |
| 149 |
\def\@bropd@g#1#2#3#4{\def\@bropd@h{#1} |
| 150 |
% \end{macrocode} |
| 151 |
% Create numerator |
| 152 |
% \begin{macrocode} |
| 153 |
\ifx\@bropd@o\@bropd@t\let\@bropd@o\empty\fi |
| 154 |
% \end{macrocode} |
| 155 |
% Reset counters |
| 156 |
% \begin{macrocode} |
| 157 |
\ifx\@bropd@h\empty |
| 158 |
\setcounter{@bropd@c}0\setcounter{@bropd@d}1 |
| 159 |
\let\@bropd@h\empty |
| 160 |
% \end{macrocode} |
| 161 |
% Determine order of partial derivative and display as power of partial if |
| 162 |
% greater than one |
| 163 |
% \begin{macrocode} |
| 164 |
\@for\@bropd@i:=#3\do{\stepcounter{@bropd@c}} |
| 165 |
\frac{#4\ifnum\value{@bropd@c}>1 |
| 166 |
^{\arabic{@bropd@c}}\fi\@bropd@o} |
| 167 |
% \end{macrocode} |
| 168 |
% Cycle through each term for the denominator. If a term is the same as the |
| 169 |
% previous, add to counter, otherwise print along with counter value |
| 170 |
% \begin{macrocode} |
| 171 |
{\@for\@bropd@i:=#3\do{ |
| 172 |
\ifx\@bropd@i\@bropd@h |
| 173 |
\stepcounter{@bropd@d} |
| 174 |
\else |
| 175 |
\@bropd@h |
| 176 |
\ifnum\value{@bropd@d}>1 |
| 177 |
^{\arabic{@bropd@d}} |
| 178 |
\fi |
| 179 |
#4\setcounter{@bropd@d}1 |
| 180 |
\fi |
| 181 |
\let\@bropd@h\@bropd@i} |
| 182 |
\@bropd@h |
| 183 |
\ifnum\value{@bropd@d}>1 |
| 184 |
^{\arabic{@bropd@d}}\fi} |
| 185 |
\else |
| 186 |
% \end{macrocode} |
| 187 |
% If optional argument provided, display partial differential to stated order |
| 188 |
% \changes{v1.1}{2012/11/08}{Fixed higher order differentials with denominators |
| 189 |
% containing commands} |
| 190 |
% \begin{macrocode} |
| 191 |
\frac{#4^{#1}\@bropd@o}{#4\noexpand#3^{#1}} |
| 192 |
\fi} |
| 193 |
% \end{macrocode} |
| 194 |
% \end{macro} |
| 195 |
% \begin{macro}{\@bropd@j} |
| 196 |
% Internal command for brackets. Evaluate terms within brackets to determine the |
| 197 |
% highest bracket level |
| 198 |
% \changes{v\fileversion}\filedate{Changed \cs{bgroup} to \cs{begingroup} and |
| 199 |
% \cs{egroup} to \cs{endgroup} to remove erroneous introduction of space before |
| 200 |
% and after brackets} |
| 201 |
% \begin{macrocode} |
| 202 |
\def\@bropd@j#1{\setcounter{@bropd@f}0 |
| 203 |
\begingroup\renewcommand{\br}[1]{\stepcounter{@bropd@e}##1 |
| 204 |
\ifnum\value{@bropd@e}>\value{@bropd@f} |
| 205 |
\setcounter{@bropd@f}{\value{@bropd@e}} |
| 206 |
\fi |
| 207 |
\addtocounter{@bropd@e}{-1}}\sbox0{$#1$}\endgroup |
| 208 |
\loop |
| 209 |
\ifnum\value{@bropd@f}>2 |
| 210 |
\addtocounter{@bropd@f}{-3} |
| 211 |
\repeat |
| 212 |
% \end{macrocode} |
| 213 |
% Detemine bracket type for current level |
| 214 |
% \begin{macrocode} |
| 215 |
\ifnum\value{@bropd@f}>0 |
| 216 |
\ifnum\value{@bropd@f}>1 |
| 217 |
\def\@bropd@k{\left\lbrace#1\right\rbrace} |
| 218 |
\else |
| 219 |
\def\@bropd@k{\left[#1\right]} |
| 220 |
\fi |
| 221 |
\else |
| 222 |
\def\@bropd@k{\left(#1\right)} |
| 223 |
\fi} |
| 224 |
\if@bropd@a |
| 225 |
\let\@bropd@l\empty |
| 226 |
% \end{macrocode} |
| 227 |
% \end{macro} |
| 228 |
% \begin{macro}{\br} |
| 229 |
% External command for brackets |
| 230 |
% \begin{macrocode} |
| 231 |
\newcommand\br[1]{\let\@bropd@m\@bropd@l |
| 232 |
\@bropd@j{\let\@bropd@l\empty#1\let\@bropd@l\@bropd@m} |
| 233 |
\ifx\@bropd@l\empty |
| 234 |
\def\@bropd@n{\@bropd@k} |
| 235 |
\else |
| 236 |
\let\@bropd@m\@bropd@l |
| 237 |
\def\@bropd@n{\@bropd@k_{\@bropd@m}} |
| 238 |
\fi |
| 239 |
\let\@bropd@l\empty |
| 240 |
\@bropd@n} |
| 241 |
\if@bropd@u |
| 242 |
% \end{macrocode} |
| 243 |
% \end{macro} |
| 244 |
% \begin{macro}{\@bropd@q} |
| 245 |
% Internal command for first alternative partial differential command |
| 246 |
% \changes{v1.1}{2012/11/08}{Added second alternative form for partial |
| 247 |
% differentials} |
| 248 |
% \begin{macrocode} |
| 249 |
\def\@bropd@q#1#2#3{\def\@bropd@h{#1} |
| 250 |
\ifx\@bropd@h\empty |
| 251 |
\@bropd@bfalse |
| 252 |
\else |
| 253 |
% \end{macrocode} |
| 254 |
% Default partial differential if character provided as optional argument |
| 255 |
% \changes{v1.1}{2012/11/08}{Allowed partial differential with empty numerator |
| 256 |
% without need for bracket command after} |
| 257 |
% \begin{macrocode} |
| 258 |
\if!\ifnum9<1#1!\else_\fi |
| 259 |
\@bropd@bfalse |
| 260 |
\else |
| 261 |
\@bropd@btrue |
| 262 |
\fi |
| 263 |
\fi |
| 264 |
\ifx\@bropd@o\@bropd@t |
| 265 |
\@bropd@btrue\let\@bropd@o\empty |
| 266 |
\fi |
| 267 |
\if@bropd@b\@bropd@g{#1}\@bropd@o{\noexpand#3}\partial |
| 268 |
\else |
| 269 |
% \end{macrocode} |
| 270 |
% Construct alternate form partial differential |
| 271 |
% \begin{macrocode} |
| 272 |
\partial_{\ifx\@bropd@h\empty |
| 273 |
\@for\@bropd@i:=#3\do\@bropd@i\else\setcounter{@bropd@c}0 |
| 274 |
\loop |
| 275 |
\ifnum\value{@bropd@c}<#1 |
| 276 |
#3\stepcounter{@bropd@c} |
| 277 |
\repeat |
| 278 |
\fi} |
| 279 |
\@bropd@o |
| 280 |
\fi} |
| 281 |
\else |
| 282 |
% \end{macrocode} |
| 283 |
% Internal command for second alternative partial differential command |
| 284 |
% \begin{macrocode} |
| 285 |
\def\@bropd@q#1#2#3{\def\@bropd@h{#1} |
| 286 |
\ifx\@bropd@h\empty |
| 287 |
\@bropd@bfalse |
| 288 |
\else |
| 289 |
% \end{macrocode} |
| 290 |
% Default partial differential if character provided as optional argument |
| 291 |
% \begin{macrocode} |
| 292 |
\if!\ifnum9<1#1!\else_\fi |
| 293 |
\@bropd@bfalse |
| 294 |
\else |
| 295 |
\@bropd@btrue |
| 296 |
\fi |
| 297 |
\fi |
| 298 |
\ifx\@bropd@o\@bropd@t |
| 299 |
\@bropd@btrue\let\@bropd@o\empty |
| 300 |
\fi |
| 301 |
\if@bropd@b\@bropd@g{#1}\@bropd@o{\noexpand#3}\partial |
| 302 |
\else |
| 303 |
% \end{macrocode} |
| 304 |
% Construct alternate form partial differential |
| 305 |
% \begin{macrocode} |
| 306 |
\def\@bropd@p{\ifx\@bropd@h\empty |
| 307 |
\@for\@bropd@i:=#3\do\@bropd@i\else\setcounter{@bropd@c}0 |
| 308 |
\loop |
| 309 |
\ifnum\value{@bropd@c}<#1 |
| 310 |
#3\stepcounter{@bropd@c} |
| 311 |
\repeat |
| 312 |
\fi} |
| 313 |
\ifx\@bropd@o\empty |
| 314 |
\let\@bropd@l\@bropd@p\else{\@bropd@o}{_{\@bropd@p}}\fi\fi} |
| 315 |
\fi |
| 316 |
\else |
| 317 |
% \end{macrocode} |
| 318 |
% Internal command for default partial differentials |
| 319 |
% \begin{macrocode} |
| 320 |
\def\@bropd@q#1#2#3{\@bropd@g{#1}{#2}{\noexpand#3}\partial} |
| 321 |
% \end{macrocode} |
| 322 |
% \end{macro} |
| 323 |
% \begin{macro}{\br} |
| 324 |
% External command for brackets |
| 325 |
% \begin{macrocode} |
| 326 |
\newcommand\br[1]{\@bropd@j{#1}\@bropd@k} |
| 327 |
\fi |
| 328 |
% \end{macrocode} |
| 329 |
% \end{macro} |
| 330 |
% \begin{macro}{\pd} |
| 331 |
% \changes{v1.1}{2012/11/08}{Brackets automatically added after empty numerator} |
| 332 |
% \begin{macrocode} |
| 333 |
\newcommand\pd[3][]{\def\@bropd@o{#2} |
| 334 |
\ifx\@bropd@o\empty |
| 335 |
\let\@bropd@v\br |
| 336 |
\else |
| 337 |
\let\@bropd@v\empty |
| 338 |
\fi |
| 339 |
\@bropd@q{#1}{#2}{#3}\@bropd@v} |
| 340 |
% \end{macrocode} |
| 341 |
% \end{macro} |
| 342 |
% \begin{macro}{\@bropd@r} |
| 343 |
% Format ordinary differential based on font type |
| 344 |
% \begin{macrocode} |
| 345 |
\if@bropd@s |
| 346 |
\def\@bropd@r{\mathsf d} |
| 347 |
\else |
| 348 |
\def\@bropd@r{\mathrm d} |
| 349 |
\fi |
| 350 |
% \end{macrocode} |
| 351 |
% \end{macro} |
| 352 |
% \begin{macro}{\od} |
| 353 |
% External command for ordinary differentials |
| 354 |
% \begin{macrocode} |
| 355 |
\newcommand\od[3][]{\def\@bropd@h{#1} |
| 356 |
\frac{\@bropd@r\ifx\@bropd@h\empty\else^{#1}\fi#2} |
| 357 |
{\@bropd@r#3\ifx\@bropd@h\empty\else^{#1}\fi}} |
| 358 |
\endinput |
| 359 |
% \end{macrocode} |
| 360 |
% \end{macro} |
| 361 |
% \endinput |