19

Although I use LaTeX a lot, I still have a lot to learn about it, and I still have many questions which remain unanswered. One in particular bothers me: when and why must I use curly brackets when giving arguments to a function like \cos or \sin?

I tend to use curly brackets everywhere and write \cos{x}, because that's how it was written on documents I used to teach myself. However, I see a lot of LaTeX documents where the syntax is simply \cos x.

Does it have any importance? Maybe when writing a lot of these functions at a time, like r\sin \theta d\phi?

Thanks for your help!

2
  • 4
    I think the braces are extraneous because, from a LaTeX point of view, math operators do not take arguments. I should temper my statement by saying the braces will insure that the operator sees an adjacent math atom, whereas if the first token following the operator were something other than a math atom, spacing could be different. For example, $\cos = 3$ produces different spacing than $\cos {= 3}$. But that is not an issue unless you are using very strange notation. Commented Mar 14, 2018 at 18:59
  • 3
    @StevenB.Segletes or even standard notations the spacing in $\cos(\phi+\theta)$ is adversely affected if you do $\cos{(\phi+\theta)}$ Commented Mar 14, 2018 at 19:31

2 Answers 2

26

Note that the braces are not just not required, they should not be used as \cos does not take an argument the braces form a group and force the term to lose any special math class that it would otherwise have.

\cos is a "\mathop" operator and ( is a "\mathopen" but a term surrounded by {..} is always a "\mathord". TeX uses different space between a \mathop and a \mathopen than between a \mathop an a \mathord (because log(x) does not need any space but log x does).

Compare

\documentclass{article}

\begin{document}

$\cos(\phi+\theta)$

$\cos{(\phi+\theta)}$

\end{document}

which produces

enter image description here

4
  • 1
    I'd also add \cos{\arccos{x}} that shows the opposite (wrong) spacing.
    – egreg
    Commented Mar 14, 2018 at 20:48
  • I don't understand why \cos{(\phi+\theta)} and \cos{\arccos{x}} would be considered incorrect. They look fine to me. I understand that, usually, if I have a function called f, then I would want to say f(x) and have no space, but I think when the function name is multiple characters and typeset differently, the space actually adds readability.
    – Will R
    Commented Mar 15, 2018 at 15:41
  • 2
    @WillR well I think it looks wrong but actually the main point is that the braces are not "superfluous" or "optional" in the way that x^2 is the same as x^{2} if you add them they change the output. Commented Mar 15, 2018 at 17:29
  • Time to change my habits then! Thank you very much for your answer. :-)
    – Biblot
    Commented Mar 15, 2018 at 20:36
20

operators like \cos or \sin don't require curly braces, because they don't take arguments; they're simply substitutions.

any command that takes an argument is best fed that argument in braces. even if the argument is a single, unexpandable token (such as the letter "x"), where braces are optional, it's not improper to provide the braces. in fact, it's probably a good idea to get in the habit of using them, since what may look like a single token (it will always begin with a backslash) may expand to more than one token and cause problems.

(the final example in the question would be improved by the addition of a thin space: r\sin \theta \, d\phi.)

1
  • 1
    Thanks a lot! I finally get it, I didn't know the difference between substitutions and actual commands that take arguments. I'll look that up!
    – Biblot
    Commented Mar 14, 2018 at 19:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .