Text Formatting ⇒ Replacing * with \cdot
Replacing * with \cdot
i have no idea if this is the right place for this question, so if not pls move it for me.
what i generelly want is a script or something which is able to replace the "*"-character with a \cdot. But the script should only replace the * if i'm in mathmode and not in the normal text mode. What i already found on another board is this:
1:
2: \catcode '\*=\active
3: \def *{\cdot}
4:
5:
6: \begin{document}
7:
8: $a*b=c$
9:
10:
11: Ein Stern: $\ast$
12:
13: \end{document}
it actually already works perfectly, the only problem is that it replaces ANY *-character, although i only want those to be replaced that are written in mathmode. So what i need is an if-else-kinda thing, that can check if i'm in mathmode or not. Does anyone of you have an idea how i can realise this?
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
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
Re: Replacing * with \cdot
Re: Replacing * with \cdot
Replacing * with \cdot
\ifmmode ... \else ... \fi
But making the asterisk active also breaks commands + environments, that use it already, such as
\newcommand*
or, speaking of math, the *-variants like align* (amsmath)...KR
Rainer