7

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?

8

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}}
| improve this answer | |
5

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

| improve this answer | |
1

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

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

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.