#include txt.cam #include seq.cam ;N tex.cam - a CAMILA abstract syntax for a LaTeX subset ;A J.N. Oliveira (jno@di.uminho.pt) ;D ; This library provides for LaTeX outputs, which can be written to ; files via txt.cam. ; Only a (very!) tiny subset of LaTeX is considered. ; Last Update: 1999.11.11 ;E TYPE TeX = TeXObj-seq ; TeXObj = TeXCmd | TeXTabRow | STR ; TeXCmd :: O: STR A: TeXArg-seq ; TeXTabRow :: R: TeXArg-seq ; TeXArg = STR | INT | TeXCmd | Opt | TeX ; Opt :: A: TeXArg; ENDTYPE FUNC texDef(m:STR,l:TeX):TeXCmd ; ; texDef(m,l) emulates the TeX def command. ; RETURN TeXCmd("def\\"++m,l); FUNC texNDef(n:INT,m:STR,l:TeX):TeXCmd ; ; texDef(n,m,l) emulates the TeX def command with n-parameters ; RETURN let (s=strCAT((lambda(n)."#"++itoa(n))-seq(seqInseg(n)))) in TeXCmd("def\\"++m++s,l); FUNC texGdef(m:STR,l:TeX):TeXCmd ; ; texGdef(m,l) emulates the TeX global def command. ; RETURN TeXCmd(strcat("gdef\\",m),l); FUNC texLdef(m:STR,l:TeX):TeXCmd ; ; texLdef(m,l) emulates the TeX long def command. ; RETURN TeXCmd(strcat("long\\def\\",m),l); FUNC texCons(c:STR):TeXCmd ; ; texCons(c) generates TeX constant macro c. ; RETURN TeXCmd(c,<>); FUNC texDefMap(ff:STR->STR):TeX ; ; texDefMap(ff) scales texDef up to collection of macro definitions. ; RETURN < texDef(a,) | a <- dom(ff) >; FUNC texTeX2txt(l:TeX): txt ; ; texTeX2txt(l:TeX) converts TeX object l into txt-embedded concrete ; syntax. ; RETURN CONC(< (if is-STR(c) then else if is-TeXCmd(c) then texTeXCmd2txt(c) else texTeXTabRow2txt(c)) ^ <"\n"> | c <- l >); FUNC texTeXTabRow2txt(x:TeXTabRow): txt ; ; texTeXTabRow2txt(x) converts TeXTabRow object x into txt-embedded ; concrete syntax. ; RETURN CONC(seqAddSep(< texTeXArg2txt(c) | c <- R(x) >, <"&">)); FUNC texTeXArg2txt(x:TeXArg): txt ; ; texTeXArg2txt(x) converts TeXArg object x into txt embedded ; concrete syntax. ; RETURN (if is-STR(x) then < x > else if is-INT(x) then < itoa(x) > else if is-TeXCmd(x) then texTeXCmd2txt(x) else texTeX2txt(x)); FUNC texTeXCmd2txt(c:TeXCmd): txt ; ; texTeXCmd2txt(c) converts TeXCmd object c into txt embedded ; concrete syntax. ; RETURN let (o=O(c), l=A(c)) in < strcat("\\",o) > ^ CONC(< if is-Opt(x) then <"[">^texTeXArg2txt(A(x))^<"]"> else <"{">^texTeXArg2txt(x)^<"}"> | x <- l >);