# How can I use unicode symbols in TeX source?

I've tried using \usepackage[utf8]{inputenc}, but that throws an error:

Package inputenc Error: Unicode char µ (U+B5)
(inputenc)                not set up for use with LaTeX.


Whatever I do, unicode character in the source either do not appear, or do not appear and throw an error. I would like to use both Russian and mathematical symbols in my source code.

How can I do this?

• I think the least troublesome solution would be using a unicode egine like XeTeX or LuaTeX with an appropriate font. – Johannes_B Oct 1 '17 at 14:33
• are you planning onto using µ in math mode too? – user4686 Oct 1 '17 at 15:50
• @jfbu: Yes. I find it easier to read the source when it looks somewhat like the output. – Zaz Oct 1 '17 at 16:05

Probably this will miss more complex scenarios, but from here:

%%
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\DeclareUnicodeCharacter{B5}{\ifmmode\mu\else\textmu\fi}
%
% use http://shapecatcher.com/ to find the char
% or https://w3c.github.io/xml-entities/unicode-names.html

\begin{document}

This is a textmode µ and this a math mode one: $µ_µ$.

\end{document}


If you do not want to define everything, you need to switch to a native unicode TeX engine, like for example xelatex. If you compilte with xelatex the following code:

%%
\documentclass{article}
\usepackage{fontspec}
\usepackage{unicode-math}
%
% use http://shapecatcher.com/ to find the char
% or https://w3c.github.io/xml-entities/unicode-names.html

\begin{document}

Is the character ẁ used in some language?

This is a textmode µ and this a math mode one: $𝜇_𝜇$.
(But be careful, math mu is a different unicode codepoint,
\texttt{1D707}.)

\end{document}


to obtain:

Where I am using the unicode-math package; I found the mathmode µ codepoint at shapcatcher.

• Isn't that textmode µ really ugly? – Rmano Oct 1 '17 at 16:39
• Is there any way to do this but without having to declare every symbol you want to use? – Zaz Oct 1 '17 at 17:08
• ...I edited the answer. – Rmano Oct 1 '17 at 17:35