Written and maintained by CASRAI Editorial Board
Published · Last updated
On this page
To write cosine in LaTeX, type \cos in math mode, for example $\cos \theta$ or \[ \cos(\theta + \phi) \]. The command prints the function name “cos” in upright (roman) type with the spacing LaTeX uses for operator names. It is part of standard LaTeX, so no package is needed. A package (amsmath) is needed only if you want to define operators of your own.
What \cos is used for in research
Any paper, thesis or report that contains trigonometry, signal processing, Fourier series, physics or geometry will use cosine somewhere in a displayed or inline equation. The unofficial LaTeX2e reference manual (section “Math functions”, June 2026 edition) describes the family of commands that includes \cos as ones that “produce roman function names in math mode with proper spacing”. Two reasons matter for research writing:
- Typography. The Overleaf learning centre notes that characters in math mode are usually shown in italics, but function names require different formatting.
\cosprints the name in upright text, which is what journals expect for named functions. - Meaning. Typing
cos xwithout the backslash does not name a function at all. The Trinity College Dublin LaTeX primer explains that LaTeX then treats it as a product of separate quantities (italic c, o, s and x). The backslash command is what tells LaTeX that “cos” is one function name.
The same family covers the inverse and hyperbolic forms and the other trigonometric functions; the data table below the FAQ lists the commands that the reference manual documents. If you are writing about other named operators, see our guides on argmax in LaTeX (an operator defined with \DeclareMathOperator) and inner products in LaTeX.
How to install or access it
\cos is built into LaTeX itself. If your document compiles at all, the command is available; you do not load a package for it. You compile it in whichever LaTeX environment you already use: a local TeX distribution on your computer, or an online editor such as Overleaf, which hosts the LaTeX learning pages cited in this guide.
The amsmath package is a separate matter. The Overleaf operators page states that \DeclareMathOperator requires \usepackage{amsmath} in the preamble. The package is distributed through CTAN (the Comprehensive TeX Archive Network), whose package page for amsmath showed version 2.17z dated 2025-07-09 under the LaTeX Project Public License 1.3c when checked on 2026-11-12. Its user guide is linked from that page as amsldoc. Use a distribution’s own package manager or an online editor that already bundles it rather than downloading files from third-party mirrors.
Step-by-step: typing cosine in an equation
- Enter math mode. For an inline formula use
$ ... $. For a displayed equation use\[ ... \]. Commands such as\cosare math-mode commands. - Type the command with its backslash:
$\cos x$. The argument follows after a space, as in\cos \theta. - Use parentheses when the argument is an expression. The Trinity College Dublin primer’s example is
\[ \cos(\theta + \phi) = \cos \theta \cos \phi - \sin \theta \sin \phi \], which prints the angle-addition identity with every function name upright. - Add amsmath if you also want custom operators. Put
\usepackage{amsmath}in the preamble. - Compile and check the PDF for upright function names.
A minimal document that uses both a built-in and a user-defined operator, written from the syntax the Overleaf operators page and the reference manual document, looks like this:
\documentclass{article}\usepackage{amsmath}\DeclareMathOperator{\cosec}{cosec}\begin{document}\[ \sin(a + b) = \sin a \cos b + \cos a \sin b \]\[ \cosec A \]\end{document}
The first line of math is the example given on the Overleaf operators page. \cosec is not in the standard list of built-in names (see below), so it is declared in the preamble.
Which approach should you use?
Four routes produce an upright function name. The table is a decision aid built from the reference manual, the Trinity College Dublin primer and the Overleaf operators page.
| Situation | Use | What the sources say |
|---|---|---|
| The function has a built-in command (cos, sin, arccos, cosh, and so on) | \cos |
Built-in commands produce roman function names in math mode with proper spacing (reference manual). |
| A function name has no built-in command and you use it once or twice | \mathrm{cosec} A |
The Trinity College Dublin primer gives \mathrm{cosec} A for names without a built-in command. |
| A custom function name you will reuse | \DeclareMathOperator{\cosec}{cosec} with amsmath |
Reference manual and Overleaf both document \DeclareMathOperator, which requires amsmath. |
| A custom operator whose subscripts should sit below it, like a limit | \DeclareMathOperator*{\op}{op} |
The starred form puts sub- and superscripts above and below, as with \lim, \sup and \max (reference manual). |
Output and how to read it
In the compiled PDF, \cos appears as upright “cos” followed by the argument. Compare it with the unescaped version: $cos x$ typesets the four letters in math italics, as individual variables, and LaTeX may space them like a product. If you see slanted letters where a function name should be, the backslash is missing. The reference manual’s wording, “proper spacing”, refers to the operator spacing LaTeX inserts around these names; you do not add thin spaces by hand.
Which related commands produce which printed names is listed in the data table below. The same pattern holds across the family: \arccos prints the inverse cosine, \cosh the hyperbolic cosine, and so on, all upright.
Other named operators in the same list
Cosine is one entry in a longer list. The reference manual documents the following in the same section, each printed as an upright name: \exp (exponential), \ln (natural logarithm), \log (logarithm), \lg (base 2 logarithm), \det (determinant), \dim (dimension), \gcd (greatest common divisor), \lim (limit), \max (maximum), \min (minimum) and \Pr (probability). Two entries work differently: \bmod is a binary modulo operator, used as in \( 5\bmod 3=2 \), and \pmod gives a parenthesized modulus, used as in \( 5\equiv 2\pmod 3 \). Because they share one mechanism, a document that uses \cos correctly already follows the right pattern for all of them: backslash, then the name, in math mode.
When a name you need is absent from the list, the table above tells you which of the two routes to take. A symbol that is not a function name at all, such as a set relation, belongs to a different part of the manual; see superset symbols in LaTeX for an example.
Troubleshooting
The function name prints in italics
The backslash is missing, so LaTeX is typesetting variables, not a function name. Change cos x to \cos x.
“Undefined control sequence” for a name like \cosec
The command is not in the standard list. The Trinity College Dublin primer lists the standard control sequences as: arccos, arcsin, arctan, arg, cos, cosh, cot, coth, csc, deg, det, dim, exp, gcd, hom, inf, ker, lg, lim, liminf, limsup, ln, log, max, min, Pr, sec, sin, sinh, sup, tan, tanh. Cosecant appears in that list as \csc; the form “cosec” is not there. Use \csc, or declare your own with \DeclareMathOperator.
\DeclareMathOperator is undefined
The preamble lacks \usepackage{amsmath}. Add it before the \DeclareMathOperator line.
You want the operator to take limits-style subscripts
Declare it with the starred form, \DeclareMathOperator*, so subscripts are set below the name in display math, the way \lim and \max behave.
Free alternatives and where to compile
The table lists ways to compile a document that contains \cos. It does not compare prices; check each provider’s own pages for plan details.
| Option | What it is | Note on amsmath and \cos |
|---|---|---|
| Local TeX distribution plus a text editor | LaTeX installed on your own computer, with packages obtained from CTAN | \cos is built in; amsmath is available from CTAN (LPPL 1.3c). |
| Overleaf | Browser-based LaTeX editor with a public learning centre | Its Operators page documents \cos and \DeclareMathOperator with amsmath. |
| Papeeria | Browser-based LaTeX and Markdown editor with a free tier, checked 2026-08-29 | Projects can be downloaded as a ZIP and compiled locally. |
If you collaborate on a manuscript, see collaborative writing in LaTeX and Overleaf. For reference lists in the same document, see LaTeX bibliography styles explained.
FAQ
How do I write cosine in LaTeX?
Use \cos in math mode, such as $\cos \theta$. It prints an upright “cos” with operator spacing and needs no package.
Why is cos x without a backslash wrong?
Without the backslash LaTeX does not recognise a function name. It typesets c, o, s and x as separate italic quantities, as the Trinity College Dublin primer explains.
How do I write inverse cosine or hyperbolic cosine?
Use \arccos for inverse cosine and \cosh for hyperbolic cosine. Both are in the reference manual’s list of math function commands.
Do I need amsmath for \cos?
No. You need amsmath only for \DeclareMathOperator, which defines operators that have no built-in command.
How do I typeset a function that LaTeX has no command for?
Use \mathrm{name} for a one-off, or \DeclareMathOperator{\name}{name} (with amsmath) when you will reuse it. Related examples are our guides on argmax in LaTeX and big O notation in LaTeX.
Sources
- LaTeX2e: An unofficial reference manual, “Math functions” (June 2026 edition), https://latexref.xyz/Math-functions.html, read 2026-11-12.
- Trinity College Dublin, LaTeX Primer, “Standard Functions”, https://www.maths.tcd.ie/~dwilkins/LaTeXPrimer/StdFuncts.html, read 2026-11-12.
- Overleaf learning centre, “Operators”, https://www.overleaf.com/learn/latex/Operators, read 2026-11-12.
- CTAN, amsmath package page, https://ctan.org/pkg/amsmath, read 2026-11-12.
- Papeeria, https://papeeria.com, read 2026-08-29.
Data: LaTeX math function commands for cosine and related trigonometric functions
Commands documented in the unofficial LaTeX2e reference manual section on math functions, with the function name each prints and a grouping by function family compiled for this guide.
| LaTeX command | Function | Family |
|---|---|---|
| \cos | Cosine | Trigonometric |
| \arccos | Inverse cosine | Inverse trigonometric |
| \cosh | Hyperbolic cosine | Hyperbolic |
| \sin | Sine | Trigonometric |
| \arcsin | Inverse sine | Inverse trigonometric |
| \sinh | Hyperbolic sine | Hyperbolic |
| \tan | Tangent | Trigonometric |
| \arctan | Inverse tangent | Inverse trigonometric |
| \tanh | Hyperbolic tangent | Hyperbolic |
| \sec | Secant | Trigonometric |
| \csc | Cosecant | Trigonometric |
| \cot | Cotangent | Trigonometric |
| \coth | Hyperbolic cotangent | Hyperbolic |
Sources
- LaTeX2e: An unofficial reference manual, Math functions (accessed 2026-11-12)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







