0

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.

4
  • 3
    The problem is the underscore which starts subscript in maths and isn't allowed outside of it. You should use \_ instead.
    – Skillmon
    Oct 21, 2020 at 20:33
  • @Skillmon, thank you! Oct 21, 2020 at 20:56
  • Can you clarify if you want alpha written like this or you want the Greek letter? The question is a bit unclear.
    – egreg
    Oct 21, 2020 at 21:00
  • I want it like this: \texttt{alpha\ _0} corresponds to alpha_0. Oct 21, 2020 at 21:11

2 Answers 2

0

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

1
  • Thank you, the 1. option - the names and the underscore, was the one that I was looking for. Oct 21, 2020 at 21:19
1

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.

\newcommand\param[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.

\newcommand\param[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{\ttfamily\selectfont\alpha} or \textnormal{\ttfamily\selectfont\textalpha} in text mode, the same command will work in math mode as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.