7

I am wondering what is the best practice for putting space between functions that are multiplied.

Here is a specific problem I have. I want to render \cos{x} u(x), which is meant to represent the product of two functions \cos{x} and u(x). However, direct rendering of this expression produces a result without enough space between x and u(x) and looks like \cos{x u(x)}:

enter image description here

In order to avoid this problem, I actually have been surrounding the function name u with \mathop to write \cos{x} \mathop{u}(x). This puts a proper space in front of u(x):

enter image description here

However, I just learned that surrounding a single letter with \mathop shifts the baseline, as discussed here. (You can see that u is shifted upward in the above rendering.) Using \operatorname instead of \mathop avoids this issue, but it uses an upright rather than italicized font for a single-letter function name.

Obviously, the easiest solution would be to put a space explicitly by \cos{x}\,u(x), but I don't want to disturb TeX's automatic spacing scheme as argued convincingly here. Is there a better way to inform TeX that there should be a space between two functions multiplied?

  • 1
    \mathop{{}u} would do what \operatorname does but without the font change – David Carlisle Feb 16 '22 at 17:18
  • 5
    IMHO I would use parenthesis around x in this case.... Or write u(x)\cos x. But I understand it's a matter of personal preferences. – Rmano Feb 16 '22 at 17:22
  • Why, why, mathematicians like to write a function as f(x), but write the trigonometric functions as cos x? I would use a \cdot. – yannisl Feb 16 '22 at 17:57
  • @YiannisLazarides, I think omitting parentheses when obvious increases readability by avoiding nested parentheses. For example (cos x - sin x) / (cos x + sin x) is easier to understand than (cos(x) - sin(x)) / (cos(x) + sin(x)) to me. – dashmile Feb 16 '22 at 18:20
  • @dashmile then why did you write u(x). I agree is more clear if you only use trigonometry, but once you start using your own functions, you lose this clarity. – yannisl Feb 16 '22 at 18:27
  • 1
    If we do not add parentheses or some kind of class changing like \mathop, how should LaTeX know if you mean cos(xu(x)) or cos(x)u(x)? I think @Rmano gives you a good suggestion. – mickep Feb 16 '22 at 18:48
  • @mickep, that's why I used \cos{x} rather than \cos x. Then it should be clear that only x is the argument of \cos. – dashmile Feb 16 '22 at 19:01
  • @YiannisLazarides, you are asking why I don't use u x for u(x) like cos x. When the function name is single-letter like u, it is not clear whether it is a function or variable, so we need parentheses, I guess. When the function name is multiple-letter like cos, it is clearer that it is a function rather than a variable, especially if it is written with upright font rather than variable's italicized font. – dashmile Feb 16 '22 at 19:09
  • @dashmile yes, see my post and choose! – yannisl Feb 16 '22 at 19:23
  • @dashmile You are mentioned TeX automatic spacing scheme, no LaTeX spacing scheme. LaTeX macro does nothing with spaces in math formulae. – wipet Feb 16 '22 at 19:36
  • @wipet, thanks for pointing that out. I updated the OP accordingly. – dashmile Feb 16 '22 at 21:45
  • 3
    Thin space or not, readers will be puzzled about the meaning of cos x u(x). If you write u(x) cos x nobody would misunderstand. If you insist in cos x u(x), just use \, which is the command of choice for such cases where you do want to override the automatic spacing. – egreg Feb 16 '22 at 22:03
  • As @egreg points out, inserting \, here is the preferable method, and I believe that you can find an example in the TeXbook recommending that. In fact, there's a list of examples on p.169 regarding explicit input spaces. – barbara beeton Feb 17 '22 at 02:35

3 Answers3

5

TeX primitive command \mathop does vertically centering of is argument, if this argument consists only from single object. That is the reason why \mathop{u} centers the u at math axis. If the argument of \mathop has more than single object then the argument is at baseline.

You can define

\def\op#1{\mathop{{}#1}}

and use

\cos x \op u(x)
wipet
  • 74,238
4

With this code

\[\cos x \,u(x)\] 

you dont have problems. The rendering is:

enter image description here

2

For absolute clarity, consistency and beauty use eq(1)

\begin{gather}
\begin{align}
\cos{(x)}\cdot \operatorname{u}(x)\\
\cos x \operatorname{fn}x
\end{align}
\end{gather}

enter image description here

yannisl
  • 117,160