# verbatim subscript in mathmode

I want to produce a formula in Math-Mode which is something like

\pi_{film_title}(\sigma_{release_year > 2006}(film))


where film_title, release_year, and film are in verbatim so far I was using the alltt package, but the acclaimed \sb only produces subscripts in the usual math mode font.

Any tips for that?

-

You should be able to use \_ to get _ (the actual appearance depends on the font unless you have redefined \_ to use a rule, but either way the markup is:

\pi_{\mathtt{film\_title}}

-

I wouldn't use the alltt environment for this. The simplest way is to give up the _ character for subscripts and using \sb in its place:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{amsmath}

\AtBeginDocument{\catcode\_=12 \mathcode\_=\string"715F }
\DeclareMathAlphabet{\mathtt}{\encodingdefault}{\ttdefault}{m}{n}

\begin{document}

$$\pi\sb\texttt{film_title}(\sigma\sb\texttt{release_year > 2006}(\texttt{film}))$$

$$\pi\sb\mathtt{film_title}(\sigma\sb\mathtt{release_year > 2006}(\mathtt{film}))$$

\end{document}


Using amsmath and \texttt or \mathtt ensures the correct size for subscripts. Here you see the results: the difference is in you math symbols are treated: with \texttt you get the > in typewriter type and spaces are kept, with \mathtt you get the > symbol from the normal math font.

-

use $$...$$ for the inline math mode

\begin{alltt}
$$\pi\sb{film_title}(\sigma\sb{release_year > 2006}(film))$$
\end{alltt}


or with a correct fontsize setting

\documentclass{article}
\usepackage{alltt,amsmath}
\begin{document}
\begin{alltt}
$$\pi\sb{\text{film_title}}(\sigma\sb{\text{release_year > 2006}}(film))$$
\end{alltt}

\end{document}


or without alltt and then as David suggested with \_

-
This doesn't produce subscripts in the typewriter font as requested. –  Andrew Swann Nov 19 '12 at 10:59