## command that behaves different in a math context (vs. text context)

### command that behaves different in a math context (vs. text context)

Subject: command that behaves different in a math context (vs. text context)

To: comp.text.tex

I am searching for a mechanism that will make it possible to make
a command behave differently in a math environment than in a
text environment.  For example, the bold used in this command
should be mathbf in a math environment and textbf elsewhere.

Any advise would be greatly appreciated,
BK

### command that behaves different in a math context (vs. text context)

> I am searching for a mechanism that will make it possible to make
> a command behave differently in a math environment than in a
> text environment.

TeX: \ifmmode ... \else ... \fi
LaTeX: ifthen.sty

Happy TeXing!
--
Axel Reichert -- http://www.axel-reichert.de

### command that behaves different in a math context (vs. text context)

:> I am searching for a mechanism that will make it possible to make
:> a command behave differently in a math environment than in a
:> text environment.

: TeX: \ifmmode ... \else ... \fi
: LaTeX: ifthen.sty

Works like a charm.

: Happy TeXing!

Happy TeXing indeed.
BK

: --
: Axel Reichert -- http://www.axel-reichert.de

### command that behaves different in a math context (vs. text context)

> :> I am searching for a mechanism that will make it possible to make
> :> a command behave differently in a math environment than in a
> :> text environment.

> : TeX: \ifmmode ... \else ... \fi
> : LaTeX: ifthen.sty

> Works like a charm.

The former does not.  Well, strictly speaking, it does, but you might
be surprised at what points of time TeX/LaTeX secretly puts a foot
forward in the wrong mode, then surprises you by doing the real thing
in an entirely different mode.

This usually happens at places in array or tabular environments where
*is peeking in order to detect if a column starts with
\multicolumn or \hline or \cline and the like.  This peeking often
happens in a different mode than the real typesetting, but then the

In order not to have it evaluate \ifmmode in these peeking situations,
you have to place something like \relax before them.

So: TeX: \relax \ifmmode ...

ifthen.sty I know not, so cannot comment on that.

--
David Kastrup                                     Phone: +49-234-32-25570

Institut fr Neuroinformatik, Universit?tsstr. 150, 44780 Bochum, Germany

### command that behaves different in a math context (vs. text context)

D> In order not to have it evaluate \ifmmode in these peeking situations,
D> you have to place something like \relax before them.

D> So: TeX: \relax \ifmmode ...

Wow, thanks for this explanation.  I have memories of being utterly
confounded by some \relax's in the*kernel and other
authoritative code, and I think many were before \if<mode> commands.

Should one also use \relax before \ifvmode and \ifhmode for the same
reasons?

### command that behaves different in a math context (vs. text context)

>     D> In order not to have it evaluate \ifmmode in these peeking situations,
>     D> you have to place something like \relax before them.

>     D> So: TeX: \relax \ifmmode ...

> Wow, thanks for this explanation.  I have memories of being utterly
> confounded by some \relax's in the*kernel and other
> authoritative code, and I think many were before \if<mode> commands.

> Should one also use \relax before \ifvmode and \ifhmode for the same
> reasons?

Yes, \ifvmode is true in a tabular p column, unless it occurs as the
first token, when it is false.

Actually \relax is not enough in general, for any of these \if...
It solves the tabular problem but they all make the command in use
fragile. If for example you do $\ifmmode math\fi$ it will say math
unless you happen to put this in a `moving argument' in which case
the \if will expand (to false) during the move, and so the table of
contents or whatever will just see  and probably try to start display
math....

if you go \DeclareRobustCommand\foo{\ifmmode math\fi}

and then use \foo. Both of these problems will be avoided by the
insertion of \protect at suitable times.

David

Some of the notes I'm typesetting at the moment in AMSLaTeX follow a
very precise convention with enumerations.  Within a theorem of type
'example', the items all want \alph) labels, and within theorems of type
'theorem', they want \roman) labels.

At the moment, I'm manually switching with \renewcomand{\labelenumi}.
But I'm sure there must be a better way.  I was hoping there would be
some 'hook' macro invoked every time a given theoremstyle environment is
entered so I could do something like this:


...but I can't work out if such a hook exists.  Does one, or is there
another approach?

Many thanks for any help,

Jules

--
/----------------+-------------------------------+---------------------\

|  Jules aka     |                               |  Richmond, Surrey   |

+----------------+-------------------------------+---------------------+
|  War doesn't demonstrate who's right... just who's left.             |
|  When privacy is outlawed... only the outlaws have privacy.          |
\----------------------------------------------------------------------/