unescaped macros
You can decide to make -
"active" only within math mode, and look ahead for a >
.
\documentclass{article}
\mathchardef\minuschar=\mathcode`-\relax
\mathcode`-="8000\relax
\begingroup\makeatletter\lccode`~=`-\lowercase{\endgroup
\def~{\@ifnextchar{>}{\rightarrow\@gobble}{\minuschar}}}
\begin{document}
We can try $-\int$, $-\sum$, $x->0$, $x- >0$ etc.
\end{document}
When TeX encounters a character with catcode 11 or 12 (letter or other) in math mode, it looks up the character's mathcode. That's a number between "0000
and "8000
(hexadecimal). The value "8000
is treated specially to mean "use the corresponding active character instead". I then defined -
to look ahead for a >
, and either put a \rightarrow
and \@gobble
the >
, or put the minus character.
The easiest solution, as was observed in one of the comments is to directly type →
. Both ConTeXt MkIV and LaTeX + unicode-math
give the right output when using the correct unicode input.
If you are using LuaTeX, it is also possible to parse the input and convert ->
to →
. Here is an example in ConTeXt that uses the translate
module
\usemodule[translate]
\translateinput[->][→]
\translateinput[=>][⇒]
\enableinputtranslation
\starttext
$x - y = 0 => x = y$
\stoptext
Just for the record,
\usepackage{newunicodechar}
\newunicodechar{→}{\to}
allows for
$x→0$
with pdflatex
(the file must be coded in UTF-8 and \usepackage[utf8]{inputenc}
must be used, not utf8x
). It also works with xelatex
or lualatex
(without unicode-math
, of course, otherwise it would be nonsense).