# Greek directly in math mode XeLaTeX instead of PdfLatex

This piece of code

\documentclass{article}
\usepackage{alphabeta}
\usepackage{amsmath}

\begin{document}

$α+β+γ=\alpha+\beta+\gamma$

\end{document}


works perfectly in MiKTeX-TeXworks provided that I use the option pdfLatex.

However greek letters are ignored by when I use the XeLaTeX option.

I want to use XeLaTeX and yet be able to write greek letters directly in math mode.

Is this possible?

If yes how should I modify the above piece of code?

• Please extend your example to a full document (there is no documentclass) Jul 28 at 12:42
• use unicode-math not alphabeta and you will be able to use all Unicode math characters Jul 28 at 14:19
• Somewhat special case of Entering Unicode characters in LaTeX - TeX - LaTeX Stack Exchange, for cross-linking purposes. Jul 29 at 5:18

## 2 Answers

You can use unicode-math with xelatex and lualatex, it includes amsmath

\documentclass{article}

\usepackage{unicode-math}

\begin{document}

$α+β+γ=\alpha+\beta+\gamma$

\end{document}


It's not difficult to make alphabeta to do its job also for XeLaTeX or LuaLaTeX.

\documentclass{article}
\usepackage{iftex}
\usepackage{amsmath}

\iftutex
\newcommand\DeclareUnicodeCharacter[2]{%
\begingroup\lccode~="#1\lowercase{\endgroup\protected\def~}{#2}%
\catcode"#1=\active
}
\fi
\usepackage{alphabeta}

\begin{document}

$α+β+γ=\alpha+\beta+\gamma$

\end{document}


Explanation: the package redefines \alpha to be \TextOrMath{\textalpha}{\mathalpha}, where \mathalpha is the original \alpha. The same for all other Greek letters.

After that it does

\DeclareUnicodeCharacter{03B1}{\alpha}


in order to allow the user to type α to get an alpha in text or math mode. The code between \iftutex (which is true when using XeLaTeX or LuaLaTeX and false otherwise) makes the Greek letter α active and provides a definition for them, which is exactly \alpha as redefine by alphabeta as mentioned above.

Of course, in order to use the Greek letters in text mode, you need a font that supports them.

If you plan to only use XeLaTeX or LuaLaTeX, you can obviously omit \iftutex and \fi`.