TransWikia.com

How to have the arctan2 / atan2 function in LaTeX?

TeX - LaTeX Asked by Covich on April 19, 2021

Is there an arctan2 / atan2 function in LaTeX, which can print an aesthetic result like the other trigonometric functions sin cos… ?

2 Answers

amsmath provides DeclareMathOperator{foo}{foo} to define new operator names that are typeset similar to sin and cos, ln, i.e. upright font and correct spacings.

This can be used with atantwo as well (the 2 isn't allowed as part of the macro name, however, therefor atantwo.

documentclass{article}

usepackage{amsmath}

DeclareMathOperator{atantwo}{atan2}

DeclareMathOperator{arctantwo}{arctan2}


begin{document}

[
atantwo ( y, x)
]

[
arctantwo ( y, x)
]



[
sin (x y)
]



end{document}

enter image description here

Note: The atan2(y,x) function determines the angle in polar coordinates and is related to but different than the function atan(y/x). The two are not interchangeable. The atan function has output range (-pi/2,pi/2), whereas atan2 has an output range of (-pi,pi]. If x>0, then atan2(y,x)=atan(y/x). If x<0, then atan2(y,x)=atan(y/x) +/- pi. And if x=0 then atan(y/x) is undefined while atan2(y,x)=pi/2 for y>0 or -pi/2 for y<0. This definition of atan2 (or equivalently arctan2) is the same both for mathematics and for common programming languages including C, FORTRAN, and matlab.

Correct answer by user31729 on April 19, 2021

If you want you can let them be a little bit more intelligent to enable atan2 and arctan2

longdefgobbleone#1{}
protecteddefatan{futurelettmptokendoatan}
protecteddefdoatan{operatorname{atanifxtmptoken22fi}%
  ifxtmptoken2expandaftergobbleonefi}
protecteddefarctan{futurelettmptokendoarctan}
protecteddefdoarctan{operatorname{arc,tanifxtmptoken22fi}%
  ifxtmptoken2expandaftergobbleonefi}

$atan2(y, x) arctan2(y, x) sin(x, y)$

Answered by Manuel on April 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP