I'm looking for a TeX
way to substitute -
(or other characters) while in text-mode with their math equivalent (i.e. $-$
) in one environment/group. I'm looking for a 'switch' (\foo #
and not \foo{#}
).
The code below does essentially what I want, but only works in math-mode.
\def\foo{%
\bgroup\uccode`\~\expandafter`\string-%
\uppercase{\egroup\edef~{\noexpand\text{$-$\relax}}}%
\mathcode\expandafter`\string-"8000 }
\def\textsymbols{\foo}
I've been unable to come up with a solution. The closest I've come is the following command that takes one argument (which I don't want) and it does not work with $-$
(but $+$
works).
\begingroup
\catcode`-=\active\gdef\foo{%
\begingroup\catcode`-=\active\gdef-{$+$}%
\fooaux
}\gdef\fooaux#1{\endgroup #1}
\endgroup
A usecase would be:
\begin{table}
\foo
- is now set in math.
\end{table}
equivalent
.