summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/fixdif/fixdif.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/fixdif/fixdif.dtx')
-rw-r--r--macros/latex/contrib/fixdif/fixdif.dtx191
1 files changed, 84 insertions, 107 deletions
diff --git a/macros/latex/contrib/fixdif/fixdif.dtx b/macros/latex/contrib/fixdif/fixdif.dtx
index c6dfc5a236..e6f37a330f 100644
--- a/macros/latex/contrib/fixdif/fixdif.dtx
+++ b/macros/latex/contrib/fixdif/fixdif.dtx
@@ -131,7 +131,7 @@ Copyright (C) 2022-2023 by Zhang Tingxuan <alphaztx@163.com>.
%</internal>
%
%<*driver>
-\ProvidesFile{fixdif.dtx}[2023/01/27 (c) Copyright 2022-2023 by Zhang Tingxuan]
+\ProvidesFile{fixdif.dtx}[2023/01/31 (c) Copyright 2022-2023 by Zhang Tingxuan]
\documentclass{ltxdoc}
\usepackage{xcolor}
@@ -150,7 +150,7 @@ Copyright (C) 2022-2023 by Zhang Tingxuan <alphaztx@163.com>.
\title{The \pkg{fixdif} Package}
\author{Zhang Tingxuan}
-\date{2023/01/27\quad Version 1.6\thanks{\url{https://github.com/AlphaZTX/fixdif}}}
+\date{2023/01/31\quad Version 2.0\thanks{\url{https://github.com/AlphaZTX/fixdif}}}
\usepackage{hyperref}
\hypersetup{
@@ -188,7 +188,6 @@ Copyright (C) 2022-2023 by Zhang Tingxuan <alphaztx@163.com>.
\g@addto@macro{\UrlBreaks}{\UrlDigits}
\ifdefined\Umathcode
\usepackage{unicode-math}
- \setmathfont{Latin Modern Math}
\fi
\makeatother
@@ -215,7 +214,7 @@ Copyright (C) 2022-2023 by Zhang Tingxuan <alphaztx@163.com>.
% in \XeTeX{} and \LuaTeX.
% \end{abstract}
%
-% \tableofcontents
+% {\parskip1pt plus 1pt\tableofcontents}
%
% \section{The background}
% It's usually recommended that one should reserve a small skip between
@@ -258,39 +257,14 @@ Copyright (C) 2022-2023 by Zhang Tingxuan <alphaztx@163.com>.
% \begin{Verbatim}
% \usepackage{fixdif}
% \end{Verbatim}
-% in the preamble. In your document,
+% 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{When using \pkg{unicode-math}}
-% If you are using \pkg{unicode-math} package with \XeTeX/\LuaTeX{}
-% in your document, you must pay attention to the following items:
-% \begin{itemize}
-% \item If you want to use \pkg{amsmath} package, make sure that the
-% \pkg{unicode-math} package is loaded \emph{after} \pkg{amsmath}.
-%
-% \item You had better specify the math font through the \cs{setmathfont}
-% command provided by \pkg{unicode-math} in order to avoid bad skip in
-% text fraction like $\d y/\d x$.
-%
-% \item Load the \pkg{fixdif} package \emph{after} \pkg{unicode-math}.
-% \end{itemize}
-% Therefore the correct order is
-% \begin{Verbatim}
-% \usepackage{amsmath}
-% \usepackage{unicode-math}
-% \setmathfont{...}[...]
-% \usepackage{fixdif}
-% \end{Verbatim}
-%
-% \subsection{When using \pkg{hyperref}}
-% If you want to use the \pkg{hyperref} package simultaneously,
-% remember to load \pkg{hyperref} \emph{before} the \pkg{fixdif} package,
-% otherwise the \pkg{hyperref} package will cause conflicts.
-%
% \subsection{Basic commands and package options}
% \DescribeMacro{\d}
% The \pkg{fixdif} package provides a \cs{d} command for the differential
@@ -362,7 +336,7 @@ Copyright (C) 2022-2023 by Zhang Tingxuan <alphaztx@163.com>.
% For example, in default, \DescribeMacro{\partialnondif}\cs{partialnondif}
% yields the old partial symbol ``$\partialnondif$''.
%
-% \noindent\textcolor{titlecolor}{\cs{letdif*}\marg{cmd}\marg{csname}}\DescribeMacro{\letdif*}
+% \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
@@ -385,7 +359,7 @@ Copyright (C) 2022-2023 by Zhang Tingxuan <alphaztx@163.com>.
%
% \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}}\DescribeMacro{\newdif*}
+% \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
@@ -409,7 +383,7 @@ Copyright (C) 2022-2023 by Zhang Tingxuan <alphaztx@163.com>.
%
% \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}}\DescribeMacro{\renewdif*}
+% \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*}.
@@ -421,7 +395,7 @@ Copyright (C) 2022-2023 by Zhang Tingxuan <alphaztx@163.com>.
%
% \noindent\textcolor{titlecolor}{\cs{mathdif}\marg{symbol}}\DescribeMacro{\mathdif}
% \hfill(without correction, in math mode only)\\
-%\noindent\textcolor{titlecolor}{\cs{mathdif*}\marg{symbol}}\DescribeMacro{\mathdif*}
+%\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,
@@ -473,62 +447,68 @@ Copyright (C) 2022-2023 by Zhang Tingxuan <alphaztx@163.com>.
% Check the \TeX{} format and provides the package name.
% \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{fixdif}[2023/01/27 Interface for defining differential operators.]
+\ProvidesPackage{fixdif}[2023/01/31 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.
-% \begin{macrocode}
-\@ifpackageloaded{unicode-math}{\AtBeginDocument{%
-% \end{macrocode}
-% If the \pkg{unicode-math} package has been loaded, use the \XeTeX/\LuaTeX{} primitive
+%
+% 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}
- \Umathcode`\/="4 \symoperators "002F
- \Umathcode"2044="4 \symoperators "2044
- \Umathcode"2215="4 \symoperators "2215
- \Umathcode"2F98="4 \symoperators "2F98
- \Umathcode`\\="4 \symoperators "005C
- \Umathcode"2216="4 \symoperators "2216
- \Umathcode"29F5="4 \symoperators "29F5
- \Umathcode"29F9="4 \symoperators "29F9
-}}{
+\AtBeginDocument{%
+\ifcsname symbf\endcsname%
+ \csname bool_if:cF\endcsname{g__um_main_font_defined_bool}%
+ {\csname __um_load_lm:\endcsname}%
+ \Umathcode`\/="4 \symoperators "002F%
+ \Umathcode"2044="4 \symoperators "2044%
+ \Umathcode"2215="4 \symoperators "2215%
+ \Umathcode"2F98="4 \symoperators "2F98%
+ \Umathcode`\\="4 \symoperators "005C%
+ \Umathcode"2216="4 \symoperators "2216%
+ \Umathcode"29F5="4 \symoperators "29F5%
+ \Umathcode"29F9="4 \symoperators "29F9%
+\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}
-% If the \pkg{unicode-math} package has not been loaded, use the \TeX{} primitive
-% \cs{mathcode} to change the type of slashes. The \cs{backslash} needs to be redefined
-% through \cs{delimiter} primitive too.
+% 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
- \def\backslash{\delimiter"426E30F\relax}
-}
+\mathcode`\/="413D
+\mathcode`\\="426E% \backslash
+\protected\def\backslash{\delimiter"426E30F\relax}
% \end{macrocode}
%
% \subsection{Patch the skips around the differential operator}
-% \DescribeMacro{\mup@tch}
-% The following \cs{mup@tch} patches the skip after the differential operator.
+% \DescribeMacro{\fd@mu@p}
+% The following \cs{fd@mu@p} patches the skip after the differential operator.
% \begin{macrocode}
-\def\mup@tch{\mathchoice{\mskip-\thinmuskip}{\mskip-\thinmuskip}{}{}{}}
+\def\fd@mu@p{\mathchoice{\mskip-\thinmuskip}{\mskip-\thinmuskip}{}{}{}}
% \end{macrocode}
-% The \cs{s@beforep@tch} patches the commands with star (\cs{letdif*}, etc).
+% The \cs{s@fd@mu@p} patches the commands with star (\cs{letdif*}, etc).
% \begin{macrocode}
-\def\s@beforep@tch{\mathchoice{}{}{\mbox{}}{\mbox{}}}
+\def\s@fd@mu@p{\mathchoice{}{}{\hbox{}}{\hbox{}}}
% \end{macrocode}
%
% \subsection{Declare the package options}
-% Declare the options of the package and execute them.
% \begin{macrocode}
-\DeclareOption{rm}{\@ifpackageloaded{unicode-math}
- {\def\@@dif{\symrm{d}}}{\def\@@dif{\mathrm{d}}}}
-\DeclareOption{normal}{\def\@@dif{d}}
+\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
-% \end{macrocode}
-% Control the behavior of \cs{partial}.
-% \begin{macrocode}
\if@tempswa
\AtEndOfPackage{\letdif{\partial}{partial}}
\fi
@@ -536,47 +516,41 @@ Copyright (C) 2022-2023 by Zhang Tingxuan <alphaztx@163.com>.
% \DescribeMacro{\resetdfont}
% Define the \cs{resetdfont} command.
% \begin{macrocode}
-\gdef\resetdfont#1{\let\@@dif\relax%
- \def\@@dif{#1{d}}}
+\gdef\resetdfont#1{\AtBeginDocument{\let\@fd@dif\relax\gdef\@fd@dif{#1{d}}}}
% \end{macrocode}
%
% \subsection{Deal with the \cs{d} command}
-% \DescribeMacro{\@dif}
-% \cs{@dif} is the differential operator produced by \cs{d} in math mode.
+% \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\@dif{\mathinner{\@@dif}\mup@tch}
+\def\fd@dif{\mathinner{\@fd@dif}\fd@mu@p}
% \end{macrocode}
-% \DescribeMacro{\d@accent}
-% Restore the \cs{d} command in text by \cs{d@accent} with the \cs{let}
-% primitive.
+% \DescribeMacro{\fd@d@acc}
+% Restore the \cs{d} command in text by \cs{fd@d@acc} with \cs{let}.
% \begin{macrocode}
-\AtBeginDocument{\let\d@accent\d
+\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\@dif\else\expandafter\d@accent\fi}}
+ \DeclareRobustCommand\d{\ifmmode\fd@dif\else\expandafter\fd@d@acc\fi}}
% \end{macrocode}
%
% \subsection{User's interface for defining new differential operators}
-% \DescribeMacro{\letdif}\DescribeMacro{\letdif*}
-% Define the \cs{letdif} and \cs{letdif*} command. The internal version of \cs{letdif}
-% is \cs{@letdif}, of \cs{letdif*} is \cs{s@letdif}.
-% \begin{macrocode}
-\def\@letdif#1#2{\AtBeginDocument{%
-% \end{macrocode}
+% \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%
-% \end{macrocode}
-% Finally let |#1| be the new command.
-% \begin{macrocode}
- \gdef#1{\mathinner{\csname #2nondif\endcsname}\mup@tch}%
+ \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.
@@ -586,56 +560,59 @@ Copyright (C) 2022-2023 by Zhang Tingxuan <alphaztx@163.com>.
\expandafter\let\csname #2nondif\expandafter\endcsname
\csname #2\endcsname%
\fi%
- \gdef#1{\mathinner{\s@beforep@tch\csname #2nondif\endcsname\hbox{}}\mup@tch}%
+ \DeclareRobustCommand#1{\mathinner{\s@fd@mu@p\csname #2nondif\endcsname\hbox{}}\fd@mu@p}%
}}
-\def\letdif{\@ifstar\s@letdif\@letdif}
+\DeclareRobustCommand\letdif{\@ifstar\s@letdif\@letdif}
+\@onlypreamble\letdif
% \end{macrocode}
-% \DescribeMacro{\newdif}\DescribeMacro{\newdif*}
-% Define the \cs{newdif} and \cs{newdif*} commands. |#1| is the final command; |#2| is the ``long'' argument.
+% \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.}
+ \PackageError{fixdif}{\string#1 is already defined}
{Try another command instead of \string#1.}%
\else
- \long\gdef#1{\mathinner{#2}\mup@tch}%
+ \DeclareRobustCommand#1{\mathinner{#2}\fd@mu@p}%
\fi%
}}
\long\def\s@newdif#1#2{\AtBeginDocument{%
\ifdefined#1
- \PackageError{fixdif}{\string#1 is already defined.}
+ \PackageError{fixdif}{\string#1 is already defined}
{Try another command instead of \string#1.}%
\else
- \long\gdef#1{\s@beforep@tch\mathinner{#2\mbox{}}\mup@tch}%
+ \DeclareRobustCommand#1{\s@fd@mu@p\mathinner{#2\hbox{}}\fd@mu@p}%
\fi%
}}
-\def\newdif{\@ifstar\s@newdif\@newdif}
+\DeclareRobustCommand\newdif{\@ifstar\s@newdif\@newdif}
+\@onlypreamble\newdif
% \end{macrocode}
-% \DescribeMacro{\renewdif}\DescribeMacro{\renewdif*}
-% Define the \cs{renewdif} and \cs{renewdif*} commands.
+% \DescribeMacro{\renewdif}
+% Define the \cs{renewdif} command.
% \begin{macrocode}
\long\def\@renewdif#1#2{\AtBeginDocument{%
\ifdefined#1
- \long\gdef#1{\mathinner{#2}\mup@tch}%
+ \DeclareRobustCommand#1{\mathinner{#2}\fd@mu@p}%
\else
- \PackageError{fixdif}{\string#1 has not been defined yet.}
+ \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
- \long\gdef#1{\s@beforep@tch\mathinner{#2\mbox{}}\mup@tch}%
+ \DeclareRobustCommand#1{\s@fd@mu@p\mathinner{#2\hbox{}}\fd@mu@p}%
\else
- \PackageError{fixdif}{\string#1 has not been defined yet.}
+ \PackageError{fixdif}{\string#1 has not been defined yet}
{You should use \string\newdif instead of \string\renewdif.}%
\fi%
}}
-\def\renewdif{\@ifstar\s@renewdif\@renewdif}
+\DeclareRobustCommand\renewdif{\@ifstar\s@renewdif\@renewdif}
+\@onlypreamble\renewdif
% \end{macrocode}
-% \subsection{In-document commands: \cs{mathdif} and \cs{mathdif*}}
+% \subsection{In-document commands: \cs{mathdif}}
% \begin{macrocode}
-\def\@mathdif#1{\mathinner{#1}\mup@tch}
-\def\s@mathdif#1{\s@beforep@tch\mathinner{#1\mbox{}}\mup@tch}
+\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.