# Degree Symbol in Latex

I want to be able to simply enter the degree symbol as ° in my source code. The German keyboard has a key that makes the source more readable. I’m using  pdfLaTeX    from TeXLive 2012, and this minimal reproduction example:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\begin{document}
Degree symbol in plain text works: 90° is a right angle.
Degree in math won’t work: $\cos(90°) = 0$.
\end{document}

Compile this file and I get a message

### Missing character: There is no in font cmr10!

Where there actually means that a single byte cannot form a valid UTF-8 sequence, so it cannot be printed correctly on my console.

I have a rough idea, all of them come from, but I don’t know anything about how to solve this problem. I want to make \textdegree symbols that can also work in math mode, or let the engine replace some different commands to replace my unicode code point. Ideally, the command will choose the correct form based on whether the current mode is a math mode, I do n’t know how to check (yet). For the final result, it would be nice if the symbols look the same in both text and math mode OK, so I might look for a solution that will switch to text mode to output the symbol.

But maybe there is an easier way to do it all. Maybe there is even a package. Searching through previous posts, I found that there is a package unicode-math , but this does not work for pdfLaTeX, and the switching engine does not seem to be most of my applications Reasonable requirements of the program.

## Latest recovery

1.The following code should work:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{gensymb}
\begin{document}
Degree symbol in plain text works: 90° is a right angle.
Degree in math now work: $\cos(90\degree) = 0$.
\end{document}

2. That’s why you have the siunitx package:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{siunitx}
\begin{document}
Degree symbol in plain text works: 90\si{\degree} (or \SI{90}{\degree}) is a right angle.
Degree in math would work: $\cos(90\si{\degree}) = 0$.
\end{document}
As cgnieder said, \ang it can also be used for this purpose:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{siunitx}
\begin{document}
Degree symbol in plain text works: \ang{90} is a right angle.
Degree in math would work: $\cos(\ang{90}) = 0$.
\end{document}

3. I used ^{\circ} to get the degree notation in math mode. It works every time. I encountered compatibility issues with some other code / package combinations.

4. If you do not need to textcomp pack, remove it and change the utf8 inputencselection to utf8x be useful to you, just for me.

\documentclass{article}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
%\usepackage{textcomp}
\begin{document}
Degree symbol in plain text works: 90° is a right angle.
Degree in math won’t work: $\cos(90°) = 0$.
\end{document}

5. I ended up using the gensymb answer from Papiro to get the \degree command, combining it with a line to tie it to ° a symbol inspired by comments to that answer:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage{gensymb}
\DeclareUnicodeCharacter{00B0}{\degree}
\begin{document}
Degree symbol in plain text still works: 90° is a right angle.
Degree in math now works as well: $\cos(90°) = 0$.
\end{document}