picolisp

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/picolisp.git/
Log | Files | Refs | README | LICENSE

tex.l (3453B)


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