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

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

Post by bkas.. » Wed, 24 Nov 1999 04:00:00



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)

Post by Axel Reicher » Wed, 24 Nov 1999 04:00:00



> 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)

Post by bkas.. » Wed, 24 Nov 1999 04:00:00


:> 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)

Post by David Kastru » Wed, 24 Nov 1999 04:00:00





> :> 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
harm has already been done.

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)

Post by Matt Swif » Wed, 24 Nov 1999 04:00:00


    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)

Post by David Carlisl » Thu, 25 Nov 1999 04:00:00




>     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

 
 
 

1. Different numbering styles in different contexts

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:

\renewcommand{\enterexample}{\renewcommand{\labelenumi}{\alph{enumi})}}
\renewcommand{\entertheorem}{\renewcommand{\labelenumi}{\roman{enumi})}}

...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.          |
\----------------------------------------------------------------------/

2. PPP protocol information for programmer

3. (La)TeX vs ConTeXt ?

4. pictures in converted files

5. LaTeX vs. ConTeXt

6. Problems with wiring/@home cable/setting up LAN...

7. LaTeX vs Context

8. ftp publish through proxy?

9. Context vs (La)tex

10. Context problem: defining own commands

11. Metapost calling TeX (with ConTeXt)

12. Justification in ConTeXt & LaTeX