[Tex/LaTex] Negative phantom

math-modespacing

I noticed that \cos is somewhat larger then \sin, and I thought of using something like \hphantom{\cos}\neghphantom{\sin} to add the difference after one of my expressions. However it turns out there is no such command. Anyone know of an alternative? Or perhaps a way of defining such a negative phantom myself?

*edit *
Additional information
I was trying to add the space difference at the end of the expression, so after the \alpha. Something like \sin \alpha ABC+additional spacing
Using Hendrik's example I could do something like \mathop{\rlap{$\sin\alpha ABC$}}\hphantom{$\cos\alpha ABC$} but then the line ABC needs to be present twice, so I am hoping for an alternative.

Best Answer

You can do with mathtools, but I wouldn't recommend it. This leaves a gap on the right of “sin”, but centering it in the available space would be even worse.

\documentclass{article}
\usepackage{mathtools}

\let\sin\relax % remove the previous definition of \sin
\DeclareMathOperator{\sin}{%
  \mathrlap{\operatorname{sin}}\hphantom{\cos}%
}

\begin{document}
$\sin\alpha$

$\cos\alpha$

$e^{\sin x}$

$e^{\cos x}$
\end{document}

enter image description here

A different solution, where you add the space after the \sin<expression> can be

\documentclass{article}
\usepackage{mathtools}

\newcommand{\csin}[1]{%
  \mathop{}\!\mathrlap{\sin#1}\hphantom{\cos#1}%
}

\begin{document}
$3\csin{\alpha}+\cos\beta$

$3\cos\alpha+\cos\beta$

$e^{\csin{x}+i\cos{x}}$

$e^{\cos x+i\cos x}$
\end{document}

Since we need to know what the argument to \csin is, braces delimiting it are necessary.

However, this has limitations because it's difficult to catch the type of the last object in the argument of \csin, so this might break with parenthesized expressions and hand corrections would be needed, for instance

\csin{(x+y)}\mathclose{}

enter image description here

Yet another proposal: a \sincorr space to be added by hand where necessary:

\documentclass{article}

\newcommand{\sincorr}{\mathpalette\dosincorr\relax}
\newcommand{\dosincorr}[2]{%
  \sbox0{$#1\cos$}\sbox2{$#1\sin$}%
  \kern\dimexpr\wd0-\wd2\relax}

\begin{document}
$3\sin\alpha\sincorr+\cos\beta$

$3\cos\alpha+\cos\beta$

$e^{\sin x\sincorr+i\cos x}$

$e^{\cos x+i\cos x}$

\end{document}

The output is identical as with the previous solution.

Related Question