2

I am working on typing a document with a lot of formulas which have words in them. I know I can use \text{} from the AMS package to make the word appear normally in the equation, but I was wondering if there was a less cumbersome way to do this when I have many words in the same formula. Is there a way to set all the characters in a formula to appear normally or else some less obtrusive way to accomplish this?

Example:

$\sigma_{\text{type}=\text{'single'} \, \text{AND} \, \text{price} < 20}(\text{Room})$
9
  • Help us out with some specific examples. For example, is this what you are looking for: tex.stackexchange.com/questions/124450/… Sep 19, 2015 at 2:00
  • 1
    Welcome! Can you give an example? If all the characters should appear normally, you can just stay in text mode. So it isn't really clear what you mean.
    – cfr
    Sep 19, 2015 at 2:01
  • 4
    You can group words in \text: \text{some text here }.
    – Werner
    Sep 19, 2015 at 2:15
  • 2
    BTW, \text if for 'real' texxt inside moth mode: things like identifiers should use \mathrm or similar.
    – Joseph Wright
    Sep 19, 2015 at 5:13
  • 1
    @cfr As always, it's not a clear distinction and there would be always opinions. Personally, I usually think, as a rule of thumb, that text is what connects differents parts of math, that I can't “escape” by using $ because I'm in display math mode or because I'm inside a group/box, etc. hence I have to use \text rather than ending temporarily math mode.
    – Manuel
    Sep 19, 2015 at 19:12

3 Answers 3

4

Based on this answer, here we use * instead of < which is frequently used in math mode.

Just add your text in math mode like *text*, if you which to use character * outside math mode you can do it with the restoration of its code number inside a group.

MWE

\documentclass{article}
\usepackage{amsmath}

\catcode`\*=13
\begingroup
\lccode`\~=`\*
\lowercase{\endgroup
  \def~#1*}{\text{#1}}

\begin{document}

$\sigma_{*type*=*'single'* \, *AND* \, *price* < 20}(*Room*)$

{\catcode`\*=12 text*} 

$\sigma_{*type*=*'single'* \, *AND* \, *price* < 20}(*Room*)$

\end{document}    

Update

Thanks to @egreg suggestion replacing \catcode with \mathcode to avoid changing code number of * every time outside math mode

\documentclass{article}
\usepackage{amsmath}

\mathcode`*="8000
\begingroup
\lccode`\~=`\*
\lowercase{\endgroup
  \def~#1*}{\text{#1}}

\begin{document}

$\sigma_{*type*=*'single'* \, *AND* \, *price* < 20}(*Room*)$

text* 

$\sigma_{*type*=*'single'* \, *AND* \, *price* < 20}(*Room*)$

\end{document}   

Output

enter image description here

2
  • What about \section*{Introduction}? (It won't work.) You should say \mathcode`*="8000, rather than \catcode`*=13 (and \textnormal rather than \text).
    – egreg
    Sep 19, 2015 at 22:37
  • I'm not quite sure how it works, but this is what I was looking for. Thanks!
    – BenP1192
    Sep 20, 2015 at 0:46
0

You can create new command by \newcommand (or \renewcommand if they exist) to make text subscripts. I think something like \newcommand{\pippo}[1]{{}_\text{#1}} could work.. (I cannot try now, sorry)

0

Some things appear the same (or almost the same) in text and math modes, so for this example you could simply use

$\sigma_{\text{type = `single' AND price $<$ 20}}$(Room)

all text

or

$\sigma_{\text{type$\strut =\strut$`single' AND price$\strut <20$}}$(Room)

math mode separation

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .