Teletype Greek letters

This much depends on the main document font. For Computer Modern, you can use the cbgreek fonts. Other font families support Greek, though. Take your pick.

\documentclass{article}
\usepackage[LGR,T1]{fontenc} % to enable Greek encoding
\usepackage{amsmath}

\DeclareSymbolFont{ttgreek}{LGR}{cmtt}{m}{n}
%\SetSymbolFont{ttgreek}{bold}{LGR}{cmtt}{bx}{n} % there is no bold

\DeclareMathSymbol{\ttalpha}{\mathord}{ttgreek}{`a}
\DeclareMathSymbol{\ttmu}{\mathord}{ttgreek}{`m}
\DeclareMathSymbol{\tttau}{\mathord}{ttgreek}{`t}

\begin{document}

$\alpha\ne\ttalpha$

$\mu\ne\ttmu$

$\tau\ne\tttau$

\end{document}

enter image description here


The commands \alpha, \Beta and so on are defined in math mode. The default text fonts also don’t contain upright Greek lowercase letters.

By default, LaTeX understands Greek letters in your UTF-8 document, but the textalpha package adds commands like \textalpha, \textBeta, and so on. You can instead load the alphabeta package to be able to use commands such as \alpha in either text or math mode. It also enables \textalpha, etc.

In LuaLaTeX, you can select a Unicode font that supports Greek, and have LaTeX switch to it whenever you type a Greek letter:

\documentclass{article}
\tracinglostchars=2
\usepackage[english]{babel}
\usepackage[default]{fontsetup} % Select New Computer Modern Book
\babelprovide[onchar=ids fonts]{greek}
\usepackage{alphabeta}

\begin{document}
\texttt{αβγ\textdelta\textEpsilon\texttheta\textlambda}
\end{document}

If you need to use PDFLaTeX, you can do this:

\documentclass{article}
\tracinglostchars=2
\usepackage[LGR,T1]{fontenc}
\usepackage[utf8]{inputenc} % The default since 2018
\usepackage{alphabeta}

\begin{document}
\texttt{αβγ\textdelta\textEpsilon}
\end{document}

This assumes you only want a few Greek symbols for something like a code listing. Some fonts (such as Computer Modern Unicode) have different forms for Greek mathematical symbols and text, which you select with an OpenType feature such as Greek script or mathematical Greek. If you need to select these forms, or type in actual Greek words with correct hyphenation and final sigmas, you would need to set up separate font features for Greek and English.

\documentclass{article}
\tracinglostchars=2
\usepackage[english]{babel}
\usepackage{fontspec,textalpha}
\babelprovide[onchar=ids fonts]{greek}

\babelfont{rm}
          [Ligatures={Common,Discretionary}]{NewComputerModernBook}
\babelfont{rm}
          [Ligatures={Common,Discretionary}]{NewComputerModernSansBook}
\babelfont{tt}
          [Ligatures={Discretionary}]{NewComputerModernMonoBook}

\begin{document}
\texttt{αβγ\textdelta\textEpsilon\texttheta\textlambda}
\end{document}

In math mode, fontspec will allow a Unicode font as \mathtt. If you’re stuck using an 8-bit engine, \usepackage[OMLmathtt]{isomath} will allow you to load a \mathtt font containing Greek. There are few if any OML-encoded upright monospace fonts available for TeX, but I the option is there, and I suppose you could create one from a Unicode font yourself.

You can also define

\newcommand\vartt[1]{\textnormal{\ttfamily #1}}

to allow text-mode Greek in math mode, which could support an 8-bit LGR font. If you also load \usepackage{alphabeta}, you can use \vartt{\alpha} and so on.

Finally, mathastext has an option to load a Greek math alphabet from a LGR-encoded font.

Tags:

Math Fonts