-- TexStateInit.mesa

-- last written by Doug Wyatt, November 9, 1979 5:57 PM

DIRECTORY
TexDefs: FROM "TexDefs",
TexGlueDefs: FROM "TexGlueDefs",
TexIODefs: FROM "TexIODefs",
TexMathDefs: FROM "TexMathDefs",
TexTableDefs: FROM "TexTableDefs",
FrameDefs: FROM "FrameDefs" USING[SelfDestruct],
InlineDefs: FROM "InlineDefs" USING[LongDiv,LongMult];

TexStateInit: PROGRAM
IMPORTS TexGlueDefs,TexTableDefs,FrameDefs,InlineDefs
EXPORTS TexTableDefs =
BEGIN OPEN TexDefs,TexTableDefs;

InitChTypes: PROCEDURE =
BEGIN OPEN TexIODefs;
c: Char;
FOR c IN Char DO SetChType[c,otherchar] ENDLOOP;
FOR c IN[’A..’Z] DO SetChType[c,letter] ENDLOOP;
FOR c IN[’a..’z] DO SetChType[c,letter] ENDLOOP;
SetChType[0C,ignore]; -- NUL
SetChType[LF,ignore]; -- LF
SetChType[177C,ignore]; -- DEL
SetChType[11C,spacer]; SetChType[SP,spacer]; -- TAB and SP
SetChType[FF,carret]; SetChType[CR,carret]; -- FF and CR
END;

InitBasicChTypes: PROCEDURE =
BEGIN
-- Codes from \input basic (for debugging)
SetChType[’{,lbrace]; -- {
SetChType[’},rbrace]; -- }
SetChType[176C,rbrace]; -- } (SUAI)
SetChType[’$,mathbr]; -- $
SetChType[26C,tabmrk]; -- –
SetChType[’%,carret]; -- %
SetChType[’#,macprm]; -- #
SetChType[’↑,supmrk]; -- ↑
SetChType[1C,submrk]; -- ̌END;

InitMModeCodes: PROCEDURE =
BEGIN
-- 000C to 007C
SetMModeCode[0C,[Bin,[sy,001C]]]; -- null (center-dot)
SetMModeCode[1C,[Rel,[sy,043C]]]; -- down
SetMModeCode[2C,[Ord,[it,013C]]]; -- alpha
SetMModeCode[3C,[Ord,[it,014C]]]; -- beta
SetMModeCode[4C,[Bin,[sy,136C]]]; -- meet
SetMModeCode[5C,[Ord,[sy,072C]]]; -- not
SetMModeCode[6C,[Ord,[it,017C]]]; -- epsilon
SetMModeCode[7C,[Ord,[it,031C]]]; -- pi
-- 010C to 017C
SetMModeCode[10C,[Ord,[it,025C]]]; -- lambda
SetMModeCode[11C,[Ord,[it,015C]]]; -- gamma
SetMModeCode[12C,[Ord,[it,016C]]]; -- delta
SetMModeCode[13C,[Op,[sy,163C]]]; -- integral
SetMModeCode[14C,[Bin,[sy,006C]]]; -- plus or minus
SetMModeCode[15C,[Bin,[sy,010C]]]; -- circle plus
SetMModeCode[16C,[Ord,[sy,061C]]]; -- infinity
SetMModeCode[17C,[Ord,[it,045C]]]; -- partial
-- 020C to 027C
SetMModeCode[20C,[Rel,[sy,032C]]]; -- contained in
SetMModeCode[21C,[Rel,[sy,033C]]]; -- contains
SetMModeCode[22C,[Bin,[sy,134C]]]; -- cap
SetMModeCode[23C,[Bin,[sy,133C]]]; -- cup
SetMModeCode[24C,[Ord,[sy,070C]]]; -- for all
SetMModeCode[25C,[Ord,[sy,071C]]]; -- exists
SetMModeCode[26C,[Bin,[sy,012C]]]; -- circle times
SetMModeCode[27C,[Rel,[sy,044C]]]; -- dblarrow
-- 030C to 037C
SetMModeCode[30C,[Ord,[sy,065C]]]; -- underline
SetMModeCode[31C,[Rel,[sy,041C]]]; -- right
SetMModeCode[32C,[Rel,[sy,030C]]]; -- tilde
SetMModeCode[33C,[Rel,[sy,034C]]]; -- uneq
SetMModeCode[34C,[Rel,[sy,024C]]]; -- lseq
SetMModeCode[35C,[Rel,[sy,025C]]]; -- gteq
SetMModeCode[36C,[Rel,[sy,021C]]]; -- equiv
SetMModeCode[37C,[Bin,[sy,137C]]]; -- join
-- 040C to 047C
SetMModeCode[’ ,[Ord,[sy,63C]]]; -- space
SetMModeCode[’!,[Close,[rm,’!]]]; -- exc
SetMModeCode[’",[Ord,[sy,141C]]]; -- dblquotes
SetMModeCode[’#,[Ord,[sy,161C]]]; -- sharp
SetMModeCode[’$,[Ord,[sy,177C]]]; -- dollar
SetMModeCode[’%,[Ord,[rm,’%]]]; -- percent
SetMModeCode[’&,[Ord,[rm,’&]]]; -- ampersand
SetMModeCode[’’,[Close,[rm,’’]]]; -- apost
-- 050C to 057C
SetMModeCode[’(,[Open,[rm,’(]]]; -- left paren
SetMModeCode[’),[Close,[rm,’)]]]; -- right paren
SetMModeCode[’*,[Ord,[rm,’*]]]; -- astrsk
SetMModeCode[’+,[Bin,[rm,’+]]]; -- plus
SetMModeCode[’,,[Punct,[rm,’,]]]; -- comma
SetMModeCode[’-,[Bin,[sy,0C]]]; -- minus
SetMModeCode[’.,[Ord,[rm,’.]]]; -- period
SetMModeCode[’/,[Ord,[rm,’/]]]; -- slash
-- 060C to 067C
SetMModeCode[’0,[Ord,[rm,’0]]]; -- 0
SetMModeCode[’1,[Ord,[rm,’1]]]; -- 1
SetMModeCode[’2,[Ord,[rm,’2]]]; -- 2
SetMModeCode[’3,[Ord,[rm,’3]]]; -- 3
SetMModeCode[’4,[Ord,[rm,’4]]]; -- 4
SetMModeCode[’5,[Ord,[rm,’5]]]; -- 5
SetMModeCode[’6,[Ord,[rm,’6]]]; -- 6
SetMModeCode[’7,[Ord,[rm,’7]]]; -- 7
-- 070C to 077C
SetMModeCode[’8,[Ord,[rm,’8]]]; -- 8
SetMModeCode[’9,[Ord,[rm,’9]]]; -- 9
SetMModeCode[’:,[Ord,[rm,’:]]]; -- colon
SetMModeCode[’;,[Punct,[rm,’;]]]; -- semicolon
SetMModeCode[’<,[Rel,[rm,’<]]]; -- less
SetMModeCode[’=,[Rel,[rm,’=]]]; -- equal
SetMModeCode[’>,[Rel,[rm,’>]]]; -- greater
SetMModeCode[’?,[Close,[rm,’?]]]; -- query
-- 100C to 107C
SetMModeCode[’@,[Ord,[sy,174C]]]; -- at
SetMModeCode[’A,[Ord,[it,’A]]]; -- A
SetMModeCode[’B,[Ord,[it,’B]]]; -- B
SetMModeCode[’C,[Ord,[it,’C]]]; -- C
SetMModeCode[’D,[Ord,[it,’D]]]; -- D
SetMModeCode[’E,[Ord,[it,’E]]]; -- E
SetMModeCode[’F,[Ord,[it,’F]]]; -- F
SetMModeCode[’G,[Ord,[it,’G]]]; -- G
-- 110C to 117C
SetMModeCode[’H,[Ord,[it,’H]]]; -- H
SetMModeCode[’I,[Ord,[it,’I]]]; -- I
SetMModeCode[’J,[Ord,[it,’J]]]; -- J
SetMModeCode[’K,[Ord,[it,’K]]]; -- K
SetMModeCode[’L,[Ord,[it,’L]]]; -- L
SetMModeCode[’M,[Ord,[it,’M]]]; -- M
SetMModeCode[’N,[Ord,[it,’N]]]; -- N
SetMModeCode[’O,[Ord,[it,’O]]]; -- O
-- 120C to 127C
SetMModeCode[’P,[Ord,[it,’P]]]; -- P
SetMModeCode[’Q,[Ord,[it,’Q]]]; -- Q
SetMModeCode[’R,[Ord,[it,’R]]]; -- R
SetMModeCode[’S,[Ord,[it,’S]]]; -- S
SetMModeCode[’T,[Ord,[it,’T]]]; -- T
SetMModeCode[’U,[Ord,[it,’U]]]; -- U
SetMModeCode[’V,[Ord,[it,’V]]]; -- V
SetMModeCode[’W,[Ord,[it,’W]]]; -- W
-- 130C to 137C
SetMModeCode[’X,[Ord,[it,’X]]]; -- X
SetMModeCode[’Y,[Ord,[it,’Y]]]; -- Y
SetMModeCode[’Z,[Ord,[it,’Z]]]; -- Z
SetMModeCode[’[,[Open,[rm,133C]]]; -- left bracket
SetMModeCode[’\,[Bin,[sy,004C]]]; -- backslash
SetMModeCode[’],[Close,[rm,135C]]]; -- right bracket
SetMModeCode[’↑,[Rel,[sy,042C]]]; -- up
SetMModeCode[’←,[Rel,[sy,040C]]]; -- left
-- 140C to 147C
SetMModeCode[140C,[Open,[rm,140C]]]; -- rev apostrophe
SetMModeCode[’a,[Ord,[it,’a]]]; -- a
SetMModeCode[’b,[Ord,[it,’b]]]; -- b
SetMModeCode[’c,[Ord,[it,’c]]]; -- c
SetMModeCode[’d,[Ord,[it,’d]]]; -- d
SetMModeCode[’e,[Ord,[it,’e]]]; -- e
SetMModeCode[’f,[Ord,[it,’f]]]; -- f
SetMModeCode[’g,[Ord,[it,’g]]]; -- g
-- 150C to 157C
SetMModeCode[’h,[Ord,[it,’h]]]; -- h
SetMModeCode[’i,[Ord,[it,’i]]]; -- i
SetMModeCode[’j,[Ord,[it,’j]]]; -- j
SetMModeCode[’k,[Ord,[it,’k]]]; -- k
SetMModeCode[’l,[Ord,[it,’l]]]; -- l
SetMModeCode[’m,[Ord,[it,’m]]]; -- m
SetMModeCode[’n,[Ord,[it,’n]]]; -- n
SetMModeCode[’o,[Ord,[it,’o]]]; -- o
-- 160C to 167C
SetMModeCode[’p,[Ord,[it,’p]]]; -- p
SetMModeCode[’q,[Ord,[it,’q]]]; -- q
SetMModeCode[’r,[Ord,[it,’r]]]; -- r
SetMModeCode[’s,[Ord,[it,’s]]]; -- s
SetMModeCode[’t,[Ord,[it,’t]]]; -- t
SetMModeCode[’u,[Ord,[it,’u]]]; -- u
SetMModeCode[’v,[Ord,[it,’v]]]; -- v
SetMModeCode[’w,[Ord,[it,’w]]]; -- w
-- 170C to 177C
SetMModeCode[’x,[Ord,[it,’x]]]; -- x
SetMModeCode[’y,[Ord,[it,’y]]]; -- y
SetMModeCode[’z,[Ord,[it,’z]]]; -- z
SetMModeCode[’{,[Open,[sy,146C]]]; -- left brace
SetMModeCode[’|,[Ord,[sy,152C]]]; -- absolute
SetMModeCode[’},[Close,[sy,147C]]]; -- right brace
SetMModeCode[’~,[Close,[sy,147C]]]; -- tilde (also maps to right brace)
SetMModeCode[177C,[Bin,[rm,017C]]]; -- hat
END;

InitGlueParams: PROCEDURE =
BEGIN OPEN TexGlueDefs;
zeroglue: GluePtr←CommonGlue[zero];
g: GlueParamType;
FOR g IN GlueParamType DO SetGlueParam[g, zeroglue] ENDLOOP;
END;

defaultTracing: TraceInfo =
[boxitems: 5, boxlevel: 3,
showmacros: FALSE, showinput: FALSE, ddtstop: TRUE,
reportoverfull: TRUE, showpages: FALSE, ddtdump: TRUE];

InitTexParams: PROCEDURE =
BEGIN
SetTexParam[jpar,[jpar[penalty: 200]]];
SetTexParam[hpen,[hpen[penalty: 50]]];
SetTexParam[penpen,[penpen[penalty: 3000]]];
SetTexParam[wpen,[wpen[penalty: 80]]];
SetTexParam[bpen,[bpen[penalty: 50]]];
SetTexParam[mbpen,[mbpen[penalty: 95]]];
SetTexParam[mrpen,[mrpen[penalty: 50]]];
SetTexParam[disppen,[disppen[penalty: 500]]];
SetTexParam[ragged,[ragged[ragged: 0]]];
SetTexParam[tracing,[tracing[tracing: defaultTracing]]];
END;

InitHangIndent: PROCEDURE =
BEGIN
SetHangIndent[nullHang];
SetGlobalHangIndent[nullHang];
END;


InitDimnParams: PROCEDURE =
BEGIN
SetDimnParam[hsize, ThInches[4500]]; -- 4.5 inches
SetDimnParam[vsize, ThInches[7000]]; -- 7.0 inches
SetDimnParam[maxdepth, Pts[3]];
SetDimnParam[parindent, Pts[0]];
SetDimnParam[topbaseline, Pts[10]];
SetDimnParam[mathsurround, Pts[0]];
SetDimnParam[varunit, Pts[1]];
SetDimnParam[lineskiplimit, Pts[0]];
END;

-- convert thousandths of inches to micas
ThInches: PROCEDURE[h: CARDINAL] RETURNS[Dimn] =
BEGIN OPEN InlineDefs;
RETURN[LongDiv[LongMult[h,2540]+(1000/2),1000]];
END;

-- convert points to micas *** 72 isn’t quite right!
Pts: PROCEDURE[p: CARDINAL] RETURNS[Dimn] =
BEGIN OPEN InlineDefs;
RETURN[LongDiv[LongMult[p,2540]+(72/2),72]];
END;

InitKounts: PROCEDURE =
BEGIN
d: Digit;
FOR d IN Digit DO SetKount[d,0] ENDLOOP;
END;

InitSfTable: PROCEDURE =
BEGIN
c: Char;
FOR c IN Char DO SetSfTable[c,1000] ENDLOOP; -- default spacefactor is 1
SetSfTable[’),0];
SetSfTable[’’,0];
SetSfTable[’",0];
SetSfTable[’],0];
SetSfTable[’.,3000];
SetSfTable[’?,3000];
SetSfTable[’!,3000];
SetSfTable[’:,2000];
SetSfTable[’;,1500];
SetSfTable[’,,1250];
END;

InitDelimTable: PROCEDURE =
BEGIN OPEN TexMathDefs;
AddDelim: PROCEDURE[c: Char, sm,lg: MChar] = INLINE
BEGIN AddDelimiter[c,[[TRUE,sm],[TRUE,lg]]] END;
AddDelimiter[’.,nullDelimiter];
AddDelim[’(,[rm,050C],[ex,000C]];
AddDelim[’),[rm,051C],[ex,001C]];
AddDelim[’[,[rm,133C],[ex,002C]];
AddDelim[’],[rm,135C],[ex,003C]];
AddDelim[’<,[sy,150C],[ex,012C]];
AddDelim[’>,[sy,151C],[ex,013C]];
AddDelim[’|,[sy,152C],[ex,014C]];
AddDelim[’/,[rm,057C],[ex,016C]];
AddDelim[’{,[sy,146C],[ex,010C]];
AddDelim[’},[sy,147C],[ex,011C]];
AddDelim[176C,[sy,147C],[ex,011C]]; -- SUAI right brace
END;

InitChTypes;
InitBasicChTypes;
InitMModeCodes;
InitTexParams;
InitHangIndent;
InitGlueParams;
InitDimnParams;
InitKounts;
InitSfTable;
InitDelimTable;

FrameDefs.SelfDestruct;

END.