[XeTeX] Defining a ligature-like macro

James Crippen jcrippen at gmail.com
Thu Nov 16 00:27:40 CET 2006


I am dealing with a Latin based script which uses an underscore
diacritic. A variation of this script uses a digraph of X + "h" where
X is the original graph. Typing the "official" Unicode underscore
diacritic is a pain and precomposed characters don't exist in most
fonts so glyphs both display and typeset poorly. What I'd like to do
is make up a TeX solution for this using something like ligatures, but
I'm not exactly sure where to start.

Right now I have a cumbersome means of representing these graphemes in
(Xe)TeX source:

% Underlines.
\usepackage{soul}
% Underline height and width.
\setul{0.85ex}{0.1ex}
\setuloverlap{-0.1ex}
% Underscore macros.
\newcommand{\kh}{\ul{k}}
\newcommand{\xh}{\ul{x}}
\newcommand{\gh}{\setul{0.3ex}{0.1ex}\ul{g}\setul{0.85ex}{0.1ex}}
% et cetera...

This works, but it's ugly in the source, since I have to type e.g.
\kh{}wáan in a document. Also, switching to the X+"h" script is
cumbersome, although I have considered writing a package and using
some sort of ifthen switch.

What I'd like to have is something like a ligature such that when I
type "kh", depending on some variable setting I either get "kh" or
"\ul{k}" (or a similar macro) as the output. Then I'd wrap that up
into an environment which could be used interspersed with ordinary
English text.

Looking at the tex-text mapping I see that I could possibly hack
something up that would map from one character sequence to a single
character, but I'm unsure whether I could use this to map to a
character sequence, and furthermore I don't think I could use TeX
macros as the end result of the mapping.

Anyone have suggestions on this, or somewhere to start looking for a
solution? I have no idea where to start or what to search for.

Thanks,
James Crippen


More information about the XeTeX mailing list