# Defining \tg so it behaves exactly like \sin and \cos?

In my country, instead of tan, we use tg (this is just one of them). I want to be able to type

\tg{x}

and possibly

\tgx

So that Latex recognizes them. I tried defining them like this:

\DeclareMathOperator{\tg}{\text{tg}}

That seemed to work until I used in a block of bold text and it was bold as well, while \sin and \cos where not bold. So how can I define them correctly?

Edit:

I use this new operator in math blocks, like

The use of $\tg{x}$

Or even in \subsection (which has a bold formatting in my document):

\subsection{The use od $\tg{x}$}
-
don't use \text (it will use the right \mathrm font automatically) – David Carlisle Jan 28 at 20:39
@DavidCarlisle then what? – Victor Jan 28 at 20:40
then it'll work as you intended, just like \sin so \DeclareMathOperator{\tg}{tg} – David Carlisle Jan 28 at 20:42
@jfbu I suppose you've gone off on a tangent? :) – Arun Debray Jan 28 at 21:58
According to Cajori, the abbreviation “tan” was used by Finck in 1583; Euler used “tang”, but sometimes “tg”. In the 18th century, “tang” and “tan” were probably the most used abbreviations. A table in the book by Cajori seems to show that “tg” is more German than French; for instance, Legendre and Cauchy used “tang”. – egreg Jan 28 at 22:07

All you need to do is write \DeclareMathOperator{\tg}{tg}; this defines the command \tg to use the normal math font. Then, you can define \tgx to just be \tg x:

\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\tg}{tg}
\newcommand{\tgx}{\tg x}
\begin{document}
In a paragraph of normal text, $\sin x$, $\cos x$, $\tg x$, and $\tgx$.

\textbf{
In a paragraph of bold text, $\sin x$, $\cos x$, $\tg x$, and $\tgx$.
}
\end{document}

-

If you are typing in Spanish, load \usepackage[spanish]{babel} and you will have it available.

-
It's Romanian actually :) – Victor Jan 28 at 20:42
Argh, I didn't know it was used elsewhere. – Manuel Jan 28 at 20:43
it used to be in use in France, but sadly we are not as robust as the Romanians ! – jfbu Jan 28 at 21:30

When you declare a math operator, you should do so without specifying it as being formatted as \text. There is no mention of this requirement in the amsmath user guide (section 5.1 Defining new operator names):

To define a math function \xxx to work like \sin, you write

\DeclareMathOperator{\xxx}{xxx}

whereupon ensuing uses of \xxx will produce xxx in the proper font and automatically add proper spacing on either side when necessary, ...

\documentclass{article}

\usepackage{amsmath}

\DeclareMathOperator{\tg}{tg}

\begin{document}

$\sin^2\theta + \cos^2\theta = 1$

$\tg^2\theta + \cos^2\theta = 1$

{\bfseries $\tg^2\theta + \cos^2\theta = 1$}

\end{document}
-