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}
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{}
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.
Once having made clear that
\mspace
can only be used in math mode (and requires amsmath
),
\mspace
only accepts a length expressed in mu
units (but the plus
and minus
components also accept fil[ll]
units) or in terms of a mu
based parameter (\thinmuskip
, \medmuskip
and \thickmuskip
),
\hspace
doesn't accept mu
units,
we can describe the differences.
Both commands insert space that will not interfere with the automatic spacing between atoms. However,
- the value of the
mu
unit for \mspace
depend on the current math style;
- the value of the
em
or ex
unit for \hspace
depends on the text font current at the time the formula began.
In particular, given that 18mu corresponds to the value of 1em in the symbol font (math group 2), the following two formulas will give quite different result
$\scriptscriptstyle a\mspace{18mu}b$
$\scriptscriptstyle a\hspace{1em}b$
This is because the former uses the em in \scriptscriptfont2
(default for 10pt size is cmsy5
) whereas the latter uses the em in the standard text font (default cmr10
).
Best Answer
Spaces (glues and kerns) disappear after line breaks by rule; by the same rule, line breaks can happen only at the "left edge" of a space. Moreover, if one says
\hspace{1cm}\hspace{1cm}
, the first\hspace
is a feasible break point, but not the second one.This is how TeX attains alignment to the left margin for normal and ragged right paragraphs (ragged left uses a different feature).
More precisely, a glue (
\hspace
) can be chosen as break point only if it is preceded by a non discardable item (most commonly a character or a rule). Among discardable items are penalties.In some cases one wants to have spaces that don't disappear at line breaks: for instance blanks that should filled by hand in an exercise. Thus LaTeX provides the
\hspace*
variant.When
\hspace*{1cm}
is called, LaTeX uses the internal command\@hspacer
, which does\vrule width 0pt
places an invisible object that takes up no space;\nobreak
sets a point where line breaking is impossible, by issuing a very large penalty;\hskip 1cm
cannot be used as a break point, because it is preceded by a discardable item (the penalty);\hskip 0pt plus 0pt minus 0pt
is inserted to avoid possible problems due to the peculiar syntax of the primitive\hskip
; it won't be a feasible break point, because it's preceded by a discardable item;Thus
\hspace*{1cm}
forms, so to speak, an indivisible unit that will never be taken as a break point, nor will disappear at line breaks.A consequence of this rules is that a space after
\hskip*{1cm}
cannot be used as break point.Suppose we want to define a
\blank
macro for leaving space to be later filled in by hand:The result will be
(where the rules represent the
\hspace*{...}
commands; they won't be printed by this command, I used them just to show the effect). You can see that the space after\blank{...}
is not used as break point.With a different definition, the blanks can appear at the end of the line:
will result in
Of course the typesetting here is suboptimal, but the point is to show how the thing works.
The
\linebreak[0]
command just inserts a feasible break point, without stating any particular preference for it.For the interested readers, the "rule" effect for showing
\hspace*
has been obtained with the following trick: