1%%%%%%%%%%%%%%%%%%%%%%%%%%% bhs.sty %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2% bhs.sty
3% Scanner for the CCAT encoding used in the machine-readable
4% Biblia Hebraica Stuttgardiana
5% to install it, include it as a LaTeX package or style option "bhs"
6% with Plain TeX, say "\input bhs.sty"
7% to activate it, say "\setcode {bhs}
8% 26.07.1999
9%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10% (c) Klaus Lagally
11%     Institut fuer Informatik
12%     Universitaet Stuttgart
13%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14
15\ifx \bhsatcode \undefined \else \expandafter \endinput
16\fi % load only once
17
18\chardef \bhsatcode = \catcode`\@  \catcode`\@ = 11
19
20\a@ident {bhs.sty} {3.09 read BHS Hebrew encoding} {26.07.1999}
21
22\UsePackage {bhslabel} % process BHS labels
23
24%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25% dynamic definitions for BHS Hebrew coding
26{\catcode `\^ 7 \catcode `\ =9 \catcode `\^^M=9 \catcode `\^^I=9
27\catcode `\"=12 \catcode `\&=12
28%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29\gdef \setbhs@codes {% activate and change some codes
30\globaldefs=1
31%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32\def \sc@A {a}   \def \sc@B {b}   \def \sc@C {S}   \def \sc@D {d}
33\def \sc@E {e}   \def \sc@F {A}   \def \sc@G {g}   \def \sc@H {h}
34\def \sc@I {i}   \def \sc@J {t}   \def \sc@K {k}   \def \sc@L {l}
35%\def \sc@M {m}   \def \sc@N {n}   \def \sc@O {O}   \def \sc@P {p}
36\def \sc@M {m}   \def \sc@N {n}\def\sc@O{\n@xp\a@o}\def \sc@P {p}
37\def \sc@Q {q}   \def \sc@R {r}   \def \sc@S {s}   \def \sc@T {t}
38%\def \sc@U {u}   \def \sc@V {D}   \def \sc@W {W}   \def \sc@X {X}
39\def \sc@U {u}   \def \sc@V {D}   \def \sc@W {w}   \def \sc@X {X}
40\def \sc@Y {y}   \def \sc@Z {z}   \def \sc@@ {QQ}
41\a@digits = {0123456789}     	\a@paren  = {[]}
42\a@first = {)+(##&$":.,*0123456789}
43\globaldefs=0 }
44%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45}% end of dynamic definitions for BHS
46%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47
48{\arab@codes
49\catcode `\& 12
50
51\gdef \bhs@beg #1#2{% start BHS scanner
52\@ssimfalse \def \next {\bhs@word #1#2}%
53\ifx #1\@\def \next {\sc@endscan #2}\else			% finished
54\ifx #2\@\def \next {\bhs@testpara #1#2}\else
55\ifx #2?\def \next {\bhs@testpara #1#2}\else
56%\ifx #1W\def \next {\bhs@begW #2}\else
57%\fi
58\fi\fi\fi \next }
59
60\gdef \bhs@word #1#2{% transform input into internal notation
61     \def \next {\bhs@word #2}%
62\ifx #1\@\def \next {\sc@endscan #2}\else			% finished
63\ifx #1]\def \next {\bhs@word }\else
64\ifx #10\def \next {\bhs@zero #2}\else
65\ifx #17\def \next {\bhs@seven #2}\else
66\if\is@in@set #1\a@digits \def \next {\bhs@word }\else
67%
68\ifx #1?\def \next {\bhs@query #2}\else
69\ifx #1:\def \next {\bhs@colon #2}\else
70%\ifx #1O\def \next {\bhs@O #2}\else
71%\ifx #1W\def \next {\bhs@W #2}\else
72\ifx #1|\def \sc@char {|}\sc@put \else
73%\ifx #1#2\def \next {\bhs@word #1|#2}\else
74%
75%\ifx #1.\sc@put \else
76\ifx #1.\def \sc@char {\nxp \a@Zu }\sc@put \else
77\ifx #1'\def \sc@char {'}\sc@put \else
78\ifx #1)\def \sc@char {Q}\sc@put \else
79\ifx #1+\def \sc@char {C}\sc@put \else
80%
81\ifx #1(\def \sc@char {P}\sc@put \else
82\if #1\a@hash \def \sc@char {\nxp \a@S }\sc@put \else
83\ifx #1&\def \sc@char {\nxp \a@s }\sc@put \else
84\ifx #1$\def \sc@char {x}\sc@put \else
85%
86\ifx #1"\def \sc@char {\nxp \a@E }\sc@put \else
87\ifx #1-\def \sc@char {B}\sc@put \else
88\ifx #1*\def \sc@char {*}\sc@put \else
89\ifcat \nxp #1a\edef \sc@char {\csname sc@#1\endcsname }%
90   	\sc@put
91\fi\fi\fi\fi
92\fi\fi\fi\fi
93\fi\fi\fi\fi
94%
95%\fi
96%\fi
97\fi\fi\fi\fi
98%\fi
99\fi\fi\fi\fi
100\next }
101
102%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103
104\gdef \bhs@colon #1{% shwa or chatef
105\def \next {\bhs@word }%
106\ifx #1A\def \sc@char {\nxp \a@A }\else
107\ifx #1F\def \sc@char {\nxp \a@O }\else
108\ifx #1E\def \sc@char {\nxp \a@I }\else
109\def \sc@char {\nxp \a@e }\def \next {\bhs@word #1}%
110\fi\fi\fi \sc@put \next }
111
112\gdef \bhs@O #1#2{% cholem or cholem waw
113\if\is@in@set #1\a@digits \def \next {\bhs@word #1#2O}\else
114	\ifx #1W\def \sc@char {O}\def \next {\bhs@word #2}%
115	\else \def \sc@char {\nxp \a@o }\def \next {\bhs@word #1#2}%
116	\fi \sc@put
117\fi \next }
118
119\iffalse
120\gdef \bhs@W #1{% waw or shureq
121\def \sc@char {w}\def \next {\bhs@word #1}%
122\sc@put \next }
123
124\gdef \bhs@begW #1{% initial waw
125\ifx #1.\def \sc@char {ww}\def \next {\bhs@word }%
126\else \def \sc@char {w}\def \next {\bhs@word #1}%
127\fi \sc@put \next }
128\fi
129
130\gdef \bhs@seven #1{% meteg
131\def \next {\bhs@word }%
132\ifx #15\def \sc@char {|}\sc@put \else
133\if\is@in@set #1\a@digits \else \def \next {\bhs@word #1}%
134\fi\fi \next }
135
136\gdef \bhs@zero #1{% sop pasuq and pasuq
137\ifx #10\def \sc@char {:}\sc@put \def \next {\bhs@word }\else
138%\ifx #15\def \sc@char {K}\sc@put \def \next {\bhs@word }\else
139\ifx #15\def \next {\bhs@pasuq }\else
140\if\is@in@set #1\a@digits \def \next {\bhs@word }\else
141	\def \next {\bhs@word #1}%
142\fi\fi\fi \next }
143
144}% \arab@codes
145
146%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147
148\def \bhs@testpara #1#2{% single initial P ?
149\ifx #1P\def \next {\bhs@para #1#2}%
150\else \def \next {\bhs@word #1#2}%
151\fi \next }
152
153\def \a@c@bhspara {% small paragraph mark
154\putwordb@x {\small \heb@font \heb@testfont
155\act@cd '164 \advance \act@cd \heb@dsp
156\space \char \act@cd \space }\test@token }
157
158\def \a@c@pasuq {% verse division
159\putwordb@x {\small $\!|\!$}\test@token }
160
161\def \bhs@para P#1\@ \@@ {% prepare paragraph mark
162\sc@back \bhspara #1\@ \@@ }
163
164\def \bhs@pasuq #1\@ \@@ {% prepare verse division
165\sc@back \pasuq #1\@ \@@ }
166
167\newcount \bhsmode	\bhsmode 0
168
169\def \bhs@query #1\@ \@@ {% new line, push back the rest
170\ifnum \bhsmode = 1 \sc@back \\#1\@ \@@ \else % finish line
171\ifnum \bhsmode = 2 \sc@back \|#1\@ \@@ \else % stretch line
172			\sc@back #1\@ \@@     % next word
173\fi\fi }
174
175%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176
177\def \set@bhs {% substitute the BHS scanner
178\let \sc@beg \bhs@beg 	\let \sc@word \bhs@word
179\let \sc@back \sc@@back	\let \sc@endscan \sc@@endscan
180\let \a@scan \a@@scan   \setbhs@codes
181\let \arab@codes \bhs@arab@codes
182\let \unarab@codes \bhs@unarab@codes
183\a@message {input encoding set to BHS conventions}}
184
185\xpa \def \xpa \sc@table \xpa {\sc@table % add the BHS encoding
186bhs\set@bhs }
187
188%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189
190\def \bhs@arab@codes {% save and set special characters
191\csname originalTeX\endcsname
192\chardef \spc@de = \catcode`\ 	\catcode`\  = 10
193\chardef \dqc@de = \catcode`\"	\catcode`\" = \@other
194\chardef \lsc@de = \catcode`\<	\catcode`\< = \@other
195\chardef \hsc@de = \catcode`\#	\catcode`\# = \@other
196\chardef \amc@de = \catcode`\&	\catcode`\& = \@other
197\arab@charsubdefmax \charsubdefmax \charsubdefmax \m@ne }
198
199\def \bhs@unarab@codes {% reset catcodes
200\catcode`\  = \spc@de \catcode`\< = \lsc@de \catcode`\" = \dqc@de
201\catcode`\# = \hsc@de \catcode`\& = \amc@de
202\charsubdefmax \arab@charsubdefmax }
203
204{\catcode`\# = \@other \gdef \a@hash {#}}
205
206%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
207
208\a@message {scanner for BHS encoding installed.}
209
210\catcode `\@ = \bhsatcode
211\endinput
212%%%%%%%%%%%%%%%%%%%%%%%% EOF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213
214