%% Here's the TeXbook's macro to test if a command has been defined.
\def\ifundefined#1{\expandafter\ifx\csname#1\endcsname\relax}
\def\monthname#1{\ifcase#1 XXX\or Jan\or Feb\or Mar\or Apr\or May\or
        Jun\or Jul\or Aug\or Sep\or Oct\or Nov\or Dec\or ZZZ\fi}
\bgroup\catcode`\ =11\gdef\mkrspace{ }\egroup
\ifundefined{today}%
        \def\today{\the\day\mkrspace\monthname\month\mkrspace\the\year}%
\fi
\newcount\scr % scratch counter
\newcount\hrs \newcount\mins
\def\getnow{\hrs=\time \divide\hrs by60 \mins=\hrs \multiply \mins by60
        \advance\mins by-\time \multiply\mins by-1 }
\getnow
\def\now{\the\hrs:\the\mins}

%% Catcodes made accessible...
\def\active{13 }\let\ACTIVE=\active 
\def\ESCAPECHAR{0 }
\def\STARTGROUP{1 }\def\ENDGROUP{2 }
\def\MATHSHIFT{3 }\def\ALIGNMENTTAB{4 }
\def\ENDOFLINE{5 }\def\PARAMETER{6 }
\def\SUPERSCRIPT{7 }\def\SUBSCRIPT{8 }
\def\IGNOREDCHAR{9 }\def\SPACECATCODE{10 }
\def\LETTER{11 }\def\OTHER{12 }\def\COMMENTCHAR{14 }
\def\INVALIDCHAR{15 }

\newif\ifAHFONTS  \AHFONTSfalse % the default
%\AHFONTStrue

%% This macro file is part of the Makor2 package for typesetting Hebrew
%% with Omega.  (Alan Hoenig; July, 2002).

\let\G=\global \let\X=\expandafter

%% Most of the Makor business is taken care of by Omega OTPs, but some
%% stuff still needs to be done via macros.  Foremost is the utilities
%% to get kerns between characters, so we can determine a characters
%% axis. 

%% \getkern{a}{b} stores the kerns between characters a and b 
%% in the current
%% font in \dimen0.
\def\getkern#1#2{\setbox0=\hbox{#1#2}\dimen0=\wd0\relax
  \setbox0=\hbox{#1{}#2}%
  \advance\dimen0 by-\wd0% dimen0 is the kern
}

%% In Makor, the kerns between the nullchar (\char254) and any other
%% character yield the width of the offset from the medial axis
%% through the type.  A positive kern means the displacement is to the
%% right; to the left, otherwise.  \getloweraxis{ch} gets the lower
%% axis of the letter ch.
\newdimen\axisoffset
\def\nullchar{\char254 }
\def\getloweraxis#1{\getkern{\nullchar}{#1}\axisoffset=\dimen0 }
\def\getupperaxis#1{\getkern{#1}{\nullchar}\axisoffset=\dimen0 }

%% Here follow some straightforward macros to adjust the placement of
%% a glyph's vowels.  Adjustment can occur for either or both of an
%% upper and lower accent.  Normally, the adjustment parameter is
%% $-10$, which means no adjustments are necessary.  Otherwise, its
%% value is a number which multiplies the width of the glyph and
%% determines where to place the accent.  Suppose the glyph's width is
%% $w$.  Then:
%%   * 0 means place the accent at the left edge;
%%   * 1 means place the accent at the right edge;
%%   * .6 means (for ex) place the accent 60\% of the way between left
%%   and right;
%%   * 1.2 means place the accent 20\% of w past right edge of the type;
%%   * -.15 means place the accent 15\% of w to the left of the type; and
%% so on for other values.
\def\upperfudgefactor{-10}\def\lowerfudgefactor{-10}% default values
\def\fudgefactordefault{-10}
\def\upperadjustment#1{\def\upperfudgefactor{#1}}
\def\loweradjustment#1{\gdef\lowerfudgefactor{#1}}

\def\startnum!{\bgroup\textdir TLT{}}\def\endnum!{\egroup}

\newdimen\upperaxisoffset \newdimen\loweraxisoffset 
\newdimen\glyphwd \newdimen\glyphht \newdimen\glyphdp
\newdimen\lowerglyphremainder \newdimen\upperglyphremainder
\newdimen\IC \newdimen\leftedge \newdimen\rightedge
\def\getIC#1{% get the Italic Correction of a character
        \setbox0=\hbox{#1\ItalCorrec}\setbox2=\hbox{#1}\dimen0=\wd0
        \advance\dimen0 by-\wd2 \IC=\dimen0 }
\def\getICstandards{\setbox0=\hbox{\clearocplists Y}\G\leftedge=\ht0
        \setbox0=\hbox{\clearocplists Z}\G\rightedge=\ht0 }
\def\measureuppertrope#1{\getICstandards\measurediacrit{#1}%
        \getIC{#1}%
        \ifdim\IC=\leftedge  \gdef\upperfudgefactor{.2}\fi
        \ifdim\IC=\rightedge \gdef\upperfudgefactor{.8}\fi}

\def\lap#1{\hbox to 0pt{\hss#1\hss}}
\def\getloweraxisandoffset#1{\getloweraxis{#1}\loweraxisoffset=\axisoffset}
\def\getupperaxisandoffset#1{\getupperaxis{#1}\upperaxisoffset=\axisoffset}
\newdimen\upxtune \newdimen\upytune \newdimen\lowxtune
        \newdimen\lowytune
\newdimen\upxtuning \newdimen\upytuning \newdimen\lowxtuning
        \newdimen\lowytuning
\upxtune=0pt \upytune=0pt \lowxtune=0pt \lowytune=0pt
\upxtuning=0pt\upytuning=0pt \lowxtuning=0pt \lowytuning=0pt
\def\restoredefaultfudges{\G\let\lowerfudgefactor=\fudgefactordefault
        \G\let\upperfudgefactor=\fudgefactordefault
        \G\upxtune=0pt \G\upytune=0pt \G\lowxtune=0pt \G\lowytune=0pt
        \G\upxtuning=0pt\G\upytuning=0pt \G\lowxtuning=0pt
        \G\lowytuning=0pt \makeifsfalse }
\def\adjustloweraxis{% No change in accent placement...
  \ifx\lowerfudgefactor\fudgefactordefault
    \advance\loweraxisoffset by.5\glyphwd
  \else % change the accent placement
    \loweraxisoffset = \lowerfudgefactor\glyphwd
  \fi}
\def\adjustupperaxis{% No change in accent placement...
  \ifx\upperfudgefactor\fudgefactordefault
    \advance\upperaxisoffset by.5\glyphwd
  \else % change the accent placement
    \upperaxisoffset = \upperfudgefactor\glyphwd
  \fi}
\def\getupperglyphremainder{\upperglyphremainder=\glyphwd 
        \advance\upperglyphremainder by-\upperaxisoffset}
\def\getlowerglyphremainder{\lowerglyphremainder=\glyphwd 
        \advance\lowerglyphremainder by-\loweraxisoffset}
\def\measurechar#1{\setbox0=\hbox{#1}\glyphwd=\wd0 \glyphht=\ht0
        \glyphdp=\dp0 }
\newdimen\dwd \def\dbox#1{\hbox to\dwd{#1\hss}}% width, box for diacrit
\def\measurediacrit#1{\setbox0=\hbox{#1}\dwd=\wd0 %
}
\def\PutVwl#1#2{\getloweraxisandoffset{#1}% all vowels are low
  \measurechar{#1}\measurediacrit{#2}\adjustloweraxis
  %% Now place glyph plus accent
    %% \glyphremainder is the remaining space to get to the right
    %% edge; glyphremainder + axisoffset = glyphwd
  \getlowerglyphremainder \finagletest
  \noindent\rlap{#1}\kern\lowerglyphremainder
  \ifltune\lap{\dbox{\lowpoint{#2}}}%
  \else\lap{#2}\fi
  \kern\loweraxisoffset
  \penalty10000\restoredefaultfudges
}\let\PutLTrp=\PutVwl % for the time being...
%% Use the following to place an upper accent only...
\def\PutUTrp#1#2{\getupperaxisandoffset{#1}% all vowels are low
  \measurechar{#1}\measureuppertrope{#2}\adjustupperaxis%
  %% Now place glyph plus accent
    %% \glyphremainder is the remaining space to get to the right
    %% edge; glyphremainder + axisoffset = glyphwd
  \getupperglyphremainder \finagletest
  \noindent\rlap{#1}\kern\upperglyphremainder
  \ifutune\raise\glyphht\lap{\dbox{\uppoint{#2}}}%
  \else\raise\glyphht\lap{#2}\fi
  \kern\upperaxisoffset
  \penalty10000\restoredefaultfudges}
\def\ArchaicVowels{\let\PutVwl=\PutUTrp}% for typesetting archaic vwls
\def\ArchO{\vbox{\baselineskip=0pt\ialign{##\crcr\hidewidth o\hidewidth
        \crcr w\crcr}}}% typesetting archaic holam
\newdimen\vwlsep % separation between adjacent trope/vowel combos
\vwlsep = .5pt
\def\PutVwlLTrp#1#2#3{\getloweraxisandoffset{#1}%
  \measurechar{#1}\measurediacrit{#2#3}\adjustloweraxis
  \getlowerglyphremainder\finagletest
  \noindent\rlap{#1}\kern\lowerglyphremainder
  \ifltuning\lap{#2\hskip\lowxtuning\lower\lowytuning\hbox{#3}}%
        \else
        \ifltune\lap{\dbox{\lowpoint{#2#3}}}\else
  \lap{#2\hskip\vwlsep#3}\fi\fi
  \kern\loweraxisoffset
  \penalty10000\restoredefaultfudges}
\let\PutLTrpVwl=\PutVwlLTrp
\def\PutVwlUTrp#1#2#3{\getloweraxisandoffset{#1}\getupperaxisandoffset{#1}%
  \measurechar{#1}\measurediacrit{#2}\measureuppertrope{#3}%
  \adjustloweraxis\adjustupperaxis
  \getlowerglyphremainder \getupperglyphremainder \finagletest
  \noindent\rlap{#1}\kern\lowerglyphremainder
  \ifltune\lap{\dbox{\lowpoint{#2}}}\else\lap{#2}\fi
  \kern-\lowerglyphremainder\kern\upperglyphremainder
    \ifutune\raise\glyphht\lap{\dbox{\uppoint{#3}}}%
  \else\raise\glyphht\lap{#3}\fi
  \kern\upperaxisoffset \penalty10000 \restoredefaultfudges}
\def\PutUTrpVwl#1#2#3{\getloweraxisandoffset{#1}\getupperaxisandoffset{#1}%
  \measurechar{#1}\measurediacrit{#3}\measureuppertrope{#2}%
  \adjustloweraxis\adjustupperaxis
  \getlowerglyphremainder \getupperglyphremainder \finagletest
  \noindent\rlap{#1}\kern\lowerglyphremainder
  \ifltune\lap{\dbox{\lowpoint{#3}}}\else\lap{#3}\fi
  \kern-\lowerglyphremainder\kern\upperglyphremainder
    \ifutune\raise\glyphht\lap{\dbox{\uppoint{#2}}}%
  \else\raise\glyphht\lap{#2}\fi
  \kern\upperaxisoffset \penalty10000 \restoredefaultfudges}
\def\PutCon#1{#1} % do nothing special with consonants...
\let\PutNum=\PutCon \let\PutOther=\PutCon
\newif\ifladjust \newif\ifltune \newif\ifltuning % test for low finagles
\newif\ifuadjust \newif\ifutune \newif\ifutuning % test for up finagles
\def\makeifsfalse{\G\ladjustfalse \G\ltunefalse \G\ltuningfalse
        \G\uadjustfalse \G\utunefalse \G\utuningfalse }
\makeifsfalse % default states
\def\finagletest{% are any finagles needed?
  \ifdim\lowxtune=0pt\else\ifdim\lowytune=0pt\else\ltunetrue\fi\fi
  \ifdim\upxtune=0pt\else\ifdim\upytune=0pt\else\utunetrue\fi\fi
  \ifdim\lowxtuning=0pt\else\ifdim\lowytuning=0pt\else\ltuningtrue\fi\fi
  \ifdim\upxtuning=0pt\else\ifdim\upytuning=0pt\else\utuningtrue\fi\fi
  \ifx\lowerfudgefactor\fudgefactordefault \else \ladjusttrue\fi
  \ifx\upperfudgefactor\fudgefactordefault \else \uadjusttrue\fi}
%% \def\finagletest{% are any finagles needed?
%%   \ltunetrue \utunetrue \ltuningtrue \utuningtrue % defaults
%%   \ifdim\lowxtune=0pt{\ifdim\lowytune=0pt \ltunefalse\fi}\fi
%%   \ifdim\upxtune=0pt  \ifdim\upytune=0pt  \utunefalse\fi\fi
%%   \ifdim\lowxtuning=0pt{\ifdim\lowytuning=0pt \ltuningfalse\fi}\fi
%%   \ifdim\upxtuning=0pt  \ifdim\upytuning=0pt  \utuningfalse\fi\fi
%%   \ifx\lowerfudgefactor\fudgefactordefault \else \ladjusttrue\fi
%%   \ifx\upperfudgefactor\fudgefactordefault \else \uadjusttrue\fi}
\def\loweradj#1{\gdef\lowerfudgefactor{#1}}
\def\upperadj#1{\gdef\upperfudgefactor{#1}}
\def\lowertune[#1,#2]{\G\lowxtune=#1\relax \G\lowytune=#2}
\def\uppertune[#1,#2]{\G\upxtune=#1\relax \G\upytune=#2}
\def\lowertuning[#1,#2;#3,#4]{\lowertune[#3,#4]\G\lowxtuning=\lowxtune
        \G\lowytuning=\lowytune\lowertune[#1,#2]}
\def\uppertuning[#1,#2;#3,#4]{\uppertune[#3,#4]\G\upxtuning=\upxtune
        \G\upytuning=\upytune\uppertune[#1,#2]}
\def\lowpoint#1{\hskip\lowxtune\lower\lowytune\hbox{#1}}
\def\uppoint#1{\hskip\upxtune\raise\upytune\hbox{#1}}

%% Some useful hacks...
\def\'{{\clearocplists\char39\relax}}
\def\"{{\clearocplists\char34\relax}}
\let\ItalCorrec=\/
\def\/{\kern0pt}
\def\PrintChar#1{{\clearocplists\char#1\relax}}

\let\prefilter=\relax
%% List def's
\ocp\yid        = m2yiddish
\ocp\yidcon     = m2yidcon
\ocp\trope      = m2ustrope
\ocp\notrope    = m2usnotrope
\ocp\vwls       = m2usvwls
\ocp\novwls     = m2usnovwls
\ocp\lamed      = m2uslamed
\ocp\bentlamed  = m2usblamed
\ocp\lamednv    = m2uslamednv
\ocp\bentlamednv= m2usblamednv
\ocp\consonants = m2uscons
\ocp\consonantsnv = m2usconsnv
\ocp\aleph      = m2aleph
\ocp\alephnv    = m2alephnv
\ocp\oddments   = m2oddments
\ocp\adddots    = m2dodagesh
\ocp\nodots     = m2dontdagesh
\ocp\contest    = m2contest
\ocp\context    = m2context
\ocp\BLcontext  = m2blcontext
\ocp\fplusv     = m2fplusv % treatment of vocalized finals
\ocp\fplusvalt  = m2fplusvalt % treatment of vocalized finals
\ocp\putvwl     = m2putvwl
\ocp\numb       = m2numeral

\ocp\lagally    = lagally
\ocp\bhsnull    = bhs0
\ocp\bhs        = bhs
\ocp\german     = m2deu2us
{\catcode`@=11
\gdef\newif#1{\count@\escapechar \escapechar\m@ne
  \expandafter\expandafter\expandafter
   \def\@if#1{true}{\let#1=\iftrue}%
  \expandafter\expandafter\expandafter
   \def\@if#1{false}{\let#1=\iffalse}%
  \@if#1{false}\escapechar\count@} % the condition starts out false
\gdef\@if#1#2{\csname\expandafter\if@\string#1#2\endcsname}
{\uccode`1=`i \uccode`2=`f \uppercase{\gdef\if@12{}}}} % `if' is required

\newwrite\tmpout
\let\OCPlist=\ocplist \let\ADDBEFOREOCPLIST=\addbeforeocplist 
\let\NULLOCPLIST=\nullocplist
\def\defIfSwitch#1{\expandafter\newif\csname if#1\endcsname
  \X\def\csname #1off\endcsname{\csname #1false\endcsname}%
  \X\def\csname #1on\endcsname{\csname #1true\endcsname}}
\defIfSwitch{CONTEXT}\CONTEXTon % easy way to suppress contextual analysis
\defIfSwitch{DEU}\DEUoff
\defIfSwitch{BHS}\BHSoff
\defIfSwitch{Lagally}\Lagallyoff
\defIfSwitch{Yiddish}\Yiddishoff
\defIfSwitch{Vowels}\Vowelson
\defIfSwitch{Trope}\Tropeon
\defIfSwitch{BentLamed}\BentLamedoff
\defIfSwitch{AlternateFinal}\AlternateFinaloff
\defIfSwitch{Pal}\Paloff
\defIfSwitch{Bab}\Baboff
\def\disablelistprimitives{%
  \let\ocplist=0\let\addbeforeocplist=0\let\nullocplist=0\relax
}
\def\enablelistprimitives{\let\ocplist=\OCPlist
  \let\addbeforeocplist=\ADDBEFOREOCPLIST \let\nullocplist=\NULLOCPLIST
}
\def\IWrT{\immediate\write\tmpout}
\bgroup \catcode`\%=11 
        \gdef\comment{% }
\egroup
%%
%% Here's the MKR ocplist, which is almost always called for...
\ocplist\MKR =
 \addbeforeocplist .99 \contest 
 \addbeforeocplist 1 \trope 
 \addbeforeocplist 1 \vwls 
 \addbeforeocplist 1 \lamed 
 \addbeforeocplist 1 \consonants 
 \addbeforeocplist 2 \aleph 
 \addbeforeocplist 3 \oddments 
 \addbeforeocplist 4 \adddots 
 \addbeforeocplist 5 \context 
 \addbeforeocplist 6 \fplusv 
 \addbeforeocplist 7 \putvwl 
 \addbeforeocplist 8 \numb 
 \nullocplist 
%% Here follows the machinery for creating ocp lists dynamically...
%%
%% We begin by making available the output stream that keeps a record
%% of these lists.
\def\M#1{\message{Defining ocplist #1...}}
\def\StartSomeOCPLists#1{\immediate\openout\tmpout=#1.tmp }
\StartSomeOCPLists{mkrlists}
\IWrT{\comment I am a temporary file called `mkrlists.tmp'; you may delete me.}
\IWrT{\comment I was created by the Makor2 package for typesetting Hebrew}
\IWrT{\comment with the Omega extension to TeX on \today\mkrspace at \now.}
\IWrT{\comment}
\def\makeocplist#1{\disablelistprimitives
  \IWrT{\comment ocplist #1...}
  \IWrT{\noexpand\ifundefined{#1}\noexpand\M{#1}%
        \global\ocplist\csname #1\endcsname=}%
  %% First, any pre-filters...
  \ifBHS \IWrT{  \addbeforeocplist .5 \bhsnull 
      \addbeforeocplist .5 \bhs}\fi
  \ifLagally\IWrT{  \addbeforeocplist .5 \lagally}\fi
  \ifYiddish\IWrT{  \addbeforeocplist .5 \yid}%
            \IWrT{  \addbeforeocplist .5 \yidcon}%
  \fi
  \ifDEU \IWrT{  \addbeforeocplist .5 \german}\fi
  \ifCONTEXT \IWrT{  \addbeforeocplist .99 \contest}\fi
  %% Trope...
  \ifTrope\IWrT{  \addbeforeocplist 1 \trope}\else
    \IWrT{  \addbeforeocplist 1 \notrope}\fi
  %% Vowels...
    %% Turning off vowels means mapping vocal diacritics to null, and
    %% mapping dagesh forms to un-dagesh, including things like shin+dot
    %% to `naked' shin.  This involves alteration also to \adddots,
    %% \lamed, and \consonants.
  \ifVowels\IWrT{  \addbeforeocplist 1 \vwls}\else
  \IWrT{  \addbeforeocplist 1 \novwls}\fi
  %% Lamed...
  \ifVowels %...
     \ifBentLamed\IWrT{  \addbeforeocplist 1 \bentlamed}\else
     \IWrT{  \addbeforeocplist 1 \lamed}\fi 
  \else % no vowels...
     \ifBentLamed\IWrT{  \addbeforeocplist 1 \bentlamednv}\else
     \IWrT{  \addbeforeocplist 1 \lamednv}\fi 
  \fi
  %% Consonants...
  \ifVowels\IWrT{  \addbeforeocplist 1 \consonants}\else
  \IWrT{  \addbeforeocplist 1 \consonantsnv}\fi
  %% The strange case of Alef/Sheva
  \ifVowels\IWrT{  \addbeforeocplist 2 \aleph}\else
  \IWrT{  \addbeforeocplist 2 \alephnv}\fi
  %% Oddments
  \IWrT{  \addbeforeocplist 3 \oddments}%
  %% Adding the Dagesh...
  \ifVowels\IWrT{  \addbeforeocplist 4 \adddots}\else
  \IWrT{  \addbeforeocplist 4 \nodots}\fi
  %% Contextual analysis...
  \ifCONTEXT 
     \ifBentLamed\IWrT{  \addbeforeocplist 5 \BLcontext}\else
     \IWrT{  \addbeforeocplist 5 \context}\fi
  \fi
  %% Vocalized final forms...
  \ifAlternateFinal\IWrT{  \addbeforeocplist 6 \fplusvalt}\else
  \IWrT{  \addbeforeocplist 6 \fplusv}\fi
  %% Vowel Placement...
  \ifBab\IWrT{  \addbeforeocplist 7 \putbvwl}\elseifPal
  \IWrT{  \addbeforeocplist 7 \putpvwl}\else
  \IWrT{  \addbeforeocplist 7 \putvwl}\fi
  %% Numbers...
  \IWrT{  \addbeforeocplist 8 \numb}%
  %% Finishing the ocp list...
  \IWrT{  \nullocplist \noexpand\fi}\IWrT{}%
  %% FInal details...
  \enablelistprimitives}
%% When you've finished specifying ocplists (environments/conventions),
%% issue this command.
\def\InhaleEnvironmentKnowledge#1{\IWrT{\comment End of lists.}%
        \immediate\closeout\tmpout 
        \enablelistprimitives\input #1.tmp }
\let\MakeMakorEnvironment=\makeocplist
\newif\ifHebrewenvironmentDefined \HebrewenvironmentDefinedfalse
\def\MakorEnvironment#1{\HebrewenvironmentDefinedtrue
        \def\CurrMakorEnv{\X\pushocplist\csname #1\endcsname}\CurrMakorEnv}
\let\MakorConvention=\MakorEnvironment
%% Some standard environments...
\def\MakeStandardMKREnvironments{%\MakeMakorEnvironment{MKR}
\Yiddishon
\Tropeoff
  \MakeMakorEnvironment{YID}
\Tropeon
\Yiddishoff
\BentLamedon
  \MakeMakorEnvironment{MKRbl}      
\BentLamedoff
\Lagallyon
  \MakeMakorEnvironment{Lagally}
\Lagallyoff
\BHSon
  \MakeMakorEnvironment{BHS}
\BHSoff
\DEUon
  \MakeMakorEnvironment{MKRdeu}
\DEUoff
\BentLamedon
  \MakeMakorEnvironment{BHSbl}
\BentLamedoff
\Vowelsoff \Tropeoff
  \MakeMakorEnvironment{MKRnv}
\BHSon
  \MakeMakorEnvironment{BHSnv}% no vowels...
\BHSoff
\Vowelson \Tropeon
\AlternateFinalon
  \MakeMakorEnvironment{MKRalt}
\AlternateFinaloff}
\MakeStandardMKREnvironments \InhaleEnvironmentKnowledge{mkrlists}
\def\CurrMakorEnv{\X\pushocplist\csname MKR\endcsname} % default
\def\CXLV{\pushocplist\MKRnv}% cancelling vowels
%% THe BIBLE environment also needs to know about \ketiv and \qere...
\def\ketiv#1 {{\little\MakorEnvironment{BHSnv}[#1 \unskip]} }
\def\qere*#1 {#1 }

%% Hebrew numbering.  Given a raw interger, this routine converts it to
%% the Hebrew alpha-number.
\newcount\rawnumber     %\scr defined at top of file
\newcount\ones  \newcount\twenty        \newcount\thirty
\newcount\forty \newcount\fifty         \newcount\sixty
\newcount\seventy       \newcount\eighty
\newcount\ninety        \newcount\onehundred
\newcount\twohundred    \newcount\threehundred
\newcount\fourhundred
\def\HebrewDigit#1#2{\ifnum#1=1\relax #2\fi}
\def\ConvertGroup#1#2{% Usage: \ConvertGroup{\twohundred}{200}
        \ifnum\scr<#2\relax #1=0\else
                #1=1 \advance\scr by -#2
        \fi}
\def\GetNumericGroups#1{\scr=#1%
        \ConvertGroup{\fourhundred}{400}%
        \ConvertGroup{\threehundred}{300}%
        \ConvertGroup{\twohundred}{200}%
        \ConvertGroup{\onehundred}{100}%
        \ConvertGroup{\ninety}{90}%
        \ConvertGroup{\eighty}{80}%
        \ConvertGroup{\seventy}{70}%
        \ConvertGroup{\sixty}{60}%
        \ConvertGroup{\fifty}{50}%
        \ConvertGroup{\forty}{40}%
        \ConvertGroup{\thirty}{30}%
        \ConvertGroup{\twenty}{20}}
{\catcode`\$=11 \catcode`\_=11 \catcode`\^=11 % beginning a group
\gdef\ConvertOnes#1{\ones=#1\relax
        \ifnum\ones>19 \G\advance\ones by-20\fi
        \ifcase\ones \or ^'\or v\or g\or d\or h\or w\or z\or 
        ch\or .t\or y\or y^'\or yv\or yg\or yd\or 
        .tw\or .tz\or yz\or ych\or y.t\fi}
\gdef\HNUMERROR{\message{Oops---this value is out-of-bounds for }%
        \message{conversion to a Hebrew number.  I'm stymied.}}
\gdef\HebrewNumber#1{\let\next=\relax \ifnum#1<1\HNUMERROR
        \elseifnum#1>1099\relax \HNUMERROR
        \else\def\next{\DoHebrewNumber{#1}}\fi \next}
\gdef\DoHebrewNumber#1{\rawnumber=#1\relax
        \GetNumericGroups{\rawnumber}%
        \HebrewDigit{\fourhundred}{s}%
        \HebrewDigit{\threehundred}{sh}%
        \HebrewDigit{\twohundred}{r}%
        \HebrewDigit{\onehundred}{q}%
        \HebrewDigit{\ninety}{ts_}%
        \HebrewDigit{\eighty}{f_}%
        \HebrewDigit{\seventy}{`}%
        \HebrewDigit{\sixty}{.s}%
        \HebrewDigit{\fifty}{n_}%
        \HebrewDigit{\forty}{m_}%
        \HebrewDigit{\thirty}{l}%
        \HebrewDigit{\twenty}{kh_}\ConvertOnes{\scr}}
} % ending the group...

\newcount\vnum \vnum=1 % verse number
\newcount\cnum \cnum=1 % chapter number
\newcount\bnum \bnum=1 % book number, in case needed or wanted
\font\little=ezra2 at 7pt
\def\NewVerse{ \G\advance\vnum by 1{\textdir TLT
        \clearocplists\little\the\vnum\ }}
\def\NewVerse{{\little\HebrewNumber{\vnum}\kern3pt}\advance\vnum by 1\relax}
\def\NewChapter{\vnum=1 \leavevmode\the\cnum\kern5pt\advance\cnum by 1\relax}
\ifAHFONTS
        \font\Bf=pacs9t scaled\magstep1
\else
        \font\Bf=cmb10 scaled\magstep2
\fi
\def\NewBook#1{\vfill\eject\advance\bnum by1 \vnum=1 \cnum=1
  {\textdir TLT\centerline{\Bf LIBER #1}}\endgraf\smallskip\noindent}
%% Some font macros.
\newdimen\hfontsize 
\hfontsize=10pt \def\hfontsizeinverse{1.0 } % defaults
\def\hfontdef#1#2#3{% \hfontdef{myhebrew}{rawfont}{size}
        \hfontsize=#3\baselineskip=1.3\hfontsize
        \expandafter\font\csname #1\endcsname = #2 at \hfontsize}
\def\hfont#1{\csname #1\endcsname}
\hfontdef{HDEFAULTFONT}{ezra2}{9pt}
\hfontdef{HFOOTFONT}{ezra2}{6pt}

%% Some footnote macros (really intended for Lambda users)...
\def\ENG{\bgroup\clearocplists\textdir TLT\rm}
\def\ENDENG{\egroup}


\def\INFLATE#1#2{\setbox0=\hbox{#1}\dimen0=\wd0\dimen2=\ht0\relax
        \dimen4=\dp0\relax\hfontdef{TMP}{#2}{1.2\hfontsize}%
        \setbox0=\hbox{\hfont{TMP}#1}\ht0=\dimen2\relax 
        \dp0=\dimen4\leavevmode\box0}
\def\LargeHSpace{{\clearocplists \hskip 4pc plus 2pc minus1pc\char16
  \hskip 4pc plus 2pc minus1pc}}
\def\NewParAfterVerse{{\clearocplists\HPAR\char17\endgraf \noindent }}

\def\HINDENT{\noindent\hskip\parindent}
\def\HPAR{{\clearocplists
        \parfillskip=0pt\hskip0pt plus1fill minus10pc\char254}}
\newskip\MAKORPARFILLSKIP \MAKORPARFILLSKIP=0pc plus100pc minus50pc
\newskip\savedparfillskip \savedparfillskip=\parfillskip
\def\CENTERLASTLINE{\global\parfillskip=\MAKORPARFILLSKIP
   \hskip\parfillskip\char254 }
{\obeylines\gdef\hobeylines{\catcode`\^^M=\active
\def^^M{\HPAR\endgraf}}}

\def\<{ \unskip}\let\>=\<

\def\HEBREW{{\clearocplists\global\catcode`\$=\LETTER 
        \global\catcode`\_=\LETTER \global\catcode`\^=\LETTER}\textdir TRT}
\def\BIBLE{{\clearocplists\global\catcode`\&=\LETTER 
        \global\catcode`\#=\LETTER }}
\def\UNHEBREW{\global\catcode`\$=\MATHSHIFT 
        \global\catcode`\_=\SUBSCRIPT \global\catcode`\^=\SUPERSCRIPT}
\def\UNBIBLE{\global\catcode`\&=\ALIGNMENTTAB 
        \global\catcode`\#=\PARAMETER }

%% In the following, we use two successive nullchar's to signal the
%% beginning and ending of the \[, \]environments.
\def\Hebrew{\HEBREW \CurrMakorEnv
        \bgroup\hfont{HDEFAULTFONT}}
\def\endHebrew{\egroup
        \UNHEBREW\UNBIBLE\clearocplists\textdir TLT\relax}
\let\[=\Hebrew \let\]=\endHebrew

\outer\def\BYE{\HPAR \vfill\supereject\end }

\def\raggedleft{\rightskip=0pt \leftskip=0pt plus4em 
  \spaceskip=.3333em \xspaceskip=.5em }

%% Now for a `\hebalign' set of macros for entering Hebrew tables.

{\catcode`\#=\OTHER\gdef\H{#}}
\newread\MKRRD \newwrite\MKRWRT
\def\CURRWRTFILE{aligntmp}\edef\CURRRDFILE{aligntmp}
\def\Openin{\message{Opening \CURRRDFILE.mkr as input...}%
        \immediate\openin\csname MKRRD\endcsname=\CURRRDFILE.mkr}
\def\Closein{\immediate\closein\csname MKRRD\endcsname}
\def\Openout{\message{Opening \CURRWRTFILE.mkr as output...}
        \immediate\openout\MKRWRT=\CURRWRTFILE.mkr}
\def\Closeout{\message{Closing \CURRWRTFILE.mkr as output...}%
        \immediate\closeout\MKRWRT}
\def\Outline{\immediate\write\csname MKRWRT\endcsname{\the\TSIL}%
        \TSIL={}}

\newtoks\TSIL % holds the reversed line
\def\PARSELINE#1&{\def\ttmp{#1}%
        \ifx\ttmp\Empty 
                \let\next=\SAVELINE
        \else \let\next=\PARSELINE
                \edef\tmpmac{\ttmp &\the\TSIL}%
                \TSIL=\expandafter{\tmpmac}%
        \fi \next}
\def\SAVELINE{\expandafter\STRIPOFFFINALAMPERSAND\the\TSIL\XYZ
        {\let\cr=0\edef\tmp{\the\TSIL\cr}\TSIL=\expandafter{\tmp}%
        \Outline}}
\def\Empty{\empty}
\def\STRIPOFFFINALAMPERSAND#1&\XYZ{\TSIL=\expandafter{#1}}
\def\CR#1{\TSIL={}\PARSELINE#1&\empty&}
\def\MPROTECT#1{\let#1=0\relax}\def\myprotects{}%% default; 
\def\HEBALIGN#1{\Openout
        \TSIL={\halign\bgroup}\Outline
        {\myprotects\let\hfont=0\let\[=0\let\]=0#1}%
        \TSIL={\egroup}\Outline\Closeout 
        \input \CURRWRTFILE.mkr}
\def\HEBNOALIGN#1{\TSIL={\noalign{#1}}\Outline}

%% Makor2, as of summer, 2003, includes a dingbat font called calading2.
%% You get some phases of moon, stars of David, menorahs, and tablets
%% of the law.  Here are the macros that make using this font a bit
%% easier.  YOU MUST DEFINE THE DINGBAT FONT USING THE NAME HDING!  It
%% is defined below, but you may redefine it as you see fit.

\hfontdef{HDING}{calading2}{12pt}
\newcount\DINGCOUNT
\def\GetDingbatFromRange#1#2#3{% #1 is font offset for dingbat
%% #2 is the position in font for first dingbat in series
%% #3 is the number of dingbats in the series
%% Example \GetDingbatFromRange{2}{64}{12} selects the third dingbat
%% in the moon series, which begins at position 64 in the calading2
%% font, and there are 12 different moon dingbats.
  \DINGCOUNT=#2\relax \advance\DINGCOUNT by#1\relax 
  \bgroup
    \hfont{HDING}%
    \count8=#2\relax \advance\count8 by#3\relax \advance\count8 by-1 
    \ifnum\DINGCOUNT>\count8 
      \message{There are only #3 dingbats to choose from, not #1.}
    \else % alles is gut
      \PrintChar{\DINGCOUNT}%
    \fi
  \egroup
}% end of \GetDingbatFromRange
\def\MagenDavid#1{\GetDingbatFromRange{#1}{33}{9}}% #1 in (0..8)
\let\StarOfDavid=\MagenDavid
\def\MoonPhase#1{\GetDingbatFromRange{#1}{64}{12}}% #1 in (0..11)

\def\RoundMenorah{{\hfont{HDING}\PrintChar{42}}}
\def\AngledMenorah{{\hfont{HDING}\PrintChar{43}}}
\def\TabletsOfLaw{{\hfont{HDING}\PrintChar{52}}}
\def\BlackTablets{{\hfont{HDING}\PrintChar{50}}}
\def\BlankTablets{{\hfont{HDING}\PrintChar{51}}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Some silly utility macros..
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% POOR MAN'S BOLD (from the TeXbook) is useful in cases where a genuine
%% bold-face font is not available, such as osheb2
\newbox\pmbbox
\def\PMB#1{\setbox\pmbbox=\hbox{#1}% for larger fonts
  \kern-.015em\copy\pmbbox\kern-\wd\pmbbox
  \kern.03em\copy\pmbbox\kern-\wd\pmbbox
  \kern-.015em\raise.025em\box\pmbbox }
\def\pmb#1{\setbox\pmbbox=\hbox{#1}% for smaller fonts
  \kern-.025em\copy\pmbbox\kern-\wd\pmbbox
  \kern.05em\copy\pmbbox\kern-\wd\pmbbox
  \kern-.025em\raise.0433em\box\pmbbox }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% DEBUG MODE
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\catcode`\@=11
\def\\{\hfont{HDEFAULTFONT}}
\def\DBGPutVwl#1#2{ @PutVwl[{\\#1}][{\\#2}]\endgraf}
\def\DBGPutUTrp#1#2{ @PutUTrp[{\\#1}][{\\#2}]\endgraf}
\def\DBGPutVwlLTrp#1#2#3{ @PutVwlLTrop[{\\#1}][{\\#2}][{\\#3}]\endgraf}
\def\DBGPutVwlUTrp#1#2#3{ @PutVwlUTrp[{\\#1}][{\\#2}][{\\#3}]\endgraf}
\def\DBGPutUTrpVwl#1#2#3{ @PutUTrpVwl[{\\#1}][{\\#2}][{\\#3}]\endgraf}
\def\DBGPutCon#1{ @PutCon[{\\#1}]\endgraf}
\def\DBGPutNum#1{ @PutNum[{\\#1}]\endgraf}
\def\DBGPutOther#1{ @PutOther[{\\#1}]\endgraf}
\def\DBGstartnum!{ @startnum!}
\def\DBGendnum!{@endnum!\endgraf}
\def\begindebugmode#1{\bgroup
  \let\[=\relax \let\]=\relax \let\CENTERLASTLINE=\relax
  \let\HPAR=\relax \let\NewVerse=\relax \let\NewChapter=\relax
  \catcode`\&=11 \catcode`\$=11 \catcode`\^=11 \catcode`\_=11 
  \let\PutVwl=\DBGPutVwl \let\PutVwlUTrp=\DBGPutVwlUTrp
  \let\PutUTrp=\DBGPutUTrp \let\PutVwlLTrp=\DBGPutVwlLTrp
  \let\PutUTrpVwl=\DBGPutUTrpVwl \let\PutCon=\DBGPutCon
  \let\PutNum=\DBGPutNum \let\PutOther=\DBGPutOther
  \let\startnum=\DBGstartnum \let\endnum=\DBGendnum
  \MakeStandardMKREnvironments
  \InhaleEnvironmentKnowledge\MakorEnvironment{#1}%
  \HEBREW\BIBLE\textdir TLT\tt}
\def\enddebugmode{\egroup}

\errorcontextlines=10
%\tolerance=10000
\endinput

%%% Local Variables: 
%%% mode: plain-tex
%%% TeX-master: t
%%% End: 
