%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\unless\ifdefined\XeTeXversion
  \@latex@error{^^J
   *************************************************^^J
   *** The xdiacomp package only works with XeTeX ***^^J
   *************************************************}
\fi
\ProvidesPackage{xdiacomp}
  [2006/07/06 v0.1 Automatic composition of diacritics from Unicode input]
%\RequirePackage[T3,T1,EU1]{fontenc}
\begingroup
 \def\XunicodeLoaded{%
  \@latex@error{*** this package is not compatible with xunicode ***^^J}\@ehc
  \endgroup\endinput}
\expandafter\ifx\csname UndeclareUTFcomposite\endcsname\relax\else\expandafter\XunicodeLoaded\fi
\endgroup
% various definitions of accents and diacritics 
\gdef\textsubbreve#1{\hmode@bgroup\o@lign{\relax#1\crcr\hidewidth 
 \vbox to.2ex{\hbox{\ifnum\fontdimen1\font=0 %
 \kern-0.0em\else\kern-0.40em\fi\ifnum\XeTeXcharglyph"02D8 > 0\char"02D8\relax%
 \else\fontencoding{T1}\selectfont\char8\fi}\vss}\hidewidth}} 
\gdef\oldain{\ifnum\fontdimen1\font=0 %
    \protect\raisebox{0.4ex}{$\lhook$}%
    \else\protect\raisebox{0.4ex}{\kern.05em$\lhook$\kern-.1em}\fi}
\gdef\oldhamza{\ifnum\fontdimen1\font=0 %
    \protect\raisebox{0.4ex}{$\rhook$}% 
    \else\protect\raisebox{0.4ex}{\kern.05em$\rhook$\kern-.1em}\fi}
\gdef\b#1{\hmode@bgroup\o@lign{\relax#1\crcr\hidewidth\sh@ft{29}%
    \vbox to.2ex{\hbox{\ifnum\XeTeXcharglyph"02C9 > 0\char"02C9\relax%
    \else\fontencoding{T1}\selectfont\char9\fi}\vss}\hidewidth}\egroup}
\newcommand{\ain}{%\raisebox{.8ex}{\fontencoding{T3}\fontfamily{ptm}\selectfont\char21}
	{\fontspec{Gentium}ʿ}}
\newcommand{\hamza}{%\raisebox{.8ex}{\fontencoding{T3}\fontfamily{ptm}\selectfont\char20}
	{\fontspec{Gentium}ʾ}}

% now we redefine the catcodes
\catcode `ḍ = \active
\catcode `ḥ = \active
\catcode `ḳ = \active
\catcode `ṣ = \active
\catcode `ṭ = \active
\catcode `ẓ = \active
\catcode `ḫ = \active
\catcode `ḏ = \active
\catcode `ṯ = \active
\catcode `Ḍ = \active
\catcode `Ḥ = \active
\catcode `Ḳ = \active
\catcode `Ṣ = \active
\catcode `Ṭ = \active
\catcode `Ẓ = \active
\catcode `Ḫ = \active
\catcode `Ḏ = \active
\catcode `Ṯ = \active
\catcode `ʿ = \active
\catcode `ʾ = \active
\catcode `ġ = \active
\catcode `Ġ = \active
\catcode `ǧ = \active
\catcode `Ǧ = \active
\catcode `ā = \active
\catcode `ī = \active
\catcode `ū = \active
\catcode `Ā = \active
\catcode `Ī = \active
\catcode `Ū = \active

\def ḍ{\ifnum\XeTeXcharglyph"1E0D > 0\char"1E0D\relax\else{\d d}\fi}%
\def ḥ{\ifnum\XeTeXcharglyph"1E25 > 0\char"1E25\relax\else{\d h}\fi}%
\def ḳ{\ifnum\XeTeXcharglyph"1E33 > 0\char"1E33\relax\else{\d k}\fi}%
\def ṣ{\ifnum\XeTeXcharglyph"1E63 > 0\char"1E63\relax\else{\d s}\fi}%
\def ṭ{\ifnum\XeTeXcharglyph"1E6D > 0\char"1E6D\relax\else{\d t}\fi}%
\def ẓ{\ifnum\XeTeXcharglyph"1E93 > 0\char"1E93\relax\else{\d z}\fi}%
\def ḫ{\ifnum\XeTeXcharglyph"1E2B > 0\char"1E2B\relax\else{\textsubbreve h}\fi}%
\def ḏ{\ifnum\XeTeXcharglyph"1E0F > 0\char"1E0F\relax\else{\b d}\fi}%
\def ṯ{\ifnum\XeTeXcharglyph"1E6F > 0\char"1E6F\relax\else{\b t}\fi}%
\def Ḍ{\ifnum\XeTeXcharglyph"1E0C > 0\char"1E0C\relax\else{\d D}\fi}%
\def Ḥ{\ifnum\XeTeXcharglyph"1E24 > 0\char"1E24\relax\else{\d H}\fi}%
\def Ḳ{\ifnum\XeTeXcharglyph"1E32 > 0\char"1E32\relax\else{\d K}\fi}%
\def Ṣ{\ifnum\XeTeXcharglyph"1E62 > 0\char"1E62\relax\else{\d S}\fi}%
\def Ṭ{\ifnum\XeTeXcharglyph"1E6C > 0\char"1E6C\relax\else{\d T}\fi}%
\def Ẓ{\ifnum\XeTeXcharglyph"1E92 > 0\char"1E92\relax\else{\d Z}\fi}%
\def Ḫ{\ifnum\XeTeXcharglyph"1E2A > 0\char"1E2A\relax\else{\textsubbreve H}\fi}%
\def Ḏ{\ifnum\XeTeXcharglyph"1E0E > 0\char"1E0E\relax\else{\b D}\fi}%
\def Ṯ{\ifnum\XeTeXcharglyph"1E6E > 0\char"1E6E\relax\else{\b T}\fi}%
\def ʿ{\ifnum\XeTeXcharglyph"02BF > 0\char"02BF\relax\else{\ain}\fi}%
\def ʾ{\ifnum\XeTeXcharglyph"02BE > 0\char"02BE\relax\else{\hamza}\fi}%
\def ġ{\ifnum\XeTeXcharglyph"0121 > 0\char"0121\relax\else{\. g}\fi}%
\def Ġ{\ifnum\XeTeXcharglyph"0120 > 0\char"0120\relax\else{\. G}\fi}%
\def ǧ{\ifnum\XeTeXcharglyph"01E7 > 0\char"01E7\relax\else{\v g}\fi}%
\def Ǧ{\ifnum\XeTeXcharglyph"01E6 > 0\char"01E6\relax\else{\v G}\fi}%
\def ā{\ifnum\XeTeXcharglyph"0101 > 0\char"0101\relax\else{\=a}\fi}%
\def ī{\ifnum\XeTeXcharglyph"012B > 0\char"012B\relax\else{\=ı}\fi}%
\def ū{\ifnum\XeTeXcharglyph"016B > 0\char"016B\relax\else{\=u}\fi}%
\def Ā{\ifnum\XeTeXcharglyph"0101 > 0\char"0100\relax\else{\=A}\fi}%
\def Ī{\ifnum\XeTeXcharglyph"012B > 0\char"012A\relax\else{\=I}\fi}%
\def Ū{\ifnum\XeTeXcharglyph"016B > 0\char"016A\relax\else{\=U}\fi}%

\endinput
