1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
# 29jul11abu
# (c) Software Lab. Alexander Burger
# Convert to PDF document
(de dviPdf (Doc)
(prog1
(tmp Doc ".pdf")
(call "/usr/bin/dvips" "-q" (pack Doc ".dvi"))
(call "ps2pdf" (pack Doc ".ps") @)
(call 'rm "-f"
(pack Doc ".tex")
(pack Doc ".dvi")
(pack Doc ".ps") ) ) )
# Tex Formatting
(de tex (S . @)
(prin "\\" (or S (next)))
(when (args)
(prin "{")
(texPrin (next))
(while (args)
(when (next)
(prin "\\\\")
(texPrin (arg)) ) )
(prin "}") )
(and S (prinl)) )
(de texl (S . @)
(prin "\\" (or S (next)) "{")
(loop
(let Lst (next)
(texPrin (pop 'Lst))
(while Lst
(when (pop 'Lst)
(prin "\\\\")
(texPrin @) ) ) )
(NIL (args))
(prin (next)) )
(prin "}")
(and S (prinl)) )
(de texPrin (X)
(let Q NIL
(for C (chop X)
(cond
((sub? C "#$%&_{}")
(prin "\\" C) )
((sub? C "<²>")
(prin "$" C "$") )
(T
(prin
(case C
(`(char 8364) "\\EUR")
("\"" (if (onOff Q) "``" "''"))
("\\" "$\\backslash$")
("\^" "\\char94")
("~" "\\char126")
(T C) ) ) ) ) ) ) )
### TeX Document ###
(de document (Doc Cls Typ Use . Prg)
(out (list "@bin/lat1" (pack Doc ".tex"))
(prinl "\\documentclass[" Cls "]{" Typ "}")
(while Use
(if (atom (car Use))
(prinl "\\usepackage{" (pop 'Use) "}")
(prinl "\\usepackage[" (caar Use) "]{" (cdr (pop 'Use)) "}") ) )
(prinl "\\begin{document}")
(prEval Prg 2)
(prinl "\\end{document}") )
(call 'sh "-c"
(pack "latex -interaction=batchmode " Doc ".tex >/dev/null") )
(call 'rm (pack Doc ".aux") (pack Doc ".log")) )
(de \\block (S . Prg)
(prinl "\\begin{" S "}")
(prEval Prg 2)
(prinl "\\end{" S "}") )
(de \\figure (S . Prg)
(prinl "\\begin{figure}" S)
(prEval Prg 2)
(prinl "\\end{figure}") )
### Tabular environment ###
(de \\table (Fmt . Prg)
(prinl "\\begin{tabular}[c]{" Fmt "}")
(prEval Prg 2)
(prinl "\\end{tabular}") )
(de \\carry ()
(prinl "\\end{tabular}")
(prinl)
(prinl "\\begin{tabular}[c]{" "Fmt" "}") )
(de \\head @
(prin "\\textbf{" (next) "}")
(while (args)
(prin " & \\textbf{")
(texPrin (next))
(prin "}") )
(prinl "\\\\") )
(de \\row @
(when (=0 (next))
(next)
(prin "\\raggedleft ") )
(ifn (=T (arg))
(texPrin (arg))
(prin "\\textbf{")
(texPrin (next))
(prin "}") )
(while (args)
(prin " & ")
(when (=0 (next))
(next)
(prin "\\raggedleft ") )
(ifn (=T (arg))
(texPrin (arg))
(prin "\\textbf{")
(texPrin (next))
(prin "}") ) )
(prinl "\\\\") )
(de \\hline ()
(prinl "\\hline") )
(de \\cline (C1 C2)
(prinl "\\cline{" C1 "-" C2 "}") )
### Letter Document Class ###
(de \\letter (Lst . Prg)
(prin "\\begin{letter}{" (pop 'Lst))
(while Lst
(when (pop 'Lst)
(prin "\\\\" @) ) )
(prinl "}")
(prEval Prg 2)
(prinl "\\end{letter}") )
(de \\signature (S)
(tex "signature" S) )
(de \\opening (S)
(tex "opening" S) )
(de \\closing (S)
(tex "closing" S) )
|