\ProvidesPackage{culmus}[2013/01/21 Culmus Fonts for Hebrew]

% Add option to use legacy (small) font size (this font size was used
% until culmus-latex-0.6
\DeclareOption{small-size}{
	\def\font@scale{1}
}

% whether to use David as the default Roman font.
\def\culmus@useDavid{0}
\DeclareOption{use-david}{
	\def\culmus@useDavid{1}
}
% Set multipliers to adjust font size to be some sane value (make it about
% the same size as the old Hebrew fonts.
\def\font@scale{1.20}

% Process options now to overide the size multipliers
\ProcessOptions\relax

\DeclareFontEncoding{HE8}{}{}
\providecommand{\HeblatexEncoding}{HE8}%
\providecommand{\HeblatexEncodingFile}{he8enc}%

% an attempt to give some replacements to the original hebfonts:
% 
\DeclareTextFontCommand{\textcrml}{\fontfamily{david}\selectfont}
\DeclareTextFontCommand{\textfr}{\fontfamily{frank}\selectfont}
\DeclareTextFontCommand{\textredis}{\fontfamily{aharoni}\selectfont}
\DeclareTextFontCommand{\textclas}{\fontfamily{drugulin}\selectfont}
\DeclareTextFontCommand{\textshold}{\fontfamily{frank}\selectfont}
\DeclareTextFontCommand{\textshscr}{\fontfamily{yad}\selectfont}
% note that redis is larger than shstk
\DeclareTextFontCommand{\textshstk}{\fontfamily{aharoni}\selectfont}

%%The following is the prefered way to set default fonts but it causes problems with english text
% set default fonts
%\ifnum \culmus@useDavid=0
	%\renewcommand{\rmdefault}{frank}
%\else
	%\renewcommand{\rmdefault}{david}
%\fi
%\renewcommand{\sfdefault}{nachlieli}
%\renewcommand{\ttdefault}{miriam}

% and finally: make it the default of HE8:
% this is done by defining font substitues for cm and lm
\DeclareFontFamily{HE8}{cmr}{}
\DeclareFontFamily{HE8}{lmr}{}
\ifnum \culmus@useDavid=0
	\DeclareFontShape{HE8}{cmr}{m}{n} {<-> s*[\font@scale]frank}{}
	\DeclareFontShape{HE8}{cmr}{m}{it} {<-> s*[\font@scale]franki}{}
	\DeclareFontShape{HE8}{cmr}{m}{sl} {<-> s*[\font@scale]franki}{}
	\DeclareFontShape{HE8}{cmr}{b}{n} {<-> s*[\font@scale]frankb}{}
	\DeclareFontShape{HE8}{cmr}{bx}{n} {<-> s*[\font@scale]frankb}{}
	\DeclareFontShape{HE8}{cmr}{bx}{it} {<-> s*[\font@scale]frankbi}{}

	\DeclareFontShape{HE8}{lmr}{m}{n} {<-> s*[\font@scale]frank}{}
	\DeclareFontShape{HE8}{lmr}{m}{it} {<-> s*[\font@scale]franki}{}
	\DeclareFontShape{HE8}{lmr}{m}{sl} {<-> s*[\font@scale]franki}{}
	\DeclareFontShape{HE8}{lmr}{b}{n} {<-> s*[\font@scale]frankb}{}
	\DeclareFontShape{HE8}{lmr}{bx}{n} {<-> s*[\font@scale]frankb}{}
	\DeclareFontShape{HE8}{lmr}{bx}{it} {<-> s*[\font@scale]frankbi}{}
\else
	\DeclareFontShape{HE8}{cmr}{m}{n} {<-> s*[\font@scale]david}{}
	\DeclareFontShape{HE8}{cmr}{m}{it} {<-> s*[\font@scale]davidi}{}
	\DeclareFontShape{HE8}{cmr}{m}{sl} {<-> s*[\font@scale]davidi}{}
	\DeclareFontShape{HE8}{cmr}{b}{n} {<-> s*[\font@scale]davidb}{}
	\DeclareFontShape{HE8}{cmr}{bx}{n} {<-> s*[\font@scale]davidb}{}
	\DeclareFontShape{HE8}{cmr}{bx}{it} {<-> s*[\font@scale]davidbi}{}

	\DeclareFontShape{HE8}{lmr}{m}{n} {<-> s*[\font@scale]david}{}
	\DeclareFontShape{HE8}{lmr}{m}{it} {<-> s*[\font@scale]davidi}{}
	\DeclareFontShape{HE8}{lmr}{m}{sl} {<-> s*[\font@scale]davidi}{}
	\DeclareFontShape{HE8}{lmr}{b}{n} {<-> s*[\font@scale]davidb}{}
	\DeclareFontShape{HE8}{lmr}{bx}{n} {<-> s*[\font@scale]davidb}{}
	\DeclareFontShape{HE8}{lmr}{bx}{it} {<-> s*[\font@scale]davidbi}{}
\fi

\DeclareFontFamily{HE8}{cmtt}{}
\DeclareFontShape{HE8}{cmtt}{m}{n} {<-> s*[\font@scale]miriam}{}
\DeclareFontShape{HE8}{cmtt}{m}{it} {<-> s*[\font@scale]miriami}{}
\DeclareFontShape{HE8}{cmtt}{m}{sl} {<-> s*[\font@scale]miriami}{}
\DeclareFontShape{HE8}{cmtt}{b}{n} {<-> s*[\font@scale]miriamb}{}
\DeclareFontShape{HE8}{cmtt}{bx}{n} {<-> s*[\font@scale]miriamb}{}
\DeclareFontShape{HE8}{cmtt}{bx}{it} {<-> s*[\font@scale]miriambi}{}

\DeclareFontFamily{HE8}{lmtt}{}
\DeclareFontShape{HE8}{lmtt}{m}{n} {<-> s*[\font@scale]miriam}{}
\DeclareFontShape{HE8}{lmtt}{m}{it} {<-> s*[\font@scale]miriami}{}
\DeclareFontShape{HE8}{lmtt}{m}{sl} {<-> s*[\font@scale]miriami}{}
\DeclareFontShape{HE8}{lmtt}{b}{n} {<-> s*[\font@scale]miriamb}{}
\DeclareFontShape{HE8}{lmtt}{bx}{n} {<-> s*[\font@scale]miriamb}{}
\DeclareFontShape{HE8}{lmtt}{bx}{it} {<-> s*[\font@scale]miriambi}{}

\DeclareFontFamily{HE8}{cmss}{}
\DeclareFontShape{HE8}{cmss}{m}{n} {<-> s*[\font@scale]nachlieli}{}
\DeclareFontShape{HE8}{cmss}{m}{it} {<-> s*[\font@scale]nachlielii}{}
\DeclareFontShape{HE8}{cmss}{m}{sl} {<-> s*[\font@scale]nachlielii}{}
\DeclareFontShape{HE8}{cmss}{b}{n} {<-> s*[\font@scale]nachlielib}{}
\DeclareFontShape{HE8}{cmss}{bx}{n} {<-> s*[\font@scale]nachlielib}{}
\DeclareFontShape{HE8}{cmss}{bx}{it} {<-> s*[\font@scale]nachlielibi}{}

\DeclareFontFamily{HE8}{lmss}{}
\DeclareFontShape{HE8}{lmss}{m}{n} {<-> s*[\font@scale]nachlieli}{}
\DeclareFontShape{HE8}{lmss}{m}{it} {<-> s*[\font@scale]nachlielii}{}
\DeclareFontShape{HE8}{lmss}{m}{sl} {<-> s*[\font@scale]nachlielii}{}
\DeclareFontShape{HE8}{lmss}{b}{n} {<-> s*[\font@scale]nachlielib}{}
\DeclareFontShape{HE8}{lmss}{bx}{n} {<-> s*[\font@scale]nachlielib}{}
\DeclareFontShape{HE8}{lmss}{bx}{it} {<-> s*[\font@scale]nachlielibi}{}

% Declare all font famelies used (this should go into *.fd files one day)
% fonts that are missing are commented out.
\DeclareFontFamily{HE8}{frank}{}
\DeclareFontShape{HE8}{frank}{m}{n} {<-> s*[\font@scale]frank}{}
\DeclareFontShape{HE8}{frank}{m}{it} {<-> s*[\font@scale]franki}{}
\DeclareFontShape{HE8}{frank}{m}{sl} {<-> s*[\font@scale]franki}{}
\DeclareFontShape{HE8}{frank}{b}{n} {<-> s*[\font@scale]frankb}{}
\DeclareFontShape{HE8}{frank}{bx}{n} {<-> s*[\font@scale]frankb}{}
\DeclareFontShape{HE8}{frank}{bx}{it} {<-> s*[\font@scale]frankbi}{}

\DeclareFontFamily{HE8}{david}{}
\DeclareFontShape{HE8}{david}{m}{n} {<-> s*[\font@scale]david}{}
\DeclareFontShape{HE8}{david}{m}{it} {<-> s*[\font@scale]davidi}{}
\DeclareFontShape{HE8}{david}{m}{sl} {<-> s*[\font@scale]davidi}{}
\DeclareFontShape{HE8}{david}{b}{n} {<-> s*[\font@scale]davidb}{}
\DeclareFontShape{HE8}{david}{bx}{n} {<-> s*[\font@scale]davidb}{}
\DeclareFontShape{HE8}{david}{bx}{it} {<-> s*[\font@scale]davidbi}{}

\DeclareFontFamily{HE8}{miriam}{}
\DeclareFontShape{HE8}{miriam}{m}{n} {<-> s*[\font@scale]miriam}{}
\DeclareFontShape{HE8}{miriam}{m}{it} {<-> s*[\font@scale]miriami}{}
\DeclareFontShape{HE8}{miriam}{m}{sl} {<-> s*[\font@scale]miriami}{}
\DeclareFontShape{HE8}{miriam}{b}{n} {<-> s*[\font@scale]miriamb}{}
\DeclareFontShape{HE8}{miriam}{bx}{n} {<-> s*[\font@scale]miriamb}{}
\DeclareFontShape{HE8}{miriam}{bx}{it} {<-> s*[\font@scale]miriambi}{}

\DeclareFontFamily{HE8}{nachlieli}{}
\DeclareFontShape{HE8}{nachlieli}{m}{n} {<-> s*[\font@scale]nachlieli}{}
\DeclareFontShape{HE8}{nachlieli}{m}{it} {<-> s*[\font@scale]nachlielii}{}
\DeclareFontShape{HE8}{nachlieli}{m}{sl} {<-> s*[\font@scale]nachlielii}{}
\DeclareFontShape{HE8}{nachlieli}{b}{n} {<-> s*[\font@scale]nachlielib}{}
\DeclareFontShape{HE8}{nachlieli}{bx}{n} {<-> s*[\font@scale]nachlielib}{}
\DeclareFontShape{HE8}{nachlieli}{bx}{it} {<-> s*[\font@scale]nachlielibi}{}

\DeclareFontFamily{HE8}{aharoni}{}
\DeclareFontShape{HE8}{aharoni}{m}{n} {<-> s*[\font@scale]aharoni}{}
\DeclareFontShape{HE8}{aharoni}{m}{it} {<-> s*[\font@scale]aharonii}{}
\DeclareFontShape{HE8}{aharoni}{m}{sl} {<-> s*[\font@scale]aharonii}{}
\DeclareFontShape{HE8}{aharoni}{b}{n} {<-> s*[\font@scale]aharonib}{}
\DeclareFontShape{HE8}{aharoni}{bx}{n} {<-> s*[\font@scale]aharonib}{}
\DeclareFontShape{HE8}{aharoni}{bx}{it} {<-> s*[\font@scale]aharonibi}{}

\DeclareFontFamily{HE8}{ellinia}{}
\DeclareFontShape{HE8}{ellinia}{m}{n} {<-> s*[\font@scale]ellinia}{}
\DeclareFontShape{HE8}{ellinia}{m}{it} {<-> s*[\font@scale]elliniai}{}
\DeclareFontShape{HE8}{ellinia}{m}{sl} {<-> s*[\font@scale]elliniai}{}
\DeclareFontShape{HE8}{ellinia}{b}{n} {<-> s*[\font@scale]elliniab}{}
\DeclareFontShape{HE8}{ellinia}{bx}{n} {<-> s*[\font@scale]elliniab}{}
\DeclareFontShape{HE8}{ellinia}{bx}{it} {<-> s*[\font@scale]elliniabi}{}

\DeclareFontFamily{HE8}{yehuda}{}
\DeclareFontShape{HE8}{yehuda}{m}{n} {<-> s*[\font@scale]yehuda}{}
%\DeclareFontShape{HE8}{yehuda}{m}{it} {<-> s*[\font@scale]yehudai}{}
\DeclareFontShape{HE8}{yehuda}{m}{sl} {<-> s*[\font@scale]yehudai}{}
\DeclareFontShape{HE8}{yehuda}{b}{n} {<-> s*[\font@scale]yehudab}{}
\DeclareFontShape{HE8}{yehuda}{bx}{n} {<-> s*[\font@scale]yehudab}{}
%\DeclareFontShape{HE8}{yehuda}{bx}{it} {<-> s*[\font@scale]yehudabi}{}

\DeclareFontFamily{HE8}{drugulin}{}
%\DeclareFontShape{HE8}{drugulin}{m}{n} {<-> s*[\font@scale]drugulin}{}
%\DeclareFontShape{HE8}{drugulin}{m}{it} {<-> s*[\font@scale]drugulini}{}
%\DeclareFontShape{HE8}{drugulin}{m}{sl} {<-> s*[\font@scale]drugulini}{}
\DeclareFontShape{HE8}{drugulin}{b}{n} {<-> s*[\font@scale]drugulinb}{}
\DeclareFontShape{HE8}{drugulin}{bx}{n} {<-> s*[\font@scale]drugulinb}{}
\DeclareFontShape{HE8}{drugulin}{bx}{it} {<-> s*[\font@scale]drugulinbi}{}

%Fix some nikud naming problems
\let\hebsheva=\sheva
\let\hebhatafsegol=\hatafsegol
\let\hebhatafpatah=\hatafpatah
\let\hebhatafqamats=\hatafqamats
\let\hebhiriq=\hiriq
\let\hebtsere=\tsere
\let\hebsegol=\segol
\let\hebpatah=\patah
\let\hebqamats=\qamats
\let\hebholam=\holam
\let\hebqubuts=\qubuts
\let\hebdagesh=\dagesh
\let\hebmeteg=\meteg
\let\hebmaqaf=\maqaf
\let\hebrafe=\rafe
\let\hebpaseq=\paseq
\let\hebshindot=\shindot
\let\hebsindot=\sindot
\let\hebsofpasuq=\sofpasuq

% Here we map unicode glyphs to their location in the he8 encoding used by culmus-latex
% The numbers must be upper case
\DeclareUnicodeCharacter{05D0}{\char"E0} % aleph
\DeclareUnicodeCharacter{05D1}{\char"E1} % bet
\DeclareUnicodeCharacter{05D2}{\char"E2} % gimel
\DeclareUnicodeCharacter{05D3}{\char"E3} % dalet
\DeclareUnicodeCharacter{05D4}{\char"E4} % he
\DeclareUnicodeCharacter{05D5}{\char"E5} % vav
\DeclareUnicodeCharacter{05D6}{\char"E6} % zayin
\DeclareUnicodeCharacter{05D7}{\char"E7} % het
\DeclareUnicodeCharacter{05D8}{\char"E8} % tet
\DeclareUnicodeCharacter{05D9}{\char"E9} % yod
\DeclareUnicodeCharacter{05DA}{\char"EA} % kaf-sofit
\DeclareUnicodeCharacter{05DB}{\char"EB} % kaf
\DeclareUnicodeCharacter{05DC}{\char"EC} % lamed
\DeclareUnicodeCharacter{05DD}{\char"ED} % mem-sofit
\DeclareUnicodeCharacter{05DE}{\char"EE} % mem
\DeclareUnicodeCharacter{05DF}{\char"EF} % nun-sofit
\DeclareUnicodeCharacter{05E0}{\char"F0} % nun
\DeclareUnicodeCharacter{05E1}{\char"F1} % samech
\DeclareUnicodeCharacter{05E2}{\char"F2} % ayin
\DeclareUnicodeCharacter{05E3}{\char"F3} % pe-sofit
\DeclareUnicodeCharacter{05E4}{\char"F4} % pe
\DeclareUnicodeCharacter{05E5}{\char"F5} % tsadi-sofit
\DeclareUnicodeCharacter{05E6}{\char"F6} % tsadi
\DeclareUnicodeCharacter{05E7}{\char"F7} % quf
\DeclareUnicodeCharacter{05E8}{\char"F8} % resh
\DeclareUnicodeCharacter{05E9}{\char"F9} % shin
\DeclareUnicodeCharacter{05EA}{\char"FA} % tav
