冪根の数字付きの\sqrtの再定義

Re: 冪根の数字付きの\sqrtの再定義

by 前田 一貴 -
Number of replies: 2
蛇足っぽいですが,\sqrt[]{g} だと羃根の指数の位置調整で入る負の \mkern が悪さをするみたいです.

本田さんのと同じですが,xparse を使うとすっきりしますね.

\usepackage{xparse}
\DeclareDocumentCommand{\newsqrt}{ o m }{%
  \IfValueTF{#1}{\oldsqrt[#1]}{\oldsqrt}{\smash[b]{\mathstrut #2}}}
\renewcommand{\sqrt}{\@ifstar{\newsqrt}{\oldsqrt}}
In reply to 前田 一貴

Re: 冪根の数字付きの\sqrtの再定義

by ヤバルゴ mdl.2 -
本田 さま,前田 さま,回答ありがとうございます.

お二方の方法で,羃根の指数がないときの \sqrt および \sqrt* の横の出力位置が揃いました.

TeX言語を使った方法や比較的新しいパッケージを使った方法があり,興味深いです.



%-------------以下,実装例
% TeX言語による操作は怖いので,xparse を利用しました

%% ドキュメントクラス
\documentclass[uplatex,dvipdfmx,a4paper,papersize,magstyle=real]{bxjsarticle}
\pagestyle{empty}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{mathtools} % include amsmath

%--冪根の数字を修正する(大きくする)--
%  https://okumuralab.org/tex/mod/forum/discuss.php?d=1857
\usepackage{etoolbox}
\makeatletter
\patchcmd{\plainroot@}{\scriptscriptstyle}{\scriptstyle}{}{}
\makeatother


%--高さの統一した根号 \sqrt* 命令を追加する--
%  https://okumuralab.org/tex/mod/forum/discuss.php?d=1864
\usepackage{letltxmacro}
\usepackage{xparse}
\makeatletter
\LetLtxMacro{\oldsqrt}{\sqrt}
\DeclareDocumentCommand{\newsqrt}{o m}{%
  \IfValueTF{#1}{\oldsqrt[#1]}{\oldsqrt}{\smash[b]{\mathstrut #2}}%
}
\renewcommand{\sqrt}{%
  \@ifstar{\newsqrt}{\oldsqrt}%
}
\makeatother

\begin{document}

\begin{align*}
s&=\sqrt{g}+\sqrt{h} \\
s^\ast &=\sqrt*{g}+\sqrt*{h} \\
s[]&=\sqrt[2]{g}+\sqrt[2]{h} \\
s^\ast[] &=\sqrt*[2]{g}+\sqrt*[2]{h}
\end{align*}

\end{document}
Attachment equation.jpg
In reply to 前田 一貴

Re: 冪根の数字付きの\sqrtの再定義

by 本田 知亮 -
>指数の位置調整で入る負の \mkern

あ,そうですね.カーンの類ですか
てっきり\newcommandかと
#\long付きがデフォルトなのがいやなので
#まず最初に疑ってしまう(^-^;;

昔のptexでも
和文+アクセント記号付きアルファベットだと
カーンの影響でグルーが入らないケースがありました.