TransWikia.com

How can I use texttt{some text} for the names of greek letters?

TeX - LaTeX Asked by Dominika Kollárová on June 14, 2021

I want to write coefficients names as alpha_0, beta_1 and phi_1 using texttt{…} to make it look like a function arguments.

I tried texttt{alpha_0} but I got an error ! Missing $ inserted.<inserted text>$ item texttt{alpha_0}. Based on https://www.tutorialspoint.com/tex_commands/texttt.htm I have tried also texttt{alpha_0}, texttt{$alpha_0$} or even similar name texttt{alfa_0} but nothing worked for me.

2 Answers

If you want the names and the underscore

documentclass{article}
usepackage{amsmath}

begin{document}

$mathtt{alpha_1}$

end{document}

enter image description here

If you want the Greek letters

documentclass{article}
usepackage[LGR,T1]{fontenc}
usepackage{amsmath}

DeclareMathAlphabet{mathgtt}{LGR}{cmtt}{m}{n}

begin{document}

$mathgtt{a_1}$
$mathgtt{b_1}$
$mathgtt{f_1}$

end{document}

The picture also shows the conversion table (some characters are not easily predictable).

enter image description here

Correct answer by egreg on June 14, 2021

If you want an underscore, you must write it in text mode as _. You also need to select a text font that supports Greek letters, such as New Computer Modern Mono or CMU Typewriter Text.

To use alpha in text mode, you can load usepackage{alphabeta}. You can also get textalpha from usepackage{alphabeta} or usepackage{textgreek}.

documentclass{article}
tracinglostchars=2
usepackage[default]{fontsetup} % Sets the text and math fonts to New Computer Modern Book.
usepackage{alphabeta} % Allows alpha, etc. in text mode.

newcommandparam[1]{textnormal{ttfamily #1}}

begin{document}
( param{alpha_0} , param{beta_1} , param{phi_1}
)
end{document}

New Computer Modern Mono sample

An alternative is to use the mathtt alphabet.

If you want the underscores to be subscripts, you can do this:

documentclass{article}
tracinglostchars=2
usepackage[default]{fontsetup} % Sets the text and math fonts to New Computer Modern Book.

newcommandparam[1]{mathtt{#1}}

begin{document}
( param{mupalpha_0} , param{mupbeta_1} , param{mupvarphi_1}
)
end{document}

New Computer Modern Mono sample

The correct symbol names to use are from this manual, but loading usepackage{textgreek} and using textalpha, etc. in math mode will work too.

For mathtt to work in 8-bit legacy PDFTeX, you would need to find (or create) a typewriter font in OML encoding and load it with isomath. That is the only legacy TeX encoding that supports both the Greek and Latin alphabets. If you’ve loaded an 8-bit LGR font and can write textnormal{ttfamilyselectfontalpha} or textnormal{ttfamilyselectfonttextalpha} in text mode, the same command will work in math mode as well.

Answered by Davislor on June 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP