[comp.text.tex] Math mode in LaTeX

rdubey@yoda.eecs.wsu.edu (Rakesh Dubey - grad student) (05/16/91)

Greetings,

I need to typeset a lot of material in which mathematical 
formulas are interspersed with text. Is it possible to define
something similar to $...$ for the text mode, so that I could use it
instead of \mbox{...} which really gets clumsy and takes too much
space. Right now I write $a \mbox{ or } b$ where it will be very
nice to have something like $a !or! b$. I believe formulas will be
easier to read this way. (The letter ! is just for example).

Thank you for your time,
Rakesh


-- 
Rakesh Dubey
rdubey@yoda.eecs.wsu.edu

espie@ibis.Stanford.EDU (Marc Espie) (05/28/91)

In article <JEFFT.91May16102428@tailgunner.mit.edu> jefft@athena.mit.edu (Jeff Tang) writes:
>In article <1991May15.205919.12393@serval.net.wsu.edu> rdubey@yoda.eecs.wsu.edu (Rakesh Dubey - grad student) writes:
>
>   I need to typeset a lot of material in which mathematical 
>   formulas are interspersed with text. Is it possible to define
>   something similar to $...$ for the text mode, so that I could use it
>   instead of \mbox{...} which really gets clumsy and takes too much
>   space. Right now I write $a \mbox{ or } b$ where it will be very
>   nice to have something like $a !or! b$. I believe formulas will be
>   easier to read this way. (The letter ! is just for example).
>
>How about the  $  character?
>
>$a$ or $b$    should work, though you'll probably need to add spaces.
>
>Jeff Tang
>jefft@athena.mit.edu
There is a very good reason why this is not a good idea:
$\left(a ! or ! b \right)$.
and another one:
$$a ! or ! b$$

So, now redefining !thing! to act like \mbox{thing} is not really 
difficult. Here is a quick answer, it should work with little or no
modification.
----
\catcode`\!=\active
\def\leavemath{\egroup\let!=\entermath}
\def\entermath{\let!=\leavemath\mbox\bgroup}
\let!=\leavemath
----
    Marc (espie@flamingo.stanford.edu)

lynbech@daimi.aau.dk (Christian Lynbech) (05/28/91)

jefft@athena.mit.edu (Jeff Tang) writes:

>In article <1991May15.205919.12393@serval.net.wsu.edu> rdubey@yoda.eecs.wsu.edu (Rakesh Dubey - grad student) writes:

>   I need to typeset a lot of material in which mathematical 
>   formulas are interspersed with text. Is it possible to define
>   something similar to $...$ for the text mode, so that I could use it
>   instead of \mbox{...} which really gets clumsy and takes too much
>   space. Right now I write $a \mbox{ or } b$ where it will be very
>   nice to have something like $a !or! b$. I believe formulas will be
>   easier to read this way. (The letter ! is just for example).

>How about the  $  character?

>$a$ or $b$    should work, though you'll probably need to add spaces.

>Jeff Tang
>jefft@athena.mit.edu



Well, another possibilty is to use a \parbox{\linewidth}{..some text...}, if 
you have a larger piece of text in math-mode. The advantage of \parbox is that
LaTeX will break the text of the second argument into lines of length 
\linewidth. Off course any length could be used instead of \linewidth. Some
fidling is necessary however to make it fit in.


Christian Lynbech

DAIMI
University of Aarhus,DK-Denmark                 email: lynbech@daimi.aau.dk

jeffrey@cs.chalmers.se (Alan Jeffrey) (06/01/91)

In article <1991May28.070140.16324@neon.Stanford.EDU> espie@ibis.Stanford.EDU (Marc Espie) writes:
>So, now redefining !thing! to act like \mbox{thing} is not really 
>difficult. Here is a quick answer, it should work with little or no
>modification.
>----
>\catcode`\!=\active
>\def\leavemath{\egroup\let!=\entermath}
>\def\entermath{\let!=\leavemath\mbox\bgroup}
>\let!=\leavemath
>----

Except that this will produce strange results for writers with a
tendency to use exclaimation marks in their text!

You could try

\newtoks\everytext
\newtoks\everyendtext
\def\textshriek{!}
\catcode`\!=\active
\def!{\relax\ifmmode\expandafter\mathshriek\else\textshriek\fi}
\def\mathshriek#1!{\hbox{\the\everytext#1\the\everyendtext}}

This also gives you token lists \everytext and \everyendtext, which
are used at the beginning and end of every !...! pair.  For example,
if you want all of this text to be set in the upright font, with a
quad space before and after, you could say

   \everytext{\normalshape\quad}  \everyendtext{\quad}

Exercise for the interested reader: why the \relax and why the
\expandafter?  (The answers to these questions, as with any other you
may have about life, the universe and everything, are kept within the
covers of the TeXbook.)

Alan.

-- 
Alan Jeffrey         Tel: +46 31 72 10 98         jeffrey@cs.chalmers.se
Department of Computer Sciences, Chalmers University, Gothenburg, Sweden

dhosek@hmcvax.claremont.edu (Don Hosek) (06/02/91)

In article <4648@undis.cs.chalmers.se>, jeffrey@cs.chalmers.se (Alan Jeffrey) writes:
> In article <1991May28.070140.16324@neon.Stanford.EDU> espie@ibis.Stanford.EDU (Marc Espie) writes:
>>So, now redefining !thing! to act like \mbox{thing} is not really 
>>difficult. Here is a quick answer, it should work with little or no
>>modification.
 
> Except that this will produce strange results for writers with a
> tendency to use exclaimation marks in their text!
 
> You could try
 
> \newtoks\everytext
> \newtoks\everyendtext
> \def\textshriek{!}
> \catcode`\!=\active
> \def!{\relax\ifmmode\expandafter\mathshriek\else\textshriek\fi}
> \def\mathshriek#1!{\hbox{\the\everytext#1\the\everyendtext}}
 
> This also gives you token lists \everytext and \everyendtext, which
> are used at the beginning and end of every !...! pair.  For example,
> if you want all of this text to be set in the upright font, with a
> quad space before and after, you could say

Alternatively, assign ! a mathcode of "8000. See p.155 of the
TeXbook for details (so am I the only one who knew about this
feature?)

> Exercise for the interested reader: why the \relax and why the
> \expandafter?  (The answers to these questions, as with any other you
> may have about life, the universe and everything, are kept within the
> covers of the TeXbook.)

Hmm, I don't think I've ever seen this use of \expandafter
before. I've more typically said:

\ifwhatever \let\next=\a\else\let\next=\b\fi \next

it still has uses but your technique is quite slick.

-dh
 
-- 
Don Hosek                  | To retrieve files from ymir via the mailserver,
dhosek@ymir.claremont.edu  | send a message to mailserv@ymir.claremont.edu 
Quixote Digital Typography | with a line saying send [DIRECTORY]FILENAME
714-625-0147               | where DIRECTORY is the FTP directory (sans 
---------------------------+ "anonymous") and FILENAME is the filename, e.g. 
"send [tex]00readme.txt". There is a list of files in each directory under the 
name 00files.txt. Binary files are not available by this technique.

edward@priam.Berkeley.EDU (Edward Wang) (06/02/91)

The orignal article and I believe all of the followups
seem to have missed an important point.  To give something
like "or" the right spacing, you should make it a binary
operator.  Just using an escape into normal mode (however
convenient it may be) won't be correct in all situations.
Sometimes, you may want \mathord or whatever instead.

geyer@galton.uchicago.edu (06/03/91)

In article <1991Jun2.075733.26205@agate.berkeley.edu>
edward@priam.Berkeley.EDU (Edward Wang) writes:

>The orignal article and I believe all of the followups
>seem to have missed an important point.  To give something
>like "or" the right spacing, you should make it a binary
>operator.  Just using an escape into normal mode (however
>convenient it may be) won't be correct in all situations.
>Sometimes, you may want \mathord or whatever instead.

Quite right, for example

  \newcommand{\set}[1]{\{\,#1\,\}}
  \newcommand{\aand}{\mathbin{\rm and}}
  \newcommand{\oor}{\mathbin{\rm or}}

  \[ C = \set{ (x, y) : x = 0 \aand y \ge 0 \oor x \ge 0 \aand y = 0 } \]

Also note the nice set macro that implements the advice on p.~174 of the
\TeX book.

Charles Geyer
Department of Statistics
University of Chicago
geyer@galton.uchicago.edu

jeffrey@cs.chalmers.se (Alan Jeffrey) (06/03/91)

In article <1991Jun1.193841.1@hmcvax.claremont.edu> dhosek@hmcvax.claremont.edu (Don Hosek) writes:
>
>Alternatively, assign ! a mathcode of "8000. See p.155 of the
>TeXbook for details (so am I the only one who knew about this
>feature?)

Ooops, sorry about that...

>Hmm, I don't think I've ever seen this use of \expandafter
>before. I've more typically said:
>
>\ifwhatever \let\next=\a\else\let\next=\b\fi \next

The problem with doing that is that it doesn't expand in the mouth, so
if you put it inside an \edef (or whatever) you get very weird results
indeed...  I needed this for implementing lists in TeX's mouth
(Tugboat 11(3)) although the technique is someone elses.
Unfortunately I can't remember who's, so if you were that mysterious
TeX hacker in black, please mail me for more credit.

I've been using this technique a lot for coding up boolean expressions
in TeX---define a test to be a macro that expands out to \iftrue or
\iffalse.  Then \truetest and \falsetest are easy:

   \def\truetest{\iftrue}
   \def\falsetest{\iffalse}

negation uses the \expandafter trick:

   \def\nottest#1{#1\expandafter\falsetest\else\expandafter\truetest\fi}

and and or are hacks:

   \def\andtest#1#2{#1\@fi#2}
   \def\@fi{\fi}

   \def\ortest#1{#1\expandafter\K@true\else\expandafter\@identity\fi}
   \def\K@true#1{\iftrue}
   \def\@identity#1{#1}

All improvements welcome...

Alan.


-- 
Alan Jeffrey         Tel: +46 31 72 10 98         jeffrey@cs.chalmers.se
Department of Computer Sciences, Chalmers University, Gothenburg, Sweden