I'ld like to make -> a shortcut for \rightarrow. Is that possible with Plain TeX or has it to do with the loaded font?
Asked
Active
Viewed 1,290 times
16
Mico
- 506,678
lvaneesbeeck
- 3,095
2 Answers
15
Make - math active and assign it a suitable definition.
\edef\minus{\mathchar\the\mathcode`-\space}
\def\lookaheadminus{\futurelet\next\whatsafter}
\def\whatsafter{%
\ifx\next>%
\expandafter\togr
\else
\expandafter\minus
\fi}
\def\togr>{\to}
\begingroup\lccode`~=`-
\lowercase{\endgroup\let~}\lookaheadminus
\mathcode`-="8000
$A->B$ and $a-b$
\bye

Then avoid doing it.
You might enjoy using UTF-8 characters for this:
% <E2> is one of the prefixes for three byte UTF-8 sequences
\catcode"E2=\active
\protected\def^^e2#1#2{\csname\detokenize{^^e2#1#2}\endcsname}
%% similar definition to the above should be made for
%% other prefixes
% the following defines a single Unicode character
\def\defineutfchar#1{%
\protected\expandafter\def\csname\detokenize{#1}\endcsname}
\defineutfchar{→}{\to}
$A→B$
\bye
egreg
- 1,121,712
-
1To this correct answer, I would add that it is very easy to type the → character if you can configure a compose key on your keyboard. (Otherwise you would probably have to rely on some kind of palette character to type the →.) – Michaël Le Barbier Oct 30 '13 at 22:26
-
You define the macro
\togr, which I think is a typo of\toarg. – Charles Stewart Nov 01 '13 at 10:12
14
A humble, faulty attempt, inspired by tohecz, and mainly based on my answer to Censoring Curse Words with Grawlixes:
The converter.lua file:
symbols = { "%-%>", "%=%>", "%<%-", "%<%=" }
replacements = { ["%-%>"] = "\\rightarrow ", ["%=%>"] = "\\Rightarrow ", ["%<%-"] = "\\leftarrow ", ["%<%="] = "\\Leftarrow " }
function replace(line)
for _, element in pairs(symbols) do
if string.find(line, element) then
return string.gsub(line, element, replacements[element])
end
end
return line, 0
end
function converter(line)
occurrences = 0
repeat
line, occurrences = replace(line)
until occurrences == 0
return line
end
callback.register('process_input_buffer', converter)
Then, in the main TeX file:
\directlua{dofile('converter.lua')}
Hello world, $A -> B$, $A => B$, $B <- A$, $B <= A$.
\bye
Of course, this solution requires LuaTeX. :) The output:

I can point at least one problem:
- Naive replacement algorithm, it's just based on pattern replacement. There might be parts of the text where things will break terribly.
An improvement of this code might be a good exercise for the reader. :)
Paulo Cereda
- 44,220
-
1Well, but that's not your mistake. Of course, how can LuaTeX know what
$n<-1$is supposed to mean? :) – yo' Oct 30 '13 at 17:13 -
-(including dimension computation) or you re-create the font tables, which is quite complicated and makes your document not portable. But I'm not an expert on fonts in LaTeX. And very likely this is easily doable in LuaLaTeX. – yo' Oct 30 '13 at 13:53\def\test #1 -> #2\par{#1 $\rightarrow$ #2\par}or similar. – daleif Oct 30 '13 at 13:55<=>). Also I haven't seen anywhere how ligatures are defined so I'm curious of the user is allowed to.But maybe the most convenient way is to redefine the arrows with shorter names (for example
– lvaneesbeeck Oct 30 '13 at 16:05\toand\otfor left/right arrows,\ttoand\ottfor the double arrows)\toactually exists. Defining\otdoesn't sound sooo bad. Then\impliesand\iffexist, and you can define\impliedby. IMHO that makes the code quite readable ;) – yo' Oct 30 '13 at 17:15amsmathand other LaTeX packages for the symbols themselves, this is already done in How could LaTeX replace the tokens<=by the command\leq?, isn’t it? – Qrrbrbirlbel Oct 30 '13 at 20:08LaTeXsolution is to use thesemanticpackage. The ligature you cite it's even provided as a default(although you can turn this off) so you don't even have to use\mathlig{->}{\rightarrow}explicitly. – Bakuriu Oct 30 '13 at 20:47mathlig.texcan be input and then the command\mathlig{->}{\rightarrow}works. But my recommendation would be to define short macros to save typing. – Dan Oct 30 '13 at 22:21