我想定义一个打印两个相邻的 sqrt 符号的宏。(来自柯西分析书中的符号)。
我得到了一个接近的结果,但间距会根据前面是否有数字而变化。如果前面没有数字,则 sqrt (surd) 符号太近了。
平均能量损失
\documentclass[class=book]{book}
% Run with xelatex
%%% fonts
\usepackage{libertine}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
%%% mathfonts
\usepackage{unicode-math}
\setmathfont{texgyrepagella-math.otf}
\usepackage{microtype}
% "221A is the surd symbol in unicode. \surd is not working, it shows a p
\usepackage{mathtools}
\NewDocumentCommand\dsqrt{o m}{%
\IfNoValueTF{#1}{%
\,\mathrlap{\char"221A}\,\char"221A#2%
}%
{
\,\mathrlap{\raisebox{3pt}{$\scriptscriptstyle#1$}}\mathrlap{\char"221A}\,\char"221A#2%
}
}
\begin{document}
\begin{equation}\label{pre1}
\dsqrt{a} = \pm\sqrt{a}
\end{equation}
\begin{equation}\label{pre1}
2\dsqrt{a} = \pm2\sqrt{a}
\end{equation}
\begin{equation}\label{pre1}
\dsqrt[n]{a} = \pm\sqrt[n]{a}
\end{equation}
\begin{equation}\label{pre1}
2\dsqrt[n]{a} = \pm2\sqrt[n]{a}
\end{equation}
And here is another: inline $\dsqrt{y} =\pm \sqrt{y}$.
And here is another: inline $2\dsqrt{y} =\pm 2\sqrt{y}$.
And here is another: inline $\dsqrt[n]{y} =\pm \sqrt[n]{y}$.
And here is another: inline $2\dsqrt[n]{y} =\pm 2\sqrt[n]{y}$.
\end{document}
答案1
这是另一次尝试;不幸的是,Unicode 中似乎没有“surd”符号。
\documentclass{book}
% Run with xelatex
%%% fonts
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{amsfonts}
\usepackage{amssymb}
%%% mathfonts
\usepackage{unicode-math}
\setmainfont{TeX Gyre Pagella}
\setmathfont{texgyrepagella-math.otf}
\usepackage{microtype}
% "221A is the surd symbol in unicode. \surd is not working, it shows a p
\NewDocumentCommand\dsqrt{o m}{%
\mathop{%
\IfNoValueTF{#1}
{\doublesurd}
{\mathrlap{^{\scriptscriptstyle#1}}\doublesurd}%
}%
{}#2
}
\makeatletter
\newcommand{\doublesurd}{\mathpalette\double@surd\relax}
\newcommand{\double@surd}[2]{%
\ooalign{$\m@th#1\char"221A$\hidewidth\cr$\m@th#1\,\char"221A$\cr}%
}
\makeatother
\begin{document}
\begin{equation}
\dsqrt{a} = \pm\sqrt{a}
\end{equation}
\begin{equation}
2\dsqrt{a} = \pm2\sqrt{a}
\end{equation}
\begin{equation}
\dsqrt[n]{a} = \pm\sqrt[n]{a}
\end{equation}
\begin{equation}
2\dsqrt[n]{a} = \pm2\sqrt[n]{a}
\end{equation}
And here is another: inline $\dsqrt{y} =\pm \sqrt{y}$.
And here is another: inline $2\dsqrt{y} =\pm 2\sqrt{y}$.
And here is another: inline $\dsqrt[n]{y} =\pm \sqrt[n]{y}$.
And here is another: inline $2\dsqrt[n]{y} =\pm 2\sqrt[n]{y}$.
\end{document}
答案2
这是使用堆栈的版本。但是,它目前尚未设置为遵循较小的数学样式。
\documentclass[class=book]{book}
% Run with xelatex
%%% fonts
\usepackage{libertine}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{stackengine}
\stackMath
%%% mathfonts
\usepackage{unicode-math}
\setmathfont{texgyrepagella-math.otf}
\usepackage{microtype}
% "221A is the surd symbol in unicode. \surd is not working, it shows a p
\usepackage{mathtools}
\NewDocumentCommand\dsqrt{o m}{%
\IfNoValueTF{#1}{%
\,\stackengine{0pt}{\char"221A}{\,\char"221A#2}{O}{l}{F}{F}{L}%
}%
{
\,\raisebox{3pt}{$\scriptscriptstyle#1$}\mkern-13mu\stackengine{0pt}{\char"221A}{\,\char"221A#2}{O}{l}{F}{F}{L}%
}
}
\begin{document}
\begin{equation}\label{pre1}
\dsqrt{a} = \pm\sqrt{a}
\end{equation}
\begin{equation}\label{pre1}
2\dsqrt{a} = \pm2\sqrt{a}
\end{equation}
\begin{equation}\label{pre1}
\dsqrt[n]{a} = \pm\sqrt[n]{a}
\end{equation}
\begin{equation}\label{pre1}
2\dsqrt[n]{a} = \pm2\sqrt[n]{a}
\end{equation}
And here is another: inline $\dsqrt{y} =\pm \sqrt{y}$.
And here is another: inline $2\dsqrt{y} =\pm 2\sqrt{y}$.
And here is another: inline $\dsqrt[n]{y} =\pm \sqrt[n]{y}$.
And here is another: inline $2\dsqrt[n]{y} =\pm 2\sqrt[n]{y}$.
\end{document}
如果希望无理数与参数大小相匹配(就像 一样\sqrt
),那么应该用这个定义来替代:
\NewDocumentCommand\dsqrt{o m}{%
\IfNoValueTF{#1}{%
\,\stackengine{0pt}{\sqrt{\vphantom{#2}}}{\,\sqrt{#2}}{O}{l}{F}{F}{L}%
}%
{
\,\raisebox{3pt}{$\scriptscriptstyle#1$}\mkern-13mu\stackengine{0pt}{%
\sqrt{\vphantom{#2}}}{\,\sqrt{#2}}{O}{l}{F}{F}{L}%
}
}
x
注意与参数的区别y
。