Incorporating math ligatures in ConTeXt
Hi Hans and Taco, I recently came across mathlig.tex (ftp://tug.ctan.org/pub/tex-archive/macros/generic/misc/mathlig.tex) which allows one to write \mathlig {->} {\rightarrow} and then in math mode -> will be equal to \rightarrow so one can just write $A -> B$ I really like this since one does not need to remeber the names of all those operators (>> << >= =< != !< !<= !>= -> => <- <= := ::= ) and the source looks easier to read. The marcos are in plain tex and work with ConTeXt. Do you think that this can be incorporated in ConTeXt as a separate module. This file is way beyond my understanding of TeX. Some parts are easy, but I just keep staring at definitions like \def\actively#1#2{\begingroup\uccode`\~=`#2\relax\uppercase{\endgroup#1~}} without understanding what it means. If you guys get tired of writing lua code, can you have a look into this and see if this can be added to ConTeXt. Aditya
Hi, Aditya Mahajan wrote:
Hi Hans and Taco,
I recently came across mathlig.tex (ftp://tug.ctan.org/pub/tex-archive/macros/generic/misc/mathlig.tex) which allows one to write
\mathlig {->} {\rightarrow}
and then in math mode -> will be equal to \rightarrow so one can just write
$A -> B$
Yes, that reads much better. It really should be a separate module because of potential conflicts with active characters, but you can just incorporate the existing mathlig.tex wholesale in a module file since it appears to work (but consider using \protect/\unprotect instead of the @ trickery)
This file is way beyond my understanding of TeX. Some parts are easy, but I just keep staring at definitions like
\def\actively#1#2{\begingroup\uccode`\~=`#2\relax\uppercase{\endgroup#1~}}
without understanding what it means.
This macro is a candidate for inclusion in the core (syst-ext). It redefines the macro attached to an active character, even if that character is not really active at this moment (such definitions remain dormant). In this case, it is used to make characters like < and - run a macro. Normally this will be done in math mode only, because their \mathcode becomes "8000 but the \catcode remains as it is. But: whenever you switch the character to active mode, this macro will now be executed instead of the original one, and that is why it has to be a module: consider what happens with \mathlig{:=}{\coloneq} in french document ... Side note: Luatex allows direct unicode input \definemathcaracter [→] [rel] [sy] ["21] % 0x2192 $A → B$ Best, Taco
Hi On Sun, 3 Dec 2006, Taco Hoekwater wrote:
Aditya Mahajan wrote:
I recently came across mathlig.tex (ftp://tug.ctan.org/pub/tex-archive/macros/generic/misc/mathlig.tex) which allows one to write
\mathlig {->} {\rightarrow}
and then in math mode -> will be equal to \rightarrow so one can just write
$A -> B$
Yes, that reads much better. It really should be a separate module because of potential conflicts with active characters, but you can just incorporate the existing mathlig.tex wholesale in a module file since it appears to work (but consider using \protect/\unprotect instead of the @ trickery)
I am doing that and converting parts to the ConTeXt "style". Most things are working as expected.
This file is way beyond my understanding of TeX. Some parts are easy, but I just keep staring at definitions like
\def\actively#1#2{\begingroup\uccode`\~=`#2\relax\uppercase{\endgroup#1~}}
without understanding what it means.
This macro is a candidate for inclusion in the core (syst-ext). It redefines the macro attached to an active character, even if that character is not really active at this moment (such definitions remain dormant).
In ConTeXtize mathlig.tex I came across two macros...Is there any ConTeXt equivalent of these? \def\mathlig@let@cs#1#2{\expandafter\let\expandafter#1\csname#2\endcsname} \def\mathlig@appendcs#1#2{\expandafter\edef\csname#1\endcsname{\csname#1\endcsname#2}} If not, what will be the ConTeXt style of doing this?
In this case, it is used to make characters like < and - run a macro. Normally this will be done in math mode only, because their \mathcode becomes "8000 but the \catcode remains as it is.
But: whenever you switch the character to active mode, this macro will now be executed instead of the original one, and that is why it has to be a module: consider what happens with \mathlig{:=}{\coloneq} in french document ...
I know. The catcode trickery can bit you in unexpected ways.
Side note: Luatex allows direct unicode input
\definemathcaracter [→] [rel] [sy] ["21] % 0x2192 $A → B$
Great. No more ugly hacks for utf :) Aditya -- Aditya Mahajan | EECS Systems, University of Michigan http://www.eecs.umich.edu/‾adityam | Ph: 734.262.4008
Aditya Mahajan wrote:
In ConTeXtize mathlig.tex I came across two macros...Is there any ConTeXt equivalent of these?
\def\mathlig@let@cs#1#2{\expandafter\let\expandafter#1\csname#2\endcsname}
\def\mathlig@appendcs#1#2{\expandafter\edef\csname#1\endcsname{\csname#1\endcsname#2}}
Check out the macros whose names start with \append.. in syst-new.tex Best, Taco
Hi, On Mon, 4 Dec 2006, Taco Hoekwater wrote:
Aditya Mahajan wrote:
In ConTeXtize mathlig.tex I came across two macros...Is there any ConTeXt equivalent of these?
\def\mathlig@let@cs#1#2{\expandafter\let\expandafter#1\csname#2\endcsname}
\def\mathlig@appendcs#1#2{\expandafter\edef\csname#1\endcsname{\csname#1\endcsname#2}}
Check out the macros whose names start with \append.. in syst-new.tex
Thanks. There are two macros which I think should go somewhere in the core. \def\actively#1#2% {\begingroup\uccode`\~=`#2\relax\uppercase{\endgroup#1~}} \def\letexpandedvalue#1#2{\@EA\let\@EA#1\csname#2\endcsname} I am attaching the complete module. This was just an excercise for me to see how such things can be done in vanilla tex. And since I just copy pasted most of the code, it was much easier to understand what is going on :) It may have taken less time to simply replace all the := with \colonequals, but thats an another story. The present module will allow something like the following. Clearly not as powerful as what is possible with LuaTeX. Hans has already shown how to do this with LuaTeX about an year ago. \definemathligature [sin] {\sin} \definemathligature [cos] {\cos} \definemathligature [exp] {e^} \definemathligature [sqrt] {\sqrt} % An ugly hack to get things to work: Notice the space \definemathcommand [sin] [nolop] {\mfunction{s in}} \definemathcommand [cos] [nolop] {\mfunction{c os}} \startformula sqrt{sin(x^2) + cos(x^2)} \stopformula \startformula exp{x} + (exp{x})^2 \stopformula Is anyone else interested in this module? If so, I may upload it on the garden.
On Sun, 3 Dec 2006, Taco Hoekwater wrote:
Hi,
Aditya Mahajan wrote:
Hi Hans and Taco,
I recently came across mathlig.tex (ftp://tug.ctan.org/pub/tex-archive/macros/generic/misc/mathlig.tex) which allows one to write
\mathlig {->} {\rightarrow}
and then in math mode -> will be equal to \rightarrow so one can just write
$A -> B$
Yes, that reads much better. It really should be a separate module because of potential conflicts with active characters, but you can just incorporate the existing mathlig.tex wholesale in a module file since it appears to work (but consider using \protect/\unprotect instead of the @ trickery)
Here is the first attempt. I have cleaned up mathlig.tex. Aditya
participants (2)
-
Aditya Mahajan
-
Taco Hoekwater