summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/fixdif/fixdif-zh-cn.tex
blob: df9fb1a7b58af039a4cbcc731c866df279a1da70 (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
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
\documentclass[letterpaper,11pt]{article}
\usepackage{indentfirst}

\usepackage{manfnt,marginnote}
\newcounter{fixdifattention}
\newcommand\attention[1][1]{\setcounter{fixdifattention}{1}%
  \ifnum#1=1 \def\attentiontext{\dbend}\else
  \def\attentiontext{\loop\dbend\,%
    \addtocounter{fixdifattention}{1}%
    \ifnum \value{fixdifattention}<#1 \repeat\dbend}\fi%
  \marginnote{\makebox[0pt][r]{\attentiontext}}}

\usepackage{xcolor}
\definecolor{titlecolor}{RGB}{0,128,8}

\usepackage{fontspec}
\setmainfont{STIX Two Text}
\setsansfont{Inter}[Scale=MatchLowercase]
\setmonofont{Noto Sans Mono}[Scale=MatchLowercase]
\usepackage{xeCJK,xeCJKfntef}
\setCJKmainfont{Source Han Serif SC}
\setCJKsansfont{Source Han Sans SC}
\setCJKmonofont{Source Han Sans SC}
\renewcommand\abstractname{摘\hskip.8em 要}
\renewcommand\contentsname{目\hskip.8em 录}
\DeclareRobustCommand\zhemph{\CJKunderdot}
\usepackage{unicode-math}
\setmathfont{STIX Two Math}

\usepackage{doc}
\DeclareRobustCommand\marg[1]{\texttt{\{}\meta{#1}\texttt{\}}}

\usepackage{fancyvrb}
\fvset{xleftmargin=2em,fontsize=\small}
\MakeShortVerb|

\usepackage{hologo}
\DeclareRobustCommand\XeTeX{\hologo{XeTeX}}
\DeclareRobustCommand\LuaTeX{\hologo{LuaTeX}}

\DeclareRobustCommand\pkg{\textsf}
\DeclareRobustCommand\opt{\texttt}

\usepackage{hyperref}
\hypersetup{pdffitwindow,
  pdftitle   = {fixdif 宏包(中文文档)},
  pdfauthor  = {AlphaZTX},
  pdfcreator = {pdfLaTeX/XeLaTeX/LuaLaTeX},
  linkcolor  = black,
  urlcolor   = titlecolor!75!black,
}

\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}%
  {\indent\normalfont\normalsize\bfseries\color{titlecolor}}}
\def\ps@plain{\let\@mkboth\@gobbletwo
  \def\@oddhead{\hbox{}\llap{\raisebox{-24.44cm}[0pt][0pt]{%
    \sffamily\bfseries\color{titlecolor!10}\fontsize{238pt}{0pt}\selectfont%
    \char"66\char"69\char"78\char"64\char"69\char"66}%
    \hspace*{-14.72cm}}\hfil\hbox{}\rlap{\raisebox{.2cm}[0pt][0pt]{%
    \hspace*{1.4cm}\sffamily\bfseries\color{titlecolor!35}%
    \fontsize{128pt}{0pt}\selectfont\thepage}}}%
  \def\@oddfoot{\reset@font}\let\@evenhead\@oddhead\let\@evenfoot\@oddfoot}
\makeatother
\pagestyle{plain}

\usepackage{fixdif}

\linespread{1.2}
\parskip8pt plus 4pt minus 2pt
\parindent2em

\title{\bfseries\pkg{fixdif} 宏包}
\author{AlphaZTX}
\date{2022/7/27\quad Version 1.3b%
  \thanks{源代码见~\hyperref{https://github.com/AlphaZTX/fixdif}{}{}{GitHub} 
  或~\hyperref{https://www.ctan.org/pkg/fixdif}{}{}{CTAN},或~\texttt{texdoc 
  fixdif}。}
}

\begin{document}
\maketitle
\thispagestyle{plain}

\begin{abstract}
\pkg{fixdif} 宏包重定义了 \LaTeX{} 中的 \cs{d} 命令,使之在数学模式下可以得到
微分算符 $\d{}$,在正文中仍然是原来的重音符号(例如 |\d{o}| 得到 \d o)。

本宏包支持不同的编译方式,在  pdf\TeX、\XeTeX{} 和 \LuaTeX{} 均可使用。本宏包在 
\XeTeX{} 和 \LuaTeX{} 下兼容 \pkg{unicode-math} 宏包。
\end{abstract}

{\parskip0pt
\tableofcontents
}

\section{背景}
我们一般更推荐在微分算符与前面的内容之间留出一个比较小的间距\footnote{%
见 \hyperref{https://tex.stackexchange.com/questions/14821/whats-the-%
proper-way-to-typeset-a-differential-operator}{}{}{\TeX.SX}。},比如在下面展示的
两种情况中,右边的比左边的更好:
\[f(x)\mathrm{d}x\qquad\text{\&}\qquad f(x)\d x.\]
微分算符 $\d{}$ 与其前面的表达式之间的间距可认为是乘积的一种表示。

有些用户习惯使用下面的方法定义一个宏:
\begin{Verbatim}
\renewcommand\d{\mathop{\mathrm{d}}\!}
\end{Verbatim}
这个命令在很多情况下不会产生什么大问题,但是在下面给出的 3 个使用场景下就会出现
不容忽略的问题:
\begin{enumerate}
\item 当 $\d{}$ 出现在用斜杠表示的分式的分母中时,$\d{}$ 前面会留出多余的间距。
例如 |$\d y/\d x$| 得到 $\mathrm{d}y/\,\mathrm{d}x$;

\item 上面定义的 \cs{d} 会覆盖原来的 \cs{d} 命令。在 \LaTeX{} 的原始定义下,\cs{d} 
是一个重音符号命令,用来产生字母下方的点。如果使用了上面的定义,则在正文中 |\d{o}| 
将不会得到“\d{o}”而是得到一条报错。

\item 前面说到,$\d{}$ 前面的间距可以认为是乘积的一种表示,因此这个间距可被视为
一个二元运算符。在上下标中时,二元运算符在两侧的间距应当消失,例如 $a+b$ 放到上标
中就会变成 $^{a+b}$。但是通过上面的方法定义的 \cs{d} 在上下标中,其前面的间距不会
消失,例如 |$a^{f(x)\d x}$| 会得到 $a^{f(x)\,\mathrm{d}x}$ 而不是 $a^{f(x)\d x}$。
\end{enumerate}
面对以上问题,解决方案是使用本宏包。

\section{宏包简介}
在导言区添加
\begin{Verbatim}
\usepackage{fixdif}
\end{Verbatim}
以使用本宏包。使用了本宏包后,在正文中输入
\begin{Verbatim}
\[ f(x)\d x,          \quad    \frac{\d y}{\d x}, 
   \quad\d y/\d x,    \quad    a^{y\d x}.         \]
\end{Verbatim}
会得到
\[f(x)\d x,\quad \frac{\d y}{\d x},\quad \d y/\d x,\quad a^{y\d x}.\]

\subsection{对 \pkg{unicode-math} 宏包的兼容}
如果你在文档中使用了 \pkg{unicode-math} 宏包(编译方式为 \XeTeX{} 或 \LuaTeX{}),
需注意以下几点:
\begin{itemize}
\item 如需使用 \pkg{amsmath} 宏包,请在 \pkg{unicode-math} \zhemph{之前}%
载入 \pkg{amsmath}。

\item 在载入 \pkg{unicode-math} 后通过 \cs{setmathfont} 指定数学字体。
若使用默认的数学字体,建议显式指明 |\setmathfont{Latin Modern Math}|,
这样可以避免在用斜杠表示的分式中产生不好的间距;

\item \pkg{fixdif} 宏包需要在 \pkg{unicode-math} 宏包\zhemph{后}载入。
\end{itemize}
从而,引入宏包的正确顺序是:
\begin{Verbatim}
\usepackage{amsmath}
\usepackage{unicode-math}
\setmathfont{...}[...]
\usepackage{fixdif}
\end{Verbatim}

\subsection{对 \pkg{hyperref} 宏包的兼容}
如果你使用了 \pkg{hyperref} 宏包,需注意 \pkg{fixdif} 宏包需要在 \pkg{hyperref} 
之后载入,否则会引起冲突。

\subsection{基本命令及宏包选项}
\DescribeMacro{\d}
\pkg{fixdif} 宏包提供了 \cs{d} 命令用于在数学模式中得到微分算符“$\d{}$”。
在正文中,\cs{d} 会保留其原有的重音符号的功能。例如:
\begin{Verbatim}
$\d x$ 和 \d x
\end{Verbatim}
以上代码会得到“$\d x$ 和 \d x”。

\paragraph{设置 \cs{d} 的字体}
本宏包提供了两个选项来控制 \cs{d} 的字体,分别为 \opt{rm} 和 \opt{normal}。
其中,\opt{rm} 为默认值,表示 \cs{d} 的字体为罗马体(\cs{mathrm});
\opt{normal} 表示 \cs{d} 的字体为数学模式下的常规体(\cs{mathnormal}),
效果类似于意大利体。例如在载入宏包时开启 \opt{normal} 选项:
\begin{Verbatim}
\usepackage[normal]{fixdif} % 导言区
\end{Verbatim}
正文中的 |$f(x)\d x$| 会得到 $f(x)\,dx$。

\DescribeMacro{\resetdfont}
除了上面的两种字体,\pkg{fixdif} 也支持通过在导言区使用 \cs{resetdfont} 命令
自定义 \cs{d} 的字体。例如:
\begin{Verbatim}
\resetdfont{\mathsf}        % 导言区
\end{Verbatim}
在此设置下,正文中的 |\d x| 会得到 $\mathsf{d}x$。

\paragraph{\cs{partial} 的行为}
\DescribeMacro{\partial}
\pkg{fixdif} 宏包将 \cs{partial} 归为微分算符,正文中的 \cs{partial} 前面也会有
自动的间距。例如 |$\partial x\partial y$| 会得到 $\partial x\partial y$。
若不需要将 \cs{partial} 视为微分算符,可以开启 \opt{nopartial} 选项:
\begin{Verbatim}
\usepackage[nopartial]{fixdif}
\end{Verbatim}

\section{通过 \pkg{fixdif} 定义微分算符命令}
{\attention[6]}注意!本节中的命令只能在\zhemph{导言区}中使用!


\subsection{通过命令名称定义微分算符命令}
\noindent\textcolor{titlecolor}{\cs{letdif}\marg{cmd}\marg{csname}}%
\DescribeMacro{\letdif}\hfill(仅限在导言区使用)

\cs{letdif} 命令有两个参数:第一个参数 \meta{cmd} 是新定义的微分算符命令,
以反斜杠开头;第二个参数 \meta{csname} 是需要设置为微分算符的数学符号的命令名称,
也就是一个完整的命令去掉最前面的反斜杠。举个例子:
\begin{Verbatim}
\letdif{\vr}{delta}
\end{Verbatim}
这样定义的 |\vr| 在数学模式中就相当于一个 |\delta|,但是它的前面会加上自动的间距。

通过 \cs{letdif} 命令,我们可以原封不动地把一个数学符号变成微分算符。例如:
\begin{Verbatim}
\letdif{\delta}{delta}
\end{Verbatim}
这样 |\delta| 本身就会具备微分算符的属性。

\cs{letdif} 的第二个参数 \meta{csname} 可以重复使用,也就是说,你可以把同一个符号
定义为两个不同的微分算符命令。例如:
\begin{Verbatim}
\letdif{\nabla}{nabla}
\letdif{\grad}{nabla}
\end{Verbatim}
这样 |\nabla| 和 |\grad| 都会得到微分算符 $\nabla$。

\noindent\textcolor{titlecolor}{\cs{letdif*}\marg{cmd}\marg{csname}}%
\DescribeMacro{\letdif*}\hfill(仅限在导言区使用)

\cs{letdif*} 与 \cs{letdif} 基本相同,唯一的区别在于 \cs{letdif*} 会在微分算符
后面添加额外的矫正。建议在使用了 \pkg{unicode-math} 的文档中使用 \cs{letdif*}。
例如:
\begin{Verbatim}
\usepackage{unicode-math}
\setmathfont{TeX Gyre Termes Math}
\usepackage{fixdif}
\letdif{\vr}{updelta}
\end{Verbatim}
这样定义的 |\vr| 后面就会有负的间距,如果不希望得到这一负间距,可以把上面的最后一行
改为:
\begin{Verbatim}
\letdif*{\vr}{updelta}
\end{Verbatim}

\subsection{定义包含多个命令或字符的微分算符命令}

\noindent\textcolor{titlecolor}{\cs{newdif}\marg{cmd}\marg{multi-cmd}}%
\DescribeMacro{\newdif}\hfill(仅限在导言区使用,后无矫正)\\
\noindent\textcolor{titlecolor}{\cs{newdif*}\marg{cmd}\marg{multi-cmd}}%
\DescribeMacro{\newdif*}\hfill(仅限在导言区使用,后有矫正)

上面两个命令的第一个参数 \meta{cmd} 是新定义的微分算符命令,第二个参数 
\meta{multi-cmd} 是超过一个字(token)的命令组合或字符串。举个例子,在 
\pkg{xcolor} 宏包下可以这样使用:
\begin{Verbatim}
\newdif{\redsfd}{\textsf{\color{red}d}}
\end{Verbatim}
这样就定义了一个 |\redsfd| 命令。再举一个例子:
\begin{Verbatim}
\newdif{\D}{\mathrm{D}}
\end{Verbatim}
这样,在正文中输入 |$y\D x$| 就会得到 $y\,\mathrm{D}x$。

{\attention[2]}如果 \cs{newdif}(\texttt{*}) 后面的第二个参数 \meta{multi-cmd} 
仅包含一个字(token),也就是一个命令或字符,请使用 \cs{letdif}(\texttt{*}) 命令
而不是 \cs{newdif}(\texttt{*})。

\cs{newdif}(\texttt{*}) 会检查第一个参数 \meta{cmd} 是否已经被定义,若 \meta{cmd} 
已被定义,则会报错。

\noindent\textcolor{titlecolor}{\cs{renewdif}\marg{cmd}\marg{multi-cmd}}\DescribeMacro{\renewdif}
\hfill(仅限在导言区使用,后无矫正)\\
\noindent\textcolor{titlecolor}{\cs{renewdif*}\marg{cmd}\marg{multi-cmd}}\DescribeMacro{\renewdif*}
\hfill(仅限在导言区使用,后有矫正)

这两个命令用于将 \meta{cmd} 重定义为微分算符命令。
若 \meta{cmd} 还未被定义,则会报错。

\section{正文中临时的微分算符命令}
\noindent\textcolor{titlecolor}{\cs{mathdif}\marg{symbol}}%
\DescribeMacro{\mathdif}\hfill(仅限在数学模式使用,后无矫正)\\ 
\noindent\textcolor{titlecolor}{\cs{mathdif*}\marg{symbol}}%
\DescribeMacro{\mathdif*}\hfill(仅限在数学模式使用,后有矫正)

如需在正文中少量使用某一数学符号作为微分算符,可以使用上面的两个命令。
例如,\verb|$x\mathdif{\Delta}\psi$| 会得到 $x\mathdif{\Delta}\psi$。

\section{举例}

本节将告诉你如何在文档中正确使用 \pkg{fixdif} 宏包。

看以下两行代码:
\begin{Verbatim}
\letdif{\Delta}{Delta}
\letdif{\nabla}{nabla}
\end{Verbatim}
哪一行更合理一些?答案是第二行。

有时,大写的“$\Delta$”会被用作拉普拉斯算符(与 $\nabla^2$ 意义相同);
另一些时候,大写的“$\Delta$”会被当作变量或函数。所以对 $\Delta$ 作为
拉普拉斯算符和变量或函数的情况分别进行定义是更好的做法。我们建议将 |$\Delta$| 
作为 $\Delta$ 的原始定义进行保留,对表示拉普拉斯算符的 $\Delta$ 另加定义。
从而我们这样修改上面的第一行:
\begin{Verbatim}
\letdif{\laplacian}{Delta}
\end{Verbatim}
如果你比较擅长使用 \pkg{xparse} 宏包的接口,你也可以采用下面的方法:
\begin{Verbatim}
\letdif{\nabla}{nabla}
\DeclareDocumentCommand{ \laplacian }{ s }{
  \IfBooleanTF { #1 } { \mathdif{\Delta} } { \nabla^2 }
}
\end{Verbatim}
这样,|\laplacian| 会得到 $\nabla^2$,|\laplacian*| 会得到 $\Delta$。

\paragraph{处理正负号与微分算符之间的间距}
输入 |$-\d x$| 会得到 $-\d x$。如果你不希望在正负号与微分算符之间保留
一定的间距,可以输入 |$-{\d x}$|,这样就会得到 $-{\d x}$。
不过话说回来,$-\d x$ 的效果也并非不可接受。

\end{document}