Text FormattingHow can I know if I am in mathematic enviroment?

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
artemff
Posts: 113
Joined: Sat Oct 17, 2009 11:15 pm

How can I know if I am in mathematic enviroment?

Post by artemff »

How can I know if I am in mathematic enviroment?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

artemff
Posts: 113
Joined: Sat Oct 17, 2009 11:15 pm

Re: How can I know if I am in mathematic enviroment?

Post by artemff »

localghost
I need to know about it in program mode. I want to write some commands, which can do other acting, depending on if we it in mathematical environment.
For example

newcommand{\ex}
{\ifthenelse{"the command is called in math mode"}{act1}{act2}}

\[
...
\ex % do act1
...
\]
\ex % do act2
josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Re: How can I know if I am in mathematic enviroment?

Post by josephwright »

TeX has the primitive \ifmmode. You will need to be careful using this with ifthenelse. If you can give a complete example of what you want to achieve, it might help.
Joseph Wright
artemff
Posts: 113
Joined: Sat Oct 17, 2009 11:15 pm

Re: How can I know if I am in mathematic enviroment?

Post by artemff »

josephwrightThanks..

\newcommand{\rv}{\text{В}}
\newcommand{\ra}{\text{А}}
\newcommand{\rma}{\text{мА}}
\newcommand{\rom}{\text{Ом}}
\newcommand{\rvt}{\text{Вт}}
\newcommand{\rkHz}{\text{кГц}}
In \text{} Russian units of measurement. If I amn't in math mode, i should use it without \text command.
Post Reply