I'm looking for a TeXway 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.

  \mathcode\expandafter`\string-"8000 }

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

 }\gdef\fooaux#1{\endgroup #1}

A usecase would be:

- is now set in math.
  • It appears that I am unable to spell equivalent.
    – Jörg
    Mar 28, 2014 at 10:35

1 Answer 1


You should use a non active - in the replacement text:


This is a - sign and not a hyphen.

Now - is a hyphen.


enter image description here

In a LaTeX context you probably want to use \ensuremath{-} instead of $-$.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.