How could LaTeX replace the tokens <=
by the command \leq
efficiently?
Example 1: I have this code:
\[
2x <= 4x - 2
\]
And I want to get after the compilation this:
Example 2:
\[
q --> q
\]
Output:
Example 3:
\[
Q ==> Q
\]
Output:
Best Answer
I assume, the replacements should be done in math mode only. Then the starting characters can be made active via a special value
"8000
for\mathcode
. The characters behave in text mode as usual, but they became special in math mode.The following example document provides parsers for the following shorthands:
Example file:
Remarks:
Macro
\msh@ifnextchar
looks up the next token. In opposite to LaTeX's\@ifnextchar
it does not gobble spaces. For example, this is important fora + -b
(a - b) that is different froma +- b
(a ± b)....
are replaced by\dots
of packageamsmath
, because it has an auto-detection feature. The vertical position of the dots depends on the next token. For example, in a comma separated list,\dots
become\ldots
; if the next token is a+
, then\cdots
is used.Spaces are gobbled after a command token like
\dots
, but not after other characters like...
. Therefore\msh@dot@dot@dot
removes a following space before calling\dots
. Otherwise\dots
would see the space and become\ldots
, even, if the token after the space is a+
.The suggested
_C
for\subseteq
looks too ambiguous too me, because it looks like a normal subscriptC
. Also there is not a good ASCII letter for use in the shorthand of\supseteq
. Therefore I have implemented the shorthands=(
,=)
and the pair=[
,=]
for the square forms.If round or square parentheses follows the equal sign, then the shorthand replacement can be prevented by a space, e.g.
a = (b + c)
.