How to Convert UTF-8 Greek Letters to LaTeX Symbols
At a glance
- 1. Check the context
Decide whether the Greek characters are part of a mathematical formula or ordinary text; LaTeX uses different commands for each.
- 2. Map the letters
Replace each Greek character in a formula with its standard LaTeX command, such as α with alpha.
- 3. Check capitals and variants
Use commands for distinct uppercase Greek forms, and handle variant letters such as ϵ and ϕ separately.
- 4. Choose a workflow
Use commands for portable source, or compile with LuaLaTeX or XeLaTeX and unicode-math to use Unicode directly.
Greek characters in a UTF-8 file can be converted to LaTeX commands for use in mathematical formulas. For example, write \alpha instead of α and \Omega instead of Ω. This is often the most portable choice, especially if the document must compile with pdfLaTeX.
You can also keep the Unicode characters in the source and compile with LuaLaTeX or XeLaTeX using the unicode-math package. Which approach is better depends on your compiler and whether you need commands in the source or simply want the characters to typeset correctly.
Common Greek-letter commands
In math mode, LaTeX’s standard commands include:
| Unicode | LaTeX | Unicode | LaTeX |
|---|---|---|---|
| α | \alpha | β | \beta |
| γ | \gamma | δ | \delta |
| ε | \epsilon | θ | \theta |
| λ | \lambda | μ | \mu |
| π | \pi | ρ | \rho |
| σ | \sigma | τ | \tau |
| φ | \phi | ω | \omega |
| Γ | \Gamma | Δ | \Delta |
| Θ | \Theta | Λ | \Lambda |
| Π | \Pi | Σ | \Sigma |
| Φ | \Phi | Ψ | \Psi |
| Ω | \Omega |
The commands belong in math mode, such as $\alpha + \beta$. Several Greek capitals that resemble Latin letters—such as Α, Β, Ε, and Ζ—do not have separate standard commands like \Alpha or \Beta. In ordinary mathematical notation, use the corresponding Latin letter, such as A or B.
Some Greek letters have alternate forms with their own commands. Common examples are ϵ → \varepsilon, ϑ → \vartheta, ϖ → \varpi, ϱ → \varrho, ς → \varsigma, and ϕ → \varphi. The precise glyph shape can depend on the math font, so check the output if matching a particular typeface matters.
Worked conversion
Suppose a formula in a UTF-8 text file is:
α + β = γ
In portable LaTeX math source, replace the characters with commands:
\[
\alpha + \beta = \gamma
\]
Here is a complete minimal document that compiles with pdfLaTeX:
\documentclass{article}
\begin{document}
The relation is
\[
\alpha + \beta = \gamma.
\]
\end{document}
No extra package is needed for these standard math commands. LaTeX interprets the Greek commands inside the displayed math environment.
If you prefer literal Unicode characters, use a Unicode-capable engine and unicode-math. For example, compile this complete file with LuaLaTeX or XeLaTeX:
\documentclass{article}
\usepackage{unicode-math}
\setmathfont{Latin Modern Math}
\begin{document}
\[
α + β = γ
\]
\end{document}
The package enables Unicode math input, and \setmathfont selects a math font. The named font is commonly available with modern TeX distributions.
Automate replacements in a file or string
For a small conversion, use an editor’s find-and-replace feature. For repeated work, a character-by-character mapping avoids replacing unrelated text. This Python example handles several common lowercase letters and distinct Greek capitals:
mapping = {
"α": r"\alpha", "β": r"\beta", "γ": r"\gamma",
"δ": r"\delta", "ε": r"\epsilon", "θ": r"\theta",
"λ": r"\lambda", "μ": r"\mu", "π": r"\pi",
"ρ": r"\rho", "σ": r"\sigma", "τ": r"\tau",
"φ": r"\phi", "ω": r"\omega",
"Γ": r"\Gamma", "Δ": r"\Delta", "Θ": r"\Theta",
"Λ": r"\Lambda", "Π": r"\Pi", "Σ": r"\Sigma",
"Φ": r"\Phi", "Ψ": r"\Psi", "Ω": r"\Omega",
}
def greek_to_latex(text):
return "".join(mapping.get(char, char) for char in text)
print(greek_to_latex("α + β = γ"))
The output is \alpha + \beta = \gamma. This function only changes characters listed in mapping; other text passes through unchanged. Add any symbols you need, including variant forms, before applying it to your material. If you process a whole document, make sure the replacements are intended only for formula content.
Common mistakes
- Using math commands in ordinary text.
\alphais a math command, so place it in math mode. If you need Greek letters in prose, use a text-mode solution or a Unicode-capable text setup instead. - Assuming
\Alphaexists. Standard LaTeX defines commands for Greek capitals with distinct mathematical forms, but not for every capital Greek letter. - Expecting UTF-8 support alone to solve math input. Saving a file as UTF-8 does not by itself make every Unicode character valid in every LaTeX engine. With pdfLaTeX, replacing formula characters with commands is a reliable option; for direct Unicode math, use LuaLaTeX or XeLaTeX with
unicode-math. - Replacing characters without checking the context. A global replacement can alter quoted text, code, or material where the original Unicode character should remain. Review the result and compile the document to catch errors.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.