% NOT YET ADAPTED TO THE NEW FONT MACROS 

% I still need to hook in some features into the setup 
% macro. I also have to (re)define farsi etc. in ways 
% similar to arab, so that we have dedicated environments. 
%
% keywords needed: vocalize transscribe 
%
% \startarabic[option=vocalize] % or vocalize=yes
% ......
% \stoparabic

%D \module
%D   [       file=font-arb,
%D        version=1999.11.06,
%D          title=\CONTEXT\ Font Macros,
%D       subtitle=Arabic,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for 
%C details. 

\writestatus{loading}{Context Font Macros / ArabTeX support}

%D At the \NTG\ 10\hoog{th} anniversary meeting Klaus Lagally
%D introduced the audience to arabic typesetting, and after
%D that I knew that some day I really had to look into his
%D generic package. And then, sort of simultaniously Maarten
%D Wisse and Imran Ahsan Nyazee asked me if \CONTEXT\ could
%D support \ARABTEX, a package that provides right to left
%D typesetting of (several variants of) arab and hebrew.
%D Having implemented support for chinese a few weeks before,
%D I could not resist to build in support for arab and hebrew
%D too. Writing support for languages that don't give me any
%D cue on how to pronounce their script, is kind of special. 

%D This is a beta version, since I still have to take care of some 
%D macros that conflict with existing stuff. 

\unprotect 

\definesystemvariable{ARABTEX}

%D A few (maybe too) simple hooks into the font mechanism. The
%D hook into the language module is not yet done.  

\unexpanded\def\setarabicfont#1%
  {\scratchdimen=1.2\bodyfontsize
   \font\arbfont=\truefontname{Arabic#1} at \currentfontscale\scratchdimen
\setx@skels
\newfonttrue 
   \arbfont}

%D Just to be compatible with Arab\TEX\ we define: 

\unexpanded\def\nash    {\setarabicfont\s!Regular}
\unexpanded\def\nashbf  {\setarabicfont\s!Bold   } 
\unexpanded\def\pnash   {\setarabicfont\s!Regular}
\unexpanded\def\pnashbf {\setarabicfont\s!Bold   } 
\unexpanded\def\xnash   {\setarabicfont\s!Regular}
\unexpanded\def\xnashbf {\setarabicfont\s!Bold   } 

%D The display arabic environment (will be an installable 
%D object) uses a few conditionals. Let's do it the 
%D \CONTEXT\ way and define an anvironment that we later can
%D adapt. 

\newif\if@ignore 
\newif\if@endpe

\def\setupARABTEXalternative[#1]%
  {\dodoubleempty\getparameters[\??ARABTEX#1]}

\def\defineARABTEXalternative%
  {\dodoubleempty\dodefineARABTEXalternative}

\def\dodefineARABTEXalternative[#1][#2]%
  {\iffirstargument % \startarab is defined but used already
     \getparameters
       [\??ARABTEX#1]
       [\c!voor=,\c!na=,\c!binnen=\setarab,
        \c!letter=\setarabfont{Arabic\fontstylesuffix}, % evt ArabicRegular
        #2]%
     \expandafter\all@wcmd\csname\e!stop#1\endcsname
     \setvalue{\e!start#1}%
       {\dodoubleempty\dostartARABTEXalternative[#1]}%
     \unexpanded\setvalue{#1}##1%
       {{\initializeARABTEXinternals{#1}\a@RL{##1}}}% 
     \unexpanded\def\RL{\getvalue{#1}}%
     \unexpanded\def\LR{\a@LR}%
     \let\R=\RL  
     \let\L=\LR
  \else
     \defineARABTEXalternative[arabic]%
   \fi}

\def\initializeARABTEXinternals#1%
  {\getvalue{\??ARABTEX#1\c!binnen}%
   \let      \\=\ARABTEXbreakA
   \let      \|=\ARABTEXbreakB
   \let    \cap=\ARABTEXcap
   \let  \sh@ft=\ARABTEXsh@ft
   \let      \b=\ARABTEXb
   \let      \d=\ARABTEXd
   \let       |=\ARABTEXbar
   \let      \,=\ARABTEXcomma
   \let\protect=\ARABTEXprotect 
   \let\normaltx \tx \def\tx {\normaltx \setarabicfont\fontstylesuffix}%
   \let\normaltxx\txx\def\txx{\normaltxx\setarabicfont\fontstylesuffix}}

\def\dostartARABTEXalternative[#1][#2]% 
  {\begingroup
   \getparameters[\??ARABTEX#1][#2]%
   \ifnum1<0\getvalue{\??ARABTEX#1\c!n}\relax
     \startkolommen
   \else
     \getvalue{\??ARABTEX#1\c!voor}%
   \fi
   \initializeARABTEXinternals{#1}%
   \initializeARABTEXend{#1}%
   \arabtext
   \initializeARABTEXalternative{#1}}

\def\initializeARABTEXalternative#1%
  {\getvalue{\??ARABTEX#1\c!letter}}

\def\initializeARABTEXend#1% \CONTEXT\ does use \end quite differently 
  {\long\def\end##1%
     {\endarabtext
      \ifnum1<0\getvalue{\??ARABTEX#1\c!n}\relax
        \stopkolommen
      \else
        \getvalue{\??ARABTEX#1\c!na}%
      \fi
      \endgroup}%
   \let\a@l@end\end 
   \letvalue{\e!stop#1}=\end
   \long\def\end##1%
     {\endarabtext
      \endgroup
      \if@ignore\global\@ignorefalse\expandafter\ignorespaces\fi}}

%D Arabic verbatim. 

\def\typearab{\a@@verb} 

%D Some \LATEX\ macros.

\def \makeatletter  {\unprotect}
\def \makeatother   {\protect} 
\def \typeout     #1{\writestatus{arabtex}{#1}}

%D We have to save some macros.

\let\ARABTEXversion=\empty

\def\startloadingARABTEX% ugly hacks 
  {\catcode`!=12  
   \catcode`?=12 
   \pushmacro\output        \let \output        \scratchtokens
   \pushmacro\LaTeX         \let \LaTeX         \undefined 
   \pushmacro\CJK           \let \CJK           \undefined 
   \pushmacro\year          \let \year          \normalyear
   \pushmacro\month         \let \month         \normalmonth
   \pushmacro\day           \let \day           \normalday
   \pushmacro\input         \def \input    ##1 {\normalinput ##1 }
   \pushmacro\linewidth
   \pushmacro\datum         \def\datum         {\toks0}
   \pushmacro\version       \def\version       {\toks2}
   \pushmacro\theversion    \let\theversion     \ARABTEXversion
   \pushmacro\emphasize
   \pushmacro\cap}

\def\stoploadingARABTEX%
  {\catcode`!=11 
   \catcode`?=11 
   \popmacro\cap
   \popmacro\emphasize
   \popmacro\theversion   
   \popmacro\version
   \popmacro\datum
   \popmacro\linewidth
   \popmacro\input
   \popmacro\day
   \popmacro\month
   \popmacro\year
   \popmacro\CJK            
   \popmacro\LaTeX
   \popmacro\output}         

%D We save some macros: 

\startloadingARABTEX

%D When loading \ARABTEX\ we have to set back the~! and~?. 

\input arabtex.sty 

%D Since \ARABTEX\ has its own \type {\cap}, we save the 
%D new meaning. We also redefine some \PLAIN\ macros, which 
%D happen to have a different meaning in \LATEX. 

\let\ARABTEXversion=\theversion     

\let\ARABTEXcap=\cap 

\def\ARABTEXsh@ft#1%
  {\dimen@.00#1ex
   \multiply\dimen@\fontdimen1\font
   \kern-.0156\dimen@}

\def\ARABTEXd#1%
  {{\o@lign{\relax#1\crcr\hidewidth\sh@ft{10}%
    .\hidewidth}}}

\def\ARABTEXb#1%
  {{\o@lign{\relax#1\crcr\hidewidth\sh@ft{29}%
    \vbox to.2ex{\hbox{\char22}\vss}\hidewidth}}}

%D A few internals: 

\def \ARABTEXcomma  {\relax\ifmmode\mskip\thinmuskip\else\thinspace\fi}
\def \ARABTEXbreakA {\hfill\break}
\def \ARABTEXbreakB {\break}
\edef\ARABTEXbar    {\string|}
\let \ARABTEXprotect \relax

%D Now we can pop the saved macros. 

\stoploadingARABTEX

%D Ah, we have to get rid of some \type {\protect} stuff but
%D to permit testing we add it in the \CONTEXT\ way. 

\bgroup
\catcode`\<=\@other  
\unexpanded\gdef\a@ins%
  {\ifmmode 
     \expandafter<%
   \else 
     \leavevmode \bgroup 
     \arab@codes \set@arabfont \@waslafalse \@wasfalse
     \expandafter\arab@insert 
   \fi}
\unexpanded\gdef\<{\a@ins} 
\catcode`\<=\active
\global\let<=\a@ins
\egroup

%D We also need to register a few macros: 

\all@w@ne\initializeARABTEXalternative % one argument, internal command
\all@wcmd\tx                           % no argument, small font  
\all@wcmd\txx                          % no argument, smaller font 

%D The main definitions are: 

\definefontsynonym [ArabicRegular] [xnsh14]   
\definefontsynonym [ArabicBold]    [xnsh14bf] 

\defineARABTEXalternative
  [arabic]
  [\c!binnen=\setarab,
   \c!letter=\setarabfont\fontstylesuffix]

\defineARABTEXalternative
  [farsi]
  [\c!binnen=\setfarsi,
   \c!letter=\setarabfont\fontstylesuffix]

\defineARABTEXalternative
  [urdu]
  [\c!binnen=\seturdu,
   \c!letter=\setarabfont\fontstylesuffix]

\defineARABTEXalternative
  [maghribi]
  [\c!binnen=\setmaghribi,
   \c!letter=\setarabfont\fontstylesuffix]

%D Apart from such definitions, one can adapt the settings 
%D using \type {\setupARABTEXalternative}. 
%D 
%D A few years ago at the Holland Festivities, I attended {\em
%D The Cave}, one of the most impressive combinations of music
%D and video I know. This composition of Steve Reich (music)
%D and .. (video) concentrates on the common grounds of arabs
%D and jews: their ancestor Abram. Listening to the \CDROM's
%D of {\em The Cave}, provided me the right ambiance for
%D filling in the details of this module. In {\em The Cave},
%D interviews, music, and |<|believe it or not|>| rhythmic
%D typography are the cornerstones. Remembering those big
%D screens, it strikes me that like music, \TEX\ too is a
%D perfect instrument to cross cultural and linguistic 
%D borders. So, let's: 

\protect 

%D those macros,

\endinput 

%D and use them!

% \defineconversion [abjad] [\abj@d]
%
% voetnoten verbatim lijsten indexen tabellen uitlijnen
% 
% \v!hoofdstuk=al-fa.slu
%    \v!inhoud=al-mu.htawayAtu
%   \v!figuren=qA'imaTu al-.suwaru
%  \v!tabellen=qA'imaTu al-^gadAwilu
% \v!grafieken=qA'imaTu al-rusUmu
%     \v!index=al-fihrisu 
%   \v!bijlage=al-mul.haqu
