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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

How can I know if I am in mathematic enviroment?

Post by localghost »

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