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 am using Plain TeX, not LaTeX.

Right now, I have

\def\text#1{\hbox{#1}}

This works for things like

$$A + \text{foo bar}$$.

However, not for things like:

$$\Sum_{ \text{foo} = a}$$.

How do I fix this? In particular, I want \text to somehow take into account the size of the current math font.

share|improve this question
    
@Werner: thanks for fixing the type setting. –  Anon Coward Oct 29 '11 at 7:27
    
Welcome to TeX.sx! –  Werner Oct 29 '11 at 7:29
    
I think \mathchoice is a TeX command, is it not? –  Werner Oct 29 '11 at 7:30
    
Whoa, this is how it works under the hood? I.e. there's no global "here is current font size" varaible; but instead, it works by specifying: if in Display style, do this; if in Text style, do this, if in script style, if in scriptscript style do this? –  Anon Coward Oct 29 '11 at 7:33
    
Correct - did that solve your problem? –  Werner Oct 29 '11 at 7:48

4 Answers 4

There exists an AMS bundle version for Plain TeX, too:

\input amstex

$$ \text{foo}^{\text{bar}^{\text{baz}}} $$

\bye

Result

share|improve this answer

Here is a solution using \mathchoice, but it hardcodes roman fonts so if you are using inside e.g italic or smallcaps it will not match the surrounding text (might even be desired).

\def\text#1{\mathchoice
  {\hbox{\tenrm #1}}
  {\hbox{\tenrm #1}}
  {\hbox{\sevenrm #1}}
  {\hbox{\fiverm #1}}
}

$$
\text{Abcd}^{\text{Abcd}^{\text{Abcd}}}
\textstyle
\text{Abcd}^{\text{Abcd}^{\text{Abcd}}}
$$
\bye
share|improve this answer

use \def\text#1{{\rm#1}}
 instead

share|improve this answer

If your \text{...} is used for denoting variables, then perhaps \text as provided by amstex.tex is not the right choice, as its argument will be typeset in the font current outside the formula.

It's thus probably more sensible to say

\input amstex
\define\tvar#1{\text{\it #1}}

if you want those snippets typeset in italics independently of the context around the formula. If no spaces in the argument is needed, then

\define\tvar#1{\italic{#1}}

would be sufficient. (In AMS-TeX, the \define command is the analog of \newcommand in LaTeX, it won't override an already defined command.)

A Plain only definition for supporting also spaces might be

\font\sevenit=cmti7
\scriptfont\itfam=\sevenit
\font\fiveit=cmti5
\scriptscriptfont\itfam=\fiveit
\def\tvar{\bgroup\mathcode`\ ="8000 \catcode`\ =12
  \begingroup\lccode`~=` \lowercase{\endgroup\def~{\ }}\tvari}
\def\tvari#1{\it#1\egroup}

$\tvar{Abc deff}$%_{\tvar{Abc deff}}$

The argument would still be typeset in math mode. If spaces are not required, then

\font\sevenit=cmti7
\scriptfont\itfam=\sevenit
\font\fiveit=cmti5
\scriptscriptfont\itfam=\fiveit
\def\tvar#1{{\it#1}}

is sufficient.

For getting Roman text it would be exactly the same, with \rm in place of \it (the \scriptfont and \scriptscriptfont are already defined).

share|improve this answer

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.