| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2022-2023 by Zhang Tingxuan <[email protected]> |
| 4 |
% |
| 5 |
% This work may be distributed and/or modified under the |
| 6 |
% conditions of the LaTeX Project Public License, either |
| 7 |
% version 1.3c of this license or (at your option) any later |
| 8 |
% version. The latest version of this license is in: |
| 9 |
% |
| 10 |
% http://www.latex-project.org/lppl.txt |
| 11 |
% |
| 12 |
% and version 1.3 or later is part of all distributions of |
| 13 |
% LaTeX version 2005/12/01 or later. |
| 14 |
% |
| 15 |
% This work has the LPPL maintenance status `maintained'. |
| 16 |
% |
| 17 |
% The Current Maintainer of this work is Zhang Tingxuan. |
| 18 |
% |
| 19 |
% This work consists of the files fixdif.dtx, |
| 20 |
% and the derived files fixdif.ins, |
| 21 |
% fixdif.sty, |
| 22 |
% fixdif.pdf, |
| 23 |
% and README.md. |
| 24 |
% |
| 25 |
%<*internal> |
| 26 |
\iffalse |
| 27 |
%</internal> |
| 28 |
% |
| 29 |
%<*readme> |
| 30 |
# The `fixdif` Package |
| 31 |
|
| 32 |
The `fixdif` package provides an interface for defining the style of differential operators. |
| 33 |
|
| 34 |
The basic commands are: |
| 35 |
|
| 36 |
- `\d`: for differential operator "d" in math mode and under-dot accent in text; |
| 37 |
- `\partial`: a "fixed" partial differential operator command; |
| 38 |
- `\letdif`: an interface for defining new commands for differential operators; |
| 39 |
- `\mathdif`: a commmand in math mode, you can use it just like `\mathop`, etc. |
| 40 |
|
| 41 |
See `fixdif.pdf` for more. Happy TeXing! |
| 42 |
|
| 43 |
## License |
| 44 |
|
| 45 |
This work may be distributed and/or modified under the conditions of |
| 46 |
the [LaTeX Project Public License](http://www.latex-project.org/lppl.txt), |
| 47 |
either version 1.3c of this license or (at your option) any later version. |
| 48 |
|
| 49 |
------ |
| 50 |
|
| 51 |
Copyright (C) 2022-2023 by Zhang Tingxuan <[email protected]>. |
| 52 |
%</readme> |
| 53 |
% |
| 54 |
%<*internal> |
| 55 |
\fi |
| 56 |
\begingroup |
| 57 |
\def\NameOfLaTeXe{LaTeX2e} |
| 58 |
\expandafter\endgroup\ifx\NameOfLaTeXe\fmtname\else |
| 59 |
\csname fi\endcsname |
| 60 |
%</internal> |
| 61 |
% |
| 62 |
%<*install> |
| 63 |
\input docstrip.tex |
| 64 |
\keepsilent |
| 65 |
|
| 66 |
\preamble |
| 67 |
|
| 68 |
Copyright (C) 2022-2023 by Zhang Tingxuan <[email protected]> |
| 69 |
|
| 70 |
This work may be distributed and/or modified under the |
| 71 |
conditions of the LaTeX Project Public License, either |
| 72 |
version 1.3c of this license or (at your option) any later |
| 73 |
version. The latest version of this license is in: |
| 74 |
|
| 75 |
http://www.latex-project.org/lppl.txt |
| 76 |
|
| 77 |
and version 1.3 or later is part of all distributions of |
| 78 |
LaTeX version 2005/12/01 or later. |
| 79 |
|
| 80 |
This work has the LPPL maintenance status `maintained'. |
| 81 |
|
| 82 |
The Current Maintainer of this work is Zhang Tingxuan. |
| 83 |
|
| 84 |
This work consists of the files fixdif.dtx, |
| 85 |
and the derived files fixdif.ins, |
| 86 |
fixdif.sty, |
| 87 |
fixdif.pdf, |
| 88 |
and README.md. |
| 89 |
|
| 90 |
\endpreamble |
| 91 |
|
| 92 |
\generate{ |
| 93 |
\usedir{tex/latex/fixdif} |
| 94 |
\file{\jobname.sty} {\from{\jobname.dtx}{package}} |
| 95 |
%</install> |
| 96 |
%<*internal> |
| 97 |
\usedir{source/latex/fixdif} |
| 98 |
\file{\jobname.ins} {\from{\jobname.dtx}{install}} |
| 99 |
%</internal> |
| 100 |
%<*install> |
| 101 |
\usedir{doc/latex/fixdif} |
| 102 |
\nopreamble\nopostamble |
| 103 |
\file{README.md} {\from{\jobname.dtx}{readme}} |
| 104 |
} |
| 105 |
|
| 106 |
\obeyspaces |
| 107 |
\Msg{****************************************************} |
| 108 |
\Msg{* *} |
| 109 |
\Msg{* To finish the installation you have to move the *} |
| 110 |
\Msg{* following file into a directory searched by TeX: *} |
| 111 |
\Msg{* *} |
| 112 |
\Msg{* fixdif.sty *} |
| 113 |
\Msg{* *} |
| 114 |
\Msg{* The recommended directory is *} |
| 115 |
\Msg{* TDS:tex/latex/fixdif *} |
| 116 |
\Msg{* *} |
| 117 |
\Msg{* To produce the documentation run the file *} |
| 118 |
\Msg{* fixdif.dtx through pdfLaTeX/XeLaTeX/LuaLaTeX. *} |
| 119 |
\Msg{* XeLaTeX and LuaLaTeX are recommended if you *} |
| 120 |
\Msg{* hope the PDF file to be smaller. *} |
| 121 |
\Msg{* *} |
| 122 |
\Msg{* Happy TeXing! *} |
| 123 |
\Msg{* *} |
| 124 |
\Msg{****************************************************} |
| 125 |
|
| 126 |
\endbatchfile |
| 127 |
%</install> |
| 128 |
% |
| 129 |
%<*internal> |
| 130 |
\fi |
| 131 |
%</internal> |
| 132 |
% |
| 133 |
%<*driver> |
| 134 |
\ProvidesFile{fixdif.dtx}[2023/03/20 (c) Copyright 2022-2023 by Zhang Tingxuan] |
| 135 |
\documentclass{ltxdoc} |
| 136 |
\usepackage{xcolor} |
| 137 |
\definecolor{titlecolor}{RGB}{0,12,160} |
| 138 |
\usepackage{doc} |
| 139 |
\usepackage{fancyvrb} |
| 140 |
\fvset{xleftmargin=2.5em,fontsize=\small,gobble=2} |
| 141 |
\MakeShortVerb| |
| 142 |
\usepackage{hologo} |
| 143 |
\def\XeTeX{\hologo{XeTeX}} |
| 144 |
\def\LuaTeX{\hologo{LuaTeX}} |
| 145 |
\def\pkg{\textsf} |
| 146 |
\def\opt{\texttt} |
| 147 |
\title{The \pkg{fixdif} Package} |
| 148 |
\author{Zhang Tingxuan} |
| 149 |
\date{2023/03/20\quad Version 2.1\thanks{\url{https://github.com/AlphaZTX/fixdif}}} |
| 150 |
\usepackage{hyperref} |
| 151 |
\hypersetup{ |
| 152 |
pdftitle = {The fixdif Package}, |
| 153 |
pdfauthor = {Zhang Tingxuan}, |
| 154 |
pdfcreator = {pdfLaTeX/XeLaTeX/LuaLaTeX}, |
| 155 |
linkcolor = black, |
| 156 |
urlcolor = titlecolor!80!black, |
| 157 |
} |
| 158 |
\def\pkg{\textsf} |
| 159 |
\makeatletter |
| 160 |
\renewcommand\section{\@startsection{section}{1}{\z@}% |
| 161 |
{-2.5ex plus -1ex minus -.2ex}% |
| 162 |
{1ex plus .2ex}% |
| 163 |
{\normalfont\Large\bfseries\color{titlecolor}}} |
| 164 |
\renewcommand\subsection{\@startsection{subsection}{2}{\z@}% |
| 165 |
{-2ex plus -1ex minus -.2ex}% |
| 166 |
{.5ex plus .2ex}% |
| 167 |
{\normalfont\normalsize\bfseries\color{titlecolor}}} |
| 168 |
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}% |
| 169 |
{.8ex plus .4ex minus .2ex}% |
| 170 |
{-1em}% |
| 171 |
{\normalfont\normalsize\bfseries\color{titlecolor}}} |
| 172 |
\def\UrlAlphabet{% |
| 173 |
\do\a\do\b\do\c\do\d\do\e\do\f\do\g\do\h\do\i\do\j% |
| 174 |
\do\k\do\l\do\m\do\n\do\o\do\p\do\q\do\r\do\s\do\t% |
| 175 |
\do\u\do\v\do\w\do\x\do\y\do\z\do\A\do\B\do\C\do\D% |
| 176 |
\do\E\do\F\do\G\do\H\do\I\do\J\do\K\do\L\do\M\do\N% |
| 177 |
\do\O\do\P\do\Q\do\R\do\S\do\T\do\U\do\V\do\W\do\X% |
| 178 |
\do\Y\do\Z} |
| 179 |
\def\UrlDigits{\do\1\do\2\do\3\do\4\do\5\do\6\do\7\do\8\do\9\do\0} |
| 180 |
\g@addto@macro{\UrlBreaks}{\UrlOrds} |
| 181 |
\g@addto@macro{\UrlBreaks}{\UrlAlphabet} |
| 182 |
\g@addto@macro{\UrlBreaks}{\UrlDigits} |
| 183 |
\ifdefined\Umathcode |
| 184 |
\usepackage{unicode-math} |
| 185 |
\fi |
| 186 |
\makeatother |
| 187 |
\usepackage{fixdif} |
| 188 |
\linespread{1.05} |
| 189 |
\parskip6pt plus 2pt minus 1pt |
| 190 |
\parindent2.5em |
| 191 |
\begin{document} |
| 192 |
\DocInput{\jobname.dtx} |
| 193 |
\end{document} |
| 194 |
%</driver> |
| 195 |
% \fi |
| 196 |
% |
| 197 |
% \maketitle |
| 198 |
% |
| 199 |
% \begin{abstract} |
| 200 |
% The \pkg{fixdif} package redefines the \cs{d} command in \LaTeX\ and |
| 201 |
% provides an interface to define commands for differential operators. |
| 202 |
% |
| 203 |
% The package does well with pdf\TeX, \XeTeX\ and \LuaTeX, only works |
| 204 |
% with \LaTeX\ format. Furthermore, this package is compatible with |
| 205 |
% \pkg{unicode-math} package in \XeTeX\ and \LuaTeX. |
| 206 |
% \end{abstract} |
| 207 |
% |
| 208 |
% {\parskip1pt plus 1pt\tableofcontents} |
| 209 |
% |
| 210 |
% \section{The background} |
| 211 |
% It's usually recommended that a small skip should be reserved between |
| 212 |
% the differential operator and the expression before it\footnote{See |
| 213 |
% \url{https://tex.stackexchange.com/questions/14821/whats-the-proper-way-to-typeset-a-differential-operator}.}. |
| 214 |
% Take the following line as an example: |
| 215 |
% \[f(x)\mathrm{d}x\qquad\hbox{and}\qquad f(x)\d x.\] |
| 216 |
% We usually consider that the example on the right side is better than the |
| 217 |
% one on left side. The small skip between $f(x)$ and $\d x$ can be |
| 218 |
% regarded as a binary operator. |
| 219 |
% |
| 220 |
% Some users prefer to define a macro like this: |
| 221 |
% \begin{Verbatim} |
| 222 |
% \renewcommand\d{\mathop{\mathrm{d}}\!} |
| 223 |
% \end{Verbatim} |
| 224 |
% This macro works well in display math and text math, but still appears with |
| 225 |
% the following three problems: |
| 226 |
% \begin{enumerate} |
| 227 |
% \item The skip before ``$\d$'' still exists before the denominator in |
| 228 |
% ``text fraction''. This is what we do not hope to see. For example, |
| 229 |
% |$\d y/\d x$| produces $\mathrm{d}y/\,\mathrm{d}x$. |
| 230 |
% |
| 231 |
% \item |\d| is defined as a text accent command in \LaTeXe\ kernel. If we |
| 232 |
% defined like this, |\d{o}| could not produce ``\d{o}'' in text. |
| 233 |
% |
| 234 |
% \item The skip before ``d'' should behave like skips around a binary operator. |
| 235 |
% It should disappear in script math and script script math. For example, |
| 236 |
% |$a+b$| yields $a+b$ while |$^{a+b}$| yields $^{a+b}$, the skips around ``$+$'' |
| 237 |
% disappear in superscript. But in the definition above, |$^{f(x)\d x}$| |
| 238 |
% yields $^{f(x)\,\mathrm{d}x}$ but not $^{f(x)\d x}$. |
| 239 |
% \end{enumerate} |
| 240 |
% To solve these problems, you can try this package. |
| 241 |
% |
| 242 |
% \section{Introduction} |
| 243 |
% To load this package, write |
| 244 |
% \begin{Verbatim} |
| 245 |
% \usepackage{fixdif} |
| 246 |
% \end{Verbatim} |
| 247 |
% in the preamble. \pkg{fixdif} allows you to write this line anywhere in the |
| 248 |
% preamble since version 2.0. In your document, |
| 249 |
% \begin{Verbatim} |
| 250 |
% \[ f(x)\d x,\quad\frac{\d y}{\d x},\quad\d y/\d x,\quad a^{y\d x}. \] |
| 251 |
% \end{Verbatim} |
| 252 |
% will produce |
| 253 |
% \[f(x)\d x,\quad \frac{\d y}{\d x},\quad \d y/\d x,\quad a^{y\d x}.\] |
| 254 |
% |
| 255 |
% \subsection{Basic commands and package options} |
| 256 |
% \DescribeMacro{\d} |
| 257 |
% The \pkg{fixdif} package provides a \cs{d} command for the differential |
| 258 |
% operator ``d'' in math mode. When in text, \cs{d} behaves just like |
| 259 |
% the old \cs{d} command in \LaTeX\ or plain \TeX\ as an accent command. |
| 260 |
% For example, |
| 261 |
% \begin{Verbatim} |
| 262 |
% $\d x$ and \d x |
| 263 |
% \end{Verbatim} |
| 264 |
% tields ``$\d x$ and \d x''. |
| 265 |
% |
| 266 |
% \paragraph{Set the font of \cs{d}} |
| 267 |
% There are two package options to control the style of \cs{d} in math mode~--- |
| 268 |
% \opt{rm} and \opt{normal}. The default option is \opt{rm}, in which case |
| 269 |
% |$f(x)\d x$| produces $f(x)\d x$. If you chose the \opt{normal} option, |
| 270 |
% that is |
| 271 |
% \begin{Verbatim} |
| 272 |
% \usepackage[normal]{fixdif} |
| 273 |
% \end{Verbatim} |
| 274 |
% |$f(x)\d x$| yields $f(x)\,dx$. |
| 275 |
% |
| 276 |
% \DescribeMacro{\resetdfont} |
| 277 |
% Regardless of the two options above, you can reset the font of \cs{d} |
| 278 |
% through \cs{resetdfont} command in preamble: |
| 279 |
% \begin{Verbatim} |
| 280 |
% \resetdfont{\mathsf} |
| 281 |
% \end{Verbatim} |
| 282 |
% then |$\d x$| yields $\mathsf{d}x$. Notice that the argument of |
| 283 |
% \cs{resetdfont} should be a command with \emph{one} argument. |
| 284 |
% |
| 285 |
% \paragraph{Control the behavior of \cs{partial}} |
| 286 |
% \DescribeMacro{\partial} |
| 287 |
% In default, \cs{partial} will be regarded as a differential operator |
| 288 |
% after you load \pkg{fixdif}. If you don't like this default setting, |
| 289 |
% you can use the \opt{nopartial} option: |
| 290 |
% \begin{Verbatim} |
| 291 |
% \usepackage[nopartial]{fixdif} |
| 292 |
% \end{Verbatim} |
| 293 |
% If you choose to use the default settings, \cs{partialnondif} yields |
| 294 |
% the ordinary symbol ``$\partialnondif$''. |
| 295 |
% |
| 296 |
% \section{Define commands for differential operators} |
| 297 |
% \noindent\emph{Attention! The commands in this section |
| 298 |
% can be used in preamble only!} |
| 299 |
% |
| 300 |
% \subsection{Define commands with a single command name} |
| 301 |
% \noindent\textcolor{titlecolor}{\cs{letdif}\marg{cmd}\marg{csname}}\DescribeMacro{\letdif} |
| 302 |
% \hfill(preamble only) |
| 303 |
% |
| 304 |
% The \cs{letdif} command takes two arguments~--- the first is the newly-defined |
| 305 |
% command and the second is the control sequence \emph{name} of a math character, |
| 306 |
% that is, a command without its backslash. For example, |
| 307 |
% \begin{Verbatim} |
| 308 |
% \letdif{\vr}{delta} |
| 309 |
% \end{Verbatim} |
| 310 |
% then |\vr| will produce a $\delta$ (|\delta|) with automatic skip |
| 311 |
% before it. |
| 312 |
% |
| 313 |
% Through the \cs{letdif} command, we can redefine a math character command |
| 314 |
% by its name. For example, |
| 315 |
% \begin{Verbatim} |
| 316 |
% \letdif{\delta}{delta} |
| 317 |
% \end{Verbatim} |
| 318 |
% then |\delta| itself will be a differential operator. |
| 319 |
% |
| 320 |
% The second argument \meta{csname} of \cs{letdif} command can be used |
| 321 |
% repeatedly. If you want to get the ordinary symbol of |
| 322 |
% \texttt{\char`\\\textnormal{\meta{csname}}}, you can input |
| 323 |
% \texttt{\char`\\\textnormal{\meta{csname}}nondif} in math mode. |
| 324 |
% For example, in default, \DescribeMacro{\partialnondif}\cs{partialnondif} |
| 325 |
% yields the old partial symbol ``$\partialnondif$''. |
| 326 |
% |
| 327 |
% \noindent\textcolor{titlecolor}{\cs{letdif*}\marg{cmd}\marg{csname}} |
| 328 |
% \hfill(preamble only) |
| 329 |
% |
| 330 |
% This command is basically the same as \cs{letdif}, but this command will |
| 331 |
% patch a correction after the differential operator. This is very useful |
| 332 |
% when a math font is setted through \pkg{unicode-math} package. For example, |
| 333 |
% \begin{Verbatim} |
| 334 |
% \usepackage{unicode-math} |
| 335 |
% \setmathfont{TeX Gyre Termes Math} |
| 336 |
% \usepackage{fixdif} |
| 337 |
% \letdif{\vr}{updelta} |
| 338 |
% \end{Verbatim} |
| 339 |
% this will cause bad negative skip after |\vr|, but if you change the last |
| 340 |
% line into |
| 341 |
% \begin{Verbatim} |
| 342 |
% \letdif*{\vr}{updelta} |
| 343 |
% \end{Verbatim} |
| 344 |
% you will get the result correct. |
| 345 |
% |
| 346 |
% \subsection{Define commands with multi commands or a string} |
| 347 |
% |
| 348 |
% \noindent\textcolor{titlecolor}{\cs{newdif}\marg{cmd}\marg{multi-cmd}}\DescribeMacro{\newdif} |
| 349 |
% \hfill(without correction, preamble only)\\ |
| 350 |
% \noindent\textcolor{titlecolor}{\cs{newdif*}\marg{cmd}\marg{multi-cmd}} |
| 351 |
% \hfill(with correction, preamble only) |
| 352 |
% |
| 353 |
% The first argument of these commands is the newly-defined command; and the |
| 354 |
% second argument should contain \emph{more than one} tokens. |
| 355 |
% For example, if you have loaded the \pkg{xcolor} package, |
| 356 |
% you can use the following line: |
| 357 |
% \begin{Verbatim} |
| 358 |
% \newdif{\redsfd}{\textsf{\color{red}d}} |
| 359 |
% \end{Verbatim} |
| 360 |
% Then you get the |\redsfd| as a differential operator. Take another example, |
| 361 |
% \begin{Verbatim} |
| 362 |
% \newdif{\D}{\mathrm{D}} |
| 363 |
% \end{Verbatim} |
| 364 |
% Then you get |\D| for an uppercase upright ``D'' as a differential operator. |
| 365 |
% |
| 366 |
% If your second argument contains only one command like |\Delta|, |
| 367 |
% it's recommended to use \cs{letdif} or \cs{letdif*} instead. |
| 368 |
% |
| 369 |
% \cs{newdif} and \cs{newdif*} will check whether \meta{cmd} has been defined |
| 370 |
% already. If so, an error message will be given. |
| 371 |
% |
| 372 |
% \noindent\textcolor{titlecolor}{\cs{renewdif}\marg{cmd}\marg{multi-cmd}}\DescribeMacro{\renewdif} |
| 373 |
% \hfill(without correction, preamble only)\\ |
| 374 |
% \noindent\textcolor{titlecolor}{\cs{renewdif*}\marg{cmd}\marg{multi-cmd}} |
| 375 |
% \hfill(with correction, preamble only) |
| 376 |
% |
| 377 |
% These two commands are basically the same as \cs{newdif} and \cs{newdif*}. |
| 378 |
% The only difference is that \cs{renewdif} and \cs{renewdif*} will check |
| 379 |
% whether \meta{cmd} has \emph{not} been defined yet. If so, an error message |
| 380 |
% will be given. |
| 381 |
% |
| 382 |
% \section{Using differential operators temporarily} |
| 383 |
% |
| 384 |
% \noindent\textcolor{titlecolor}{\cs{mathdif}\marg{symbol}}\DescribeMacro{\mathdif} |
| 385 |
% \hfill(without correction, in math mode only)\\ |
| 386 |
%\noindent\textcolor{titlecolor}{\cs{mathdif*}\marg{symbol}} |
| 387 |
% \hfill(with correction, in math mode only) |
| 388 |
% |
| 389 |
% These two commands can be used in math mode only, more specifically, |
| 390 |
% after \verb|\begin{document}|. For example, \verb|$x\mathdif{\Delta}\psi$| |
| 391 |
% will get $x\mathdif{\Delta}\psi$. |
| 392 |
% |
| 393 |
% \section{Examples} |
| 394 |
% |
| 395 |
% This section shows how to use this package properly in your document. |
| 396 |
% |
| 397 |
% Take the two examples below: |
| 398 |
% \begin{Verbatim} |
| 399 |
% \letdif{\Delta}{Delta} % Example 1, in preamble |
| 400 |
% \letdif{\nabla}{nabla} % Example 2, in preamble |
| 401 |
% \end{Verbatim} |
| 402 |
% Actually, the second example is more reasonable. |
| 403 |
% Sometimes, we take ``$\Delta$'' as laplacian (equivalent to $\nabla^2$), |
| 404 |
% while ``$\Delta$'' can also be regarded as a variable |
| 405 |
% or function at some other times. Consequently, it's better to save |
| 406 |
% a different command for ``$\Delta$'' as laplacian while reserve |
| 407 |
% \verb|\Delta| as a command for an ordinary math symbol ``$\Delta$''. |
| 408 |
% However, in the vast majority of cases, ``$\nabla$'' is regarded as |
| 409 |
% nabla operator so there is no need to save a different command for |
| 410 |
% ``$\nabla$''. Then we can correct the code above: |
| 411 |
% \begin{Verbatim} |
| 412 |
% \letdif{\laplacian}{Delta} % Example 1, corrected, in preamble |
| 413 |
% \end{Verbatim} |
| 414 |
% With the \pkg{xparse} package, we can define the command in another method: |
| 415 |
% \begin{Verbatim} |
| 416 |
% \letdif{\nabla}{nabla} |
| 417 |
% \DeclareDocumentCommand{ \laplacian }{ s }{ |
| 418 |
% \IfBooleanTF{#1}{\mathdif{\Delta}}{\nabla^2} |
| 419 |
% } |
| 420 |
% \end{Verbatim} |
| 421 |
% Then \verb|\laplacian| produces $\nabla^2$ and \verb|\laplacian*| |
| 422 |
% produces $\Delta$. |
| 423 |
% |
| 424 |
% \paragraph{Dealing with ``$+$'' and ``$-$''} |
| 425 |
% If you input \verb|$-\d x$|, you'll get ``$-\d x$'' in your document. |
| 426 |
% However, if you think ``$-{\d x}$'' is better, you can input |
| 427 |
% \verb|-{\d x}|. The ``\verb|\d x|'' in a \emph{group} will be |
| 428 |
% regarded \textsl{ordinary} but not \textsl{inner} so that the |
| 429 |
% small skip will disappear. Maybe ``$-\d x$'' is just okay. |
| 430 |
% |
| 431 |
% \section{The source code} |
| 432 |
% \begin{macrocode} |
| 433 |
%<*package> |
| 434 |
% \end{macrocode} |
| 435 |
% Check the \TeX{} format and provides the package name. |
| 436 |
% \begin{macrocode} |
| 437 |
\NeedsTeXFormat{LaTeX2e} |
| 438 |
\ProvidesPackage{fixdif}[2023/03/20 Interface for defining differential operators.] |
| 439 |
% \end{macrocode} |
| 440 |
% |
| 441 |
% \subsection{Control the skip between slashes and differential operator} |
| 442 |
% Change the math code of slash ($/$) and backslash ($\backslash$) so that the skip |
| 443 |
% between slashes and differential operators can be ignored. |
| 444 |
% |
| 445 |
% If the \pkg{unicode-math} package was loaded, use the \XeTeX/\LuaTeX{} primitive |
| 446 |
% \cs{Umathcode} to change the type of slashes. The numeral ``4'' stands for ``open''. |
| 447 |
% If \pkg{unicode-math} was not loaded but \pkg{fontspec} loaded, check if |
| 448 |
% \pkg{fontspec} had reset math fonts, that is to say, the |no-math| option. |
| 449 |
% \begin{macrocode} |
| 450 |
\AtBeginDocument{% |
| 451 |
\ifcsname symbf\endcsname% |
| 452 |
\csname bool_if:cF\endcsname{g__um_main_font_defined_bool}% |
| 453 |
{\csname __um_load_lm:\endcsname}% |
| 454 |
\def\fd@patchUmathcode#1{% 16777216 = 16^6 |
| 455 |
\@tempcnta=\numexpr(\the\Umathcodenum#1-#1)/16777216\relax |
| 456 |
\Umathcode #1 = "4 \@tempcnta #1}% |
| 457 |
\fd@patchUmathcode{"2F}% |
| 458 |
\fd@patchUmathcode{"5C}% |
| 459 |
\else\ifcsname fontspec\endcsname |
| 460 |
\csname bool_if:cT\endcsname{g__fontspec_math_bool}% |
| 461 |
{% |
| 462 |
\everymath{\mathcode`\/="413D\relax}% |
| 463 |
\PackageWarning{fixdif}{Requires `no-math' option of fontspec!\MessageBreak}% |
| 464 |
}% fontspec only influences "/" |
| 465 |
\fi\fi} |
| 466 |
% \end{macrocode} |
| 467 |
% Use \cs{mathcode} to change the type of slashes. The \cs{backslash} needs to be |
| 468 |
% redefined through \cs{delimiter} too. |
| 469 |
% \begin{macrocode} |
| 470 |
\mathcode`\/="413D |
| 471 |
\mathcode`\\="426E% \backslash |
| 472 |
\protected\def\backslash{\delimiter"426E30F\relax} |
| 473 |
% \end{macrocode} |
| 474 |
% |
| 475 |
% \subsection{Patch the skips around the differential operator} |
| 476 |
% \DescribeMacro{\fd@mu@p} |
| 477 |
% The following \cs{fd@mu@p} patches the skip after the differential operator. |
| 478 |
% \begin{macrocode} |
| 479 |
\def\fd@mu@p{\mathchoice{\mskip-\thinmuskip}{\mskip-\thinmuskip}{}{}{}} |
| 480 |
% \end{macrocode} |
| 481 |
% The \cs{s@fd@mu@p} patches the commands with star (\cs{letdif*}, etc). |
| 482 |
% \begin{macrocode} |
| 483 |
\def\s@fd@mu@p{\mathchoice{}{}{\hbox{}}{\hbox{}}} |
| 484 |
% \end{macrocode} |
| 485 |
% |
| 486 |
% \subsection{Declare the package options} |
| 487 |
% \begin{macrocode} |
| 488 |
\DeclareOption{rm}{% |
| 489 |
\AtBeginDocument{\ifcsname symbf\endcsname% |
| 490 |
\gdef\@fd@dif{\symrm{d}}\fi}% |
| 491 |
\gdef\@fd@dif{\mathrm{d}}} |
| 492 |
\DeclareOption{normal}{\gdef\@fd@dif{d}} |
| 493 |
\DeclareOption{partial}{\@tempswatrue} |
| 494 |
\DeclareOption{nopartial}{\@tempswafalse} |
| 495 |
\ExecuteOptions{rm,partial} |
| 496 |
\ProcessOptions\relax |
| 497 |
\if@tempswa |
| 498 |
\AtEndOfPackage{\letdif{\partial}{partial}} |
| 499 |
\fi |
| 500 |
% \end{macrocode} |
| 501 |
% \DescribeMacro{\resetdfont} |
| 502 |
% Define the \cs{resetdfont} command. |
| 503 |
% \begin{macrocode} |
| 504 |
\gdef\resetdfont#1{\AtBeginDocument{\let\@fd@dif\relax\gdef\@fd@dif{#1{d}}}} |
| 505 |
% \end{macrocode} |
| 506 |
% |
| 507 |
% \subsection{Deal with the \cs{d} command} |
| 508 |
% \DescribeMacro{\fd@dif} |
| 509 |
% \cs{fd@dif} is the differential operator produced by \cs{d} in math mode. |
| 510 |
% Here we prefer \cs{mathinner} to |\mathbin| to make the skip. |
| 511 |
% \begin{macrocode} |
| 512 |
\def\fd@dif{\mathinner{\@fd@dif}\fd@mu@p} |
| 513 |
% \end{macrocode} |
| 514 |
% \DescribeMacro{\fd@d@acc} |
| 515 |
% Restore the \cs{d} command in text by \cs{fd@d@acc} with \cs{let}. |
| 516 |
% \begin{macrocode} |
| 517 |
\AtBeginDocument{\let\fd@d@acc\d |
| 518 |
% \end{macrocode} |
| 519 |
% \DescribeMacro{\d} |
| 520 |
% Redefine the \cs{d} command. In text, we need to expand the stuffs after \cs{d} |
| 521 |
% \begin{macrocode} |
| 522 |
\DeclareRobustCommand\d{\ifmmode\fd@dif\else\expandafter\fd@d@acc\fi}} |
| 523 |
% \end{macrocode} |
| 524 |
% |
| 525 |
% \subsection{User's interface for defining new differential operators} |
| 526 |
% \DescribeMacro{\letdif} |
| 527 |
% Define the \cs{letdif} command. The internal version of \cs{letdif} |
| 528 |
% is \cs{@letdif} and \cs{s@letdif}. |
| 529 |
% |
| 530 |
% |#1| is the final command; |#2| is the ``control sequence name'' of |#1|'s initial definition. |
| 531 |
% Here we create a command (\cs{csname}|#2nonfif|\cs{endcsname}) to restore |#2|. |
| 532 |
% \begin{macrocode} |
| 533 |
\def\@letdif#1#2{\AtBeginDocument{% |
| 534 |
\ifcsname #2nondif\endcsname\else% |
| 535 |
\expandafter\let\csname #2nondif\expandafter\endcsname |
| 536 |
\csname #2\endcsname% |
| 537 |
\fi% |
| 538 |
\DeclareRobustCommand#1{\mathinner{\csname #2nondif\endcsname}\fd@mu@p}% |
| 539 |
}} |
| 540 |
% \end{macrocode} |
| 541 |
% The definition of \cs{s@letdif} is similar, but with the patch for negative skips. |
| 542 |
% \begin{macrocode} |
| 543 |
\def\s@letdif#1#2{\AtBeginDocument{% |
| 544 |
\ifcsname #2nondif\endcsname\else% |
| 545 |
\expandafter\let\csname #2nondif\expandafter\endcsname |
| 546 |
\csname #2\endcsname% |
| 547 |
\fi% |
| 548 |
\DeclareRobustCommand#1{\mathinner{\s@fd@mu@p\csname #2nondif\endcsname\hbox{}}\fd@mu@p}% |
| 549 |
}} |
| 550 |
\DeclareRobustCommand\letdif{\@ifstar\s@letdif\@letdif} |
| 551 |
\@onlypreamble\letdif |
| 552 |
% \end{macrocode} |
| 553 |
% \DescribeMacro{\newdif} |
| 554 |
% Define the \cs{newdif} command. |#1| is the final command; |#2| is the ``long'' argument. |
| 555 |
% \begin{macrocode} |
| 556 |
\long\def\@newdif#1#2{\AtBeginDocument{% |
| 557 |
\ifdefined#1 |
| 558 |
\PackageError{fixdif}{\string#1 is already defined} |
| 559 |
{Try another command instead of \string#1.}% |
| 560 |
\else |
| 561 |
\DeclareRobustCommand#1{\mathinner{#2}\fd@mu@p}% |
| 562 |
\fi% |
| 563 |
}} |
| 564 |
\long\def\s@newdif#1#2{\AtBeginDocument{% |
| 565 |
\ifdefined#1 |
| 566 |
\PackageError{fixdif}{\string#1 is already defined} |
| 567 |
{Try another command instead of \string#1.}% |
| 568 |
\else |
| 569 |
\DeclareRobustCommand#1{\s@fd@mu@p\mathinner{#2\hbox{}}\fd@mu@p}% |
| 570 |
\fi% |
| 571 |
}} |
| 572 |
\DeclareRobustCommand\newdif{\@ifstar\s@newdif\@newdif} |
| 573 |
\@onlypreamble\newdif |
| 574 |
% \end{macrocode} |
| 575 |
% \DescribeMacro{\renewdif} |
| 576 |
% Define the \cs{renewdif} command. |
| 577 |
% \begin{macrocode} |
| 578 |
\long\def\@renewdif#1#2{\AtBeginDocument{% |
| 579 |
\ifdefined#1 |
| 580 |
\DeclareRobustCommand#1{\mathinner{#2}\fd@mu@p}% |
| 581 |
\else |
| 582 |
\PackageError{fixdif}{\string#1 has not been defined yet} |
| 583 |
{You should use \string\newdif instead of \string\renewdif.}% |
| 584 |
\fi% |
| 585 |
}} |
| 586 |
\long\def\s@renewdif#1#2{\AtBeginDocument{% |
| 587 |
\ifdefined#1 |
| 588 |
\DeclareRobustCommand#1{\s@fd@mu@p\mathinner{#2\hbox{}}\fd@mu@p}% |
| 589 |
\else |
| 590 |
\PackageError{fixdif}{\string#1 has not been defined yet} |
| 591 |
{You should use \string\newdif instead of \string\renewdif.}% |
| 592 |
\fi% |
| 593 |
}} |
| 594 |
\DeclareRobustCommand\renewdif{\@ifstar\s@renewdif\@renewdif} |
| 595 |
\@onlypreamble\renewdif |
| 596 |
% \end{macrocode} |
| 597 |
% \subsection{In-document commands: \cs{mathdif}} |
| 598 |
% \begin{macrocode} |
| 599 |
\def\@mathdif#1{\mathinner{#1}\fd@mu@p} |
| 600 |
\def\s@mathdif#1{\s@fd@mu@p\mathinner{#1\mbox{}}\fd@mu@p} |
| 601 |
\DeclareRobustCommand\mathdif{\@ifstar\s@mathdif\@mathdif} |
| 602 |
% \end{macrocode} |
| 603 |
% End of the package. |
| 604 |
% \begin{macrocode} |
| 605 |
%</package> |
| 606 |
% \end{macrocode} |
| 607 |
\endinput |