TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 7 down vote accepted

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:

share|improve this answer

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:


\AtBeginDocument{\catcode`\_=12 \mathcode`\_=\string"715F }


\(\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}))\)


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.

enter image description here

share|improve this answer

use \( ... \) for the inline math mode

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

or with a correct fontsize setting

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


or without alltt and then as David suggested with \_

share|improve this answer
This doesn't produce subscripts in the typewriter font as requested. – Andrew Swann Nov 19 '12 at 10:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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