-
Notifications
You must be signed in to change notification settings - Fork 3
/
fixdif.dtx
607 lines (587 loc) · 21.9 KB
/
fixdif.dtx
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
% \iffalse meta-comment
%
% Copyright (C) 2022-2023 by Zhang Tingxuan <[email protected]>
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c 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 Zhang Tingxuan.
%
% This work consists of the files fixdif.dtx,
% and the derived files fixdif.ins,
% fixdif.sty,
% fixdif.pdf,
% and README.md.
%
%<*internal>
\iffalse
%</internal>
%
%<*readme>
# The `fixdif` Package
The `fixdif` package provides an interface for defining the style of differential operators.
The basic commands are:
- `\d`: for differential operator "d" in math mode and under-dot accent in text;
- `\partial`: a "fixed" partial differential operator command;
- `\letdif`: an interface for defining new commands for differential operators;
- `\mathdif`: a commmand in math mode, you can use it just like `\mathop`, etc.
See `fixdif.pdf` for more. Happy TeXing!
## License
This work may be distributed and/or modified under the conditions of
the [LaTeX Project Public License](http://www.latex-project.org/lppl.txt),
either version 1.3c of this license or (at your option) any later version.
------
Copyright (C) 2022-2023 by Zhang Tingxuan <[email protected]>.
%</readme>
%
%<*internal>
\fi
\begingroup
\def\NameOfLaTeXe{LaTeX2e}
\expandafter\endgroup\ifx\NameOfLaTeXe\fmtname\else
\csname fi\endcsname
%</internal>
%
%<*install>
\input docstrip.tex
\keepsilent
\preamble
Copyright (C) 2022-2023 by Zhang Tingxuan <[email protected]>
This work may be distributed and/or modified under the
conditions of the LaTeX Project Public License, either
version 1.3c 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 Zhang Tingxuan.
This work consists of the files fixdif.dtx,
and the derived files fixdif.ins,
fixdif.sty,
fixdif.pdf,
and README.md.
\endpreamble
\generate{
\usedir{tex/latex/fixdif}
\file{\jobname.sty} {\from{\jobname.dtx}{package}}
%</install>
%<*internal>
\usedir{source/latex/fixdif}
\file{\jobname.ins} {\from{\jobname.dtx}{install}}
%</internal>
%<*install>
\usedir{doc/latex/fixdif}
\nopreamble\nopostamble
\file{README.md} {\from{\jobname.dtx}{readme}}
}
\obeyspaces
\Msg{****************************************************}
\Msg{* *}
\Msg{* To finish the installation you have to move the *}
\Msg{* following file into a directory searched by TeX: *}
\Msg{* *}
\Msg{* fixdif.sty *}
\Msg{* *}
\Msg{* The recommended directory is *}
\Msg{* TDS:tex/latex/fixdif *}
\Msg{* *}
\Msg{* To produce the documentation run the file *}
\Msg{* fixdif.dtx through pdfLaTeX/XeLaTeX/LuaLaTeX. *}
\Msg{* XeLaTeX and LuaLaTeX are recommended if you *}
\Msg{* hope the PDF file to be smaller. *}
\Msg{* *}
\Msg{* Happy TeXing! *}
\Msg{* *}
\Msg{****************************************************}
\endbatchfile
%</install>
%
%<*internal>
\fi
%</internal>
%
%<*driver>
\ProvidesFile{fixdif.dtx}[2023/03/20 (c) Copyright 2022-2023 by Zhang Tingxuan]
\documentclass{ltxdoc}
\usepackage{xcolor}
\definecolor{titlecolor}{RGB}{0,12,160}
\usepackage{doc}
\usepackage{fancyvrb}
\fvset{xleftmargin=2.5em,fontsize=\small,gobble=2}
\MakeShortVerb|
\usepackage{hologo}
\def\XeTeX{\hologo{XeTeX}}
\def\LuaTeX{\hologo{LuaTeX}}
\def\pkg{\textsf}
\def\opt{\texttt}
\title{The \pkg{fixdif} Package}
\author{Zhang Tingxuan}
\date{2023/03/20\quad Version 2.1\thanks{\url{https://github.com/AlphaZTX/fixdif}}}
\usepackage{hyperref}
\hypersetup{
pdftitle = {The fixdif Package},
pdfauthor = {Zhang Tingxuan},
pdfcreator = {pdfLaTeX/XeLaTeX/LuaLaTeX},
linkcolor = black,
urlcolor = titlecolor!80!black,
}
\def\pkg{\textsf}
\makeatletter
\renewcommand\section{\@startsection{section}{1}{\z@}%
{-2.5ex plus -1ex minus -.2ex}%
{1ex plus .2ex}%
{\normalfont\Large\bfseries\color{titlecolor}}}
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}%
{-2ex plus -1ex minus -.2ex}%
{.5ex plus .2ex}%
{\normalfont\normalsize\bfseries\color{titlecolor}}}
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
{.8ex plus .4ex minus .2ex}%
{-1em}%
{\normalfont\normalsize\bfseries\color{titlecolor}}}
\def\UrlAlphabet{%
\do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j%
\do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t%
\do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D%
\do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N%
\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X%
\do\Y\do\Z}
\def\UrlDigits{\do\1\do\2\do\3\do\4\do\5\do\6\do\7\do\8\do\9\do\0}
\g@addto@macro{\UrlBreaks}{\UrlOrds}
\g@addto@macro{\UrlBreaks}{\UrlAlphabet}
\g@addto@macro{\UrlBreaks}{\UrlDigits}
\ifdefined\Umathcode
\usepackage{unicode-math}
\fi
\makeatother
\usepackage{fixdif}
\linespread{1.05}
\parskip6pt plus 2pt minus 1pt
\parindent2.5em
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \maketitle
%
% \begin{abstract}
% The \pkg{fixdif} package redefines the \cs{d} command in \LaTeX\ and
% provides an interface to define commands for differential operators.
%
% The package does well with pdf\TeX, \XeTeX\ and \LuaTeX, only works
% with \LaTeX\ format. Furthermore, this package is compatible with
% \pkg{unicode-math} package in \XeTeX\ and \LuaTeX.
% \end{abstract}
%
% {\parskip1pt plus 1pt\tableofcontents}
%
% \section{The background}
% It's usually recommended that a small skip should be reserved between
% the differential operator and the expression before it\footnote{See
% \url{https://tex.stackexchange.com/questions/14821/whats-the-proper-way-to-typeset-a-differential-operator}.}.
% Take the following line as an example:
% \[f(x)\mathrm{d}x\qquad\hbox{and}\qquad f(x)\d x.\]
% We usually consider that the example on the right side is better than the
% one on left side. The small skip between $f(x)$ and $\d x$ can be
% regarded as a binary operator.
%
% Some users prefer to define a macro like this:
% \begin{Verbatim}
% \renewcommand\d{\mathop{\mathrm{d}}\!}
% \end{Verbatim}
% This macro works well in display math and text math, but still appears with
% the following three problems:
% \begin{enumerate}
% \item The skip before ``$\d$'' still exists before the denominator in
% ``text fraction''. This is what we do not hope to see. For example,
% |$\d y/\d x$| produces $\mathrm{d}y/\,\mathrm{d}x$.
%
% \item |\d| is defined as a text accent command in \LaTeXe\ kernel. If we
% defined like this, |\d{o}| could not produce ``\d{o}'' in text.
%
% \item The skip before ``d'' should behave like skips around a binary operator.
% It should disappear in script math and script script math. For example,
% |$a+b$| yields $a+b$ while |$^{a+b}$| yields $^{a+b}$, the skips around ``$+$''
% disappear in superscript. But in the definition above, |$^{f(x)\d x}$|
% yields $^{f(x)\,\mathrm{d}x}$ but not $^{f(x)\d x}$.
% \end{enumerate}
% To solve these problems, you can try this package.
%
% \section{Introduction}
% To load this package, write
% \begin{Verbatim}
% \usepackage{fixdif}
% \end{Verbatim}
% in the preamble. \pkg{fixdif} allows you to write this line anywhere in the
% preamble since version 2.0. In your document,
% \begin{Verbatim}
% \[ f(x)\d x,\quad\frac{\d y}{\d x},\quad\d y/\d x,\quad a^{y\d x}. \]
% \end{Verbatim}
% will produce
% \[f(x)\d x,\quad \frac{\d y}{\d x},\quad \d y/\d x,\quad a^{y\d x}.\]
%
% \subsection{Basic commands and package options}
% \DescribeMacro{\d}
% The \pkg{fixdif} package provides a \cs{d} command for the differential
% operator ``d'' in math mode. When in text, \cs{d} behaves just like
% the old \cs{d} command in \LaTeX\ or plain \TeX\ as an accent command.
% For example,
% \begin{Verbatim}
% $\d x$ and \d x
% \end{Verbatim}
% tields ``$\d x$ and \d x''.
%
% \paragraph{Set the font of \cs{d}}
% There are two package options to control the style of \cs{d} in math mode~---
% \opt{rm} and \opt{normal}. The default option is \opt{rm}, in which case
% |$f(x)\d x$| produces $f(x)\d x$. If you chose the \opt{normal} option,
% that is
% \begin{Verbatim}
% \usepackage[normal]{fixdif}
% \end{Verbatim}
% |$f(x)\d x$| yields $f(x)\,dx$.
%
% \DescribeMacro{\resetdfont}
% Regardless of the two options above, you can reset the font of \cs{d}
% through \cs{resetdfont} command in preamble:
% \begin{Verbatim}
% \resetdfont{\mathsf}
% \end{Verbatim}
% then |$\d x$| yields $\mathsf{d}x$. Notice that the argument of
% \cs{resetdfont} should be a command with \emph{one} argument.
%
% \paragraph{Control the behavior of \cs{partial}}
% \DescribeMacro{\partial}
% In default, \cs{partial} will be regarded as a differential operator
% after you load \pkg{fixdif}. If you don't like this default setting,
% you can use the \opt{nopartial} option:
% \begin{Verbatim}
% \usepackage[nopartial]{fixdif}
% \end{Verbatim}
% If you choose to use the default settings, \cs{partialnondif} yields
% the ordinary symbol ``$\partialnondif$''.
%
% \section{Define commands for differential operators}
% \noindent\emph{Attention! The commands in this section
% can be used in preamble only!}
%
% \subsection{Define commands with a single command name}
% \noindent\textcolor{titlecolor}{\cs{letdif}\marg{cmd}\marg{csname}}\DescribeMacro{\letdif}
% \hfill(preamble only)
%
% The \cs{letdif} command takes two arguments~--- the first is the newly-defined
% command and the second is the control sequence \emph{name} of a math character,
% that is, a command without its backslash. For example,
% \begin{Verbatim}
% \letdif{\vr}{delta}
% \end{Verbatim}
% then |\vr| will produce a $\delta$ (|\delta|) with automatic skip
% before it.
%
% Through the \cs{letdif} command, we can redefine a math character command
% by its name. For example,
% \begin{Verbatim}
% \letdif{\delta}{delta}
% \end{Verbatim}
% then |\delta| itself will be a differential operator.
%
% The second argument \meta{csname} of \cs{letdif} command can be used
% repeatedly. If you want to get the ordinary symbol of
% \texttt{\char`\\\textnormal{\meta{csname}}}, you can input
% \texttt{\char`\\\textnormal{\meta{csname}}nondif} in math mode.
% For example, in default, \DescribeMacro{\partialnondif}\cs{partialnondif}
% yields the old partial symbol ``$\partialnondif$''.
%
% \noindent\textcolor{titlecolor}{\cs{letdif*}\marg{cmd}\marg{csname}}
% \hfill(preamble only)
%
% This command is basically the same as \cs{letdif}, but this command will
% patch a correction after the differential operator. This is very useful
% when a math font is setted through \pkg{unicode-math} package. For example,
% \begin{Verbatim}
% \usepackage{unicode-math}
% \setmathfont{TeX Gyre Termes Math}
% \usepackage{fixdif}
% \letdif{\vr}{updelta}
% \end{Verbatim}
% this will cause bad negative skip after |\vr|, but if you change the last
% line into
% \begin{Verbatim}
% \letdif*{\vr}{updelta}
% \end{Verbatim}
% you will get the result correct.
%
% \subsection{Define commands with multi commands or a string}
%
% \noindent\textcolor{titlecolor}{\cs{newdif}\marg{cmd}\marg{multi-cmd}}\DescribeMacro{\newdif}
% \hfill(without correction, preamble only)\\
% \noindent\textcolor{titlecolor}{\cs{newdif*}\marg{cmd}\marg{multi-cmd}}
% \hfill(with correction, preamble only)
%
% The first argument of these commands is the newly-defined command; and the
% second argument should contain \emph{more than one} tokens.
% For example, if you have loaded the \pkg{xcolor} package,
% you can use the following line:
% \begin{Verbatim}
% \newdif{\redsfd}{\textsf{\color{red}d}}
% \end{Verbatim}
% Then you get the |\redsfd| as a differential operator. Take another example,
% \begin{Verbatim}
% \newdif{\D}{\mathrm{D}}
% \end{Verbatim}
% Then you get |\D| for an uppercase upright ``D'' as a differential operator.
%
% If your second argument contains only one command like |\Delta|,
% it's recommended to use \cs{letdif} or \cs{letdif*} instead.
%
% \cs{newdif} and \cs{newdif*} will check whether \meta{cmd} has been defined
% already. If so, an error message will be given.
%
% \noindent\textcolor{titlecolor}{\cs{renewdif}\marg{cmd}\marg{multi-cmd}}\DescribeMacro{\renewdif}
% \hfill(without correction, preamble only)\\
% \noindent\textcolor{titlecolor}{\cs{renewdif*}\marg{cmd}\marg{multi-cmd}}
% \hfill(with correction, preamble only)
%
% These two commands are basically the same as \cs{newdif} and \cs{newdif*}.
% The only difference is that \cs{renewdif} and \cs{renewdif*} will check
% whether \meta{cmd} has \emph{not} been defined yet. If so, an error message
% will be given.
%
% \section{Using differential operators temporarily}
%
% \noindent\textcolor{titlecolor}{\cs{mathdif}\marg{symbol}}\DescribeMacro{\mathdif}
% \hfill(without correction, in math mode only)\\
%\noindent\textcolor{titlecolor}{\cs{mathdif*}\marg{symbol}}
% \hfill(with correction, in math mode only)
%
% These two commands can be used in math mode only, more specifically,
% after \verb|\begin{document}|. For example, \verb|$x\mathdif{\Delta}\psi$|
% will get $x\mathdif{\Delta}\psi$.
%
% \section{Examples}
%
% This section shows how to use this package properly in your document.
%
% Take the two examples below:
% \begin{Verbatim}
% \letdif{\Delta}{Delta} % Example 1, in preamble
% \letdif{\nabla}{nabla} % Example 2, in preamble
% \end{Verbatim}
% Actually, the second example is more reasonable.
% Sometimes, we take ``$\Delta$'' as laplacian (equivalent to $\nabla^2$),
% while ``$\Delta$'' can also be regarded as a variable
% or function at some other times. Consequently, it's better to save
% a different command for ``$\Delta$'' as laplacian while reserve
% \verb|\Delta| as a command for an ordinary math symbol ``$\Delta$''.
% However, in the vast majority of cases, ``$\nabla$'' is regarded as
% nabla operator so there is no need to save a different command for
% ``$\nabla$''. Then we can correct the code above:
% \begin{Verbatim}
% \letdif{\laplacian}{Delta} % Example 1, corrected, in preamble
% \end{Verbatim}
% With the \pkg{xparse} package, we can define the command in another method:
% \begin{Verbatim}
% \letdif{\nabla}{nabla}
% \DeclareDocumentCommand{ \laplacian }{ s }{
% \IfBooleanTF{#1}{\mathdif{\Delta}}{\nabla^2}
% }
% \end{Verbatim}
% Then \verb|\laplacian| produces $\nabla^2$ and \verb|\laplacian*|
% produces $\Delta$.
%
% \paragraph{Dealing with ``$+$'' and ``$-$''}
% If you input \verb|$-\d x$|, you'll get ``$-\d x$'' in your document.
% However, if you think ``$-{\d x}$'' is better, you can input
% \verb|-{\d x}|. The ``\verb|\d x|'' in a \emph{group} will be
% regarded \textsl{ordinary} but not \textsl{inner} so that the
% small skip will disappear. Maybe ``$-\d x$'' is just okay.
%
% \section{The source code}
% \begin{macrocode}
%<*package>
% \end{macrocode}
% Check the \TeX{} format and provides the package name.
% \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{fixdif}[2023/03/20 Interface for defining differential operators.]
% \end{macrocode}
%
% \subsection{Control the skip between slashes and differential operator}
% Change the math code of slash ($/$) and backslash ($\backslash$) so that the skip
% between slashes and differential operators can be ignored.
%
% If the \pkg{unicode-math} package was loaded, use the \XeTeX/\LuaTeX{} primitive
% \cs{Umathcode} to change the type of slashes. The numeral ``4'' stands for ``open''.
% If \pkg{unicode-math} was not loaded but \pkg{fontspec} loaded, check if
% \pkg{fontspec} had reset math fonts, that is to say, the |no-math| option.
% \begin{macrocode}
\AtBeginDocument{%
\ifcsname symbf\endcsname%
\csname bool_if:cF\endcsname{g__um_main_font_defined_bool}%
{\csname __um_load_lm:\endcsname}%
\def\fd@patchUmathcode#1{% 16777216 = 16^6
\@tempcnta=\numexpr(\the\Umathcodenum#1-#1)/16777216\relax
\Umathcode #1 = "4 \@tempcnta #1}%
\fd@patchUmathcode{"2F}%
\fd@patchUmathcode{"5C}%
\else\ifcsname fontspec\endcsname
\csname bool_if:cT\endcsname{g__fontspec_math_bool}%
{%
\everymath{\mathcode`\/="413D\relax}%
\PackageWarning{fixdif}{Requires `no-math' option of fontspec!\MessageBreak}%
}% fontspec only influences "/"
\fi\fi}
% \end{macrocode}
% Use \cs{mathcode} to change the type of slashes. The \cs{backslash} needs to be
% redefined through \cs{delimiter} too.
% \begin{macrocode}
\mathcode`\/="413D
\mathcode`\\="426E% \backslash
\protected\def\backslash{\delimiter"426E30F\relax}
% \end{macrocode}
%
% \subsection{Patch the skips around the differential operator}
% \DescribeMacro{\fd@mu@p}
% The following \cs{fd@mu@p} patches the skip after the differential operator.
% \begin{macrocode}
\def\fd@mu@p{\mathchoice{\mskip-\thinmuskip}{\mskip-\thinmuskip}{}{}{}}
% \end{macrocode}
% The \cs{s@fd@mu@p} patches the commands with star (\cs{letdif*}, etc).
% \begin{macrocode}
\def\s@fd@mu@p{\mathchoice{}{}{\hbox{}}{\hbox{}}}
% \end{macrocode}
%
% \subsection{Declare the package options}
% \begin{macrocode}
\DeclareOption{rm}{%
\AtBeginDocument{\ifcsname symbf\endcsname%
\gdef\@fd@dif{\symrm{d}}\fi}%
\gdef\@fd@dif{\mathrm{d}}}
\DeclareOption{normal}{\gdef\@fd@dif{d}}
\DeclareOption{partial}{\@tempswatrue}
\DeclareOption{nopartial}{\@tempswafalse}
\ExecuteOptions{rm,partial}
\ProcessOptions\relax
\if@tempswa
\AtEndOfPackage{\letdif{\partial}{partial}}
\fi
% \end{macrocode}
% \DescribeMacro{\resetdfont}
% Define the \cs{resetdfont} command.
% \begin{macrocode}
\gdef\resetdfont#1{\AtBeginDocument{\let\@fd@dif\relax\gdef\@fd@dif{#1{d}}}}
% \end{macrocode}
%
% \subsection{Deal with the \cs{d} command}
% \DescribeMacro{\fd@dif}
% \cs{fd@dif} is the differential operator produced by \cs{d} in math mode.
% Here we prefer \cs{mathinner} to |\mathbin| to make the skip.
% \begin{macrocode}
\def\fd@dif{\mathinner{\@fd@dif}\fd@mu@p}
% \end{macrocode}
% \DescribeMacro{\fd@d@acc}
% Restore the \cs{d} command in text by \cs{fd@d@acc} with \cs{let}.
% \begin{macrocode}
\AtBeginDocument{\let\fd@d@acc\d
% \end{macrocode}
% \DescribeMacro{\d}
% Redefine the \cs{d} command. In text, we need to expand the stuffs after \cs{d}
% \begin{macrocode}
\DeclareRobustCommand\d{\ifmmode\fd@dif\else\expandafter\fd@d@acc\fi}}
% \end{macrocode}
%
% \subsection{User's interface for defining new differential operators}
% \DescribeMacro{\letdif}
% Define the \cs{letdif} command. The internal version of \cs{letdif}
% is \cs{@letdif} and \cs{s@letdif}.
%
% |#1| is the final command; |#2| is the ``control sequence name'' of |#1|'s initial definition.
% Here we create a command (\cs{csname}|#2nonfif|\cs{endcsname}) to restore |#2|.
% \begin{macrocode}
\def\@letdif#1#2{\AtBeginDocument{%
\ifcsname #2nondif\endcsname\else%
\expandafter\let\csname #2nondif\expandafter\endcsname
\csname #2\endcsname%
\fi%
\DeclareRobustCommand#1{\mathinner{\csname #2nondif\endcsname}\fd@mu@p}%
}}
% \end{macrocode}
% The definition of \cs{s@letdif} is similar, but with the patch for negative skips.
% \begin{macrocode}
\def\s@letdif#1#2{\AtBeginDocument{%
\ifcsname #2nondif\endcsname\else%
\expandafter\let\csname #2nondif\expandafter\endcsname
\csname #2\endcsname%
\fi%
\DeclareRobustCommand#1{\mathinner{\s@fd@mu@p\csname #2nondif\endcsname\hbox{}}\fd@mu@p}%
}}
\DeclareRobustCommand\letdif{\@ifstar\s@letdif\@letdif}
\@onlypreamble\letdif
% \end{macrocode}
% \DescribeMacro{\newdif}
% Define the \cs{newdif} command. |#1| is the final command; |#2| is the ``long'' argument.
% \begin{macrocode}
\long\def\@newdif#1#2{\AtBeginDocument{%
\ifdefined#1
\PackageError{fixdif}{\string#1 is already defined}
{Try another command instead of \string#1.}%
\else
\DeclareRobustCommand#1{\mathinner{#2}\fd@mu@p}%
\fi%
}}
\long\def\s@newdif#1#2{\AtBeginDocument{%
\ifdefined#1
\PackageError{fixdif}{\string#1 is already defined}
{Try another command instead of \string#1.}%
\else
\DeclareRobustCommand#1{\s@fd@mu@p\mathinner{#2\hbox{}}\fd@mu@p}%
\fi%
}}
\DeclareRobustCommand\newdif{\@ifstar\s@newdif\@newdif}
\@onlypreamble\newdif
% \end{macrocode}
% \DescribeMacro{\renewdif}
% Define the \cs{renewdif} command.
% \begin{macrocode}
\long\def\@renewdif#1#2{\AtBeginDocument{%
\ifdefined#1
\DeclareRobustCommand#1{\mathinner{#2}\fd@mu@p}%
\else
\PackageError{fixdif}{\string#1 has not been defined yet}
{You should use \string\newdif instead of \string\renewdif.}%
\fi%
}}
\long\def\s@renewdif#1#2{\AtBeginDocument{%
\ifdefined#1
\DeclareRobustCommand#1{\s@fd@mu@p\mathinner{#2\hbox{}}\fd@mu@p}%
\else
\PackageError{fixdif}{\string#1 has not been defined yet}
{You should use \string\newdif instead of \string\renewdif.}%
\fi%
}}
\DeclareRobustCommand\renewdif{\@ifstar\s@renewdif\@renewdif}
\@onlypreamble\renewdif
% \end{macrocode}
% \subsection{In-document commands: \cs{mathdif}}
% \begin{macrocode}
\def\@mathdif#1{\mathinner{#1}\fd@mu@p}
\def\s@mathdif#1{\s@fd@mu@p\mathinner{#1\mbox{}}\fd@mu@p}
\DeclareRobustCommand\mathdif{\@ifstar\s@mathdif\@mathdif}
% \end{macrocode}
% End of the package.
% \begin{macrocode}
%</package>
% \end{macrocode}
\endinput