4

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?

David Carlisle
  • 757,742
annmous74
  • 43
  • 3

2 Answers2

7

enter image description here

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

\documentclass{article}

\usepackage{unicode-math}

\begin{document}

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

\end{document}

David Carlisle
  • 757,742
2

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}

enter image description here

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.

enter image description here

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

egreg
  • 1,121,712