
LaTeX には、他の三角関数のように美しい結果を印刷できる arctan2 / atan2 関数がありますか\sin
\cos
?
答え1
amsmath
は、や、\DeclareMathOperator{\foo}{foo}
に似たタイプセット、つまり直立フォントと正しい間隔の新しい演算子名を定義するために提供されます。\sin
\cos
\ln
\atantwo
これはと一緒に使用することもできます(2
ただし、 はマクロ名の一部として許可されていないため、 となります) \atantwo
。
\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\atantwo}{atan2}
\DeclareMathOperator{\arctantwo}{arctan2}
\begin{document}
\[
\atantwo ( y, x)
\]
\[
\arctantwo ( y, x)
\]
\[
\sin (x y)
\]
\end{document}
注:atan2(y,x)
関数 は極座標での角度を決定し、関数 と関連がありますが、関数 とは異なりますatan(y/x)
。この 2 つは互換性がありません。atan
関数 の出力範囲は です(-pi/2,pi/2)
が、atan2
関数 の出力範囲は です(-pi,pi]
。 の場合はx>0
ですatan2(y,x)=atan(y/x)
。 の場合x<0
は ですatan2(y,x)=atan(y/x) +/- pi
。またx=0
の場合atan(y/x)
は が未定義ですが、またはの場合は です。 のこの定義(または同等の) は、数学でも、C、FORTRAN、matlab などの一般的なプログラミング言語でも同じです。atan2(y,x)=pi/2
y>0
-pi/2
y<0
atan2
arctan2
答え2
必要に応じて、もう少し賢くして\atan2
、\arctan2
\long\def\gobbleone#1{}
\protected\def\atan{\futurelet\tmptoken\doatan}
\protected\def\doatan{\operatorname{atan\ifx\tmptoken22\fi}%
\ifx\tmptoken2\expandafter\gobbleone\fi}
\protected\def\arctan{\futurelet\tmptoken\doarctan}
\protected\def\doarctan{\operatorname{arc\,tan\ifx\tmptoken22\fi}%
\ifx\tmptoken2\expandafter\gobbleone\fi}
$\atan2(y, x) \arctan2(y, x) \sin(x, y)$