[Tex/LaTex] Writing functions and LaTeX

math-mode

How do I write a function in LaTeX? I tried writing f(…), but it just appears as a normal f. Do I have to add a math package or is it already in LaTeX

Best Answer

Anything that is maths should go in math mode. There are a number of ways of entering math mode, and actually different types. The simplest is

  • $ ... $

Thus, you will write $f(...)$

This is for in-line maths, maths that should go in the text, e.g.:

The function $f(x) = x^{2}$ is an interesting function, because ...

You may also use:

  • \( ... \)

Which does exactly the same thing:

The function \(f(x) = x^{2}\) is an interesting function, because ...

For displayed equations, you should use:

  • \[ ... \]

This will display your equation. By default it will be on a new line, centred, and there will be a small skip between the lines of text preceding and succeeding the equation. In addition, certain symbols - such as the summation and integral signs - will be set larger by default. Fractions will also be larger by default and limits, etc. will, by default, be placed above and below (except with integrals). This is suited to large displayed equations. In inline math mode we have smaller symbols, limits are set like sub- and superscripts and fractions appear smaller. This is so that the mathematics is integrated smoothly into the text and does not cause ugly line heights and excessive white space.

So you could have:

And from this it follows that
\[f(x) = x^{2}\]

There are also a number of environments, such as equation and flalign* which are maths environments and put you, by default, into math mode, e.g.:

The equation we shall begin with is:
\begin{equation}
  f(x) = x^{2}
\end{equation}

These environments usually display your equations.

P.S.: You should definitely load the amsmath package at the least.