Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
add comment

3 Answers

up vote 6 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:

\pi_{\mathtt{film\_title}}
share|improve this answer
add comment

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.

enter image description here

share|improve this answer
add comment

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 \_

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

Your Answer

 
discard

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.