add unused sources
[wix.git] / src / unused / Latex.hs
1 module Latex where
2 import Data.Array.IArray
3 import Data.Char
4 import Util
5 import Lexer
6 import IR
7 import Data.List
8 import Beautify
9
10 toLatex ll = prefix ++ (concatMap tl ll) ++ suffix
11  where
12   packages                         = [ "{ulem}",
13                                        "{parskip}",
14                                        "{wrapfig}",
15                                        "{fancyvrb}",
16                                        "{color}",
17                                        "{palatino}",
18                                        "{parskip}",
19                                        "{multicol}",
20                                        "{sectsty}",
21                                        "[colorlinks=true,urlcolor=blue,linkcolor=blue,bookmarks=true]{hyperref}" ]
22   prefix                           = "\n\\documentclass{article}\n" ++ 
23                                      "\\usepackage{mathptmx}" ++
24                                      "\\author{BluePixel, Inc\\\\ {\\footnotesize\\bf proprietary/confidential}}" ++
25                                      "\\usepackage{sectsty}" ++
26                                      (concatMap (\x -> "\\usepackage"++x++"\n") packages) ++
27                                      "\\usepackage{amstext}\n" ++
28                                      "\\usepackage[small]{titlesec}\n" ++
29                                      "\\titlespacing{\\section}{0pt}{\\baselineskip}{\\baselineskip}\n" ++
30                                      "\\titlespacing{\\subsection}{0pt}{\\baselineskip}{0pt}\n" ++
31                                      "\\renewcommand{\\ttdefault}{cmtt}\n" ++
32 {-
33                                      "\\allsectionsfont{\\sffamily}\n" ++
34                                      "\\sectionfont{\\color{black}\\leftskip=-2cm\\hrulefill\\\\"++
35                                         "\\sffamily\\bfseries\\raggedleft\\vspace{1cm}}\n" ++
36                                      "\\subsectionfont{\\color{black}\\dotfill\\\\\\sffamily\\raggedright\\hspace{ -4cm}}\n" ++
37                                      "\\newdimen\\sectskip\n" ++
38                                      "\\newdimen\\subsectskip\n" ++
39                                      "\\newdimen\\saveskip\n" ++
40                                      "\\saveskip=\\leftskip\n" ++
41                                      "\\sectskip=-2cm\n" ++
42                                      "\\subsectskip=0cm\n" ++
43                                      "\\let\\oldsection\\section\n" ++
44                                      "\\let\\oldsubsection\\subsection\n" ++
45                                      "\\def\\subsection#1{\\leftskip=\\sectskip\\oldsubsection{#1}\\leftskip=0cm}\n" ++
46 -}
47                                      "\\sectionfont{\\sffamily\\bfseries\\large}" ++
48                                      "\\def\\sec#1{\\vspace{0.6cm}\\parbox{\\columnwidth}{\\hspace{-0.5cm}\\hrulefill\\vspace{-0.3cm}\\section*{\\hspace{-0.35cm}#1}}}" ++
49                                      "\\def\\ninept{\\def\\baselinestretch{.95}\\let\\normalsize\\small\\normalsize}\n" ++
50 --                                     "\\ninept\n" ++
51                                      "\\sloppy\n" ++
52                                      "\\definecolor{CodeBorder}{rgb}{0.6,0.6,0.6}\n" ++
53                                      "\\definecolor{CodeBackground}{rgb}{0.93,0.93,0.93}\n" ++
54
55                                      "\\raggedbottom\n" ++
56                                      "\\VerbatimFootnotes\n" ++
57                                      "\\parindent 0pt\n" ++
58
59                                      "\\begin{document}\n"
60
61   suffix                           = "\n\\end{document}\n\\end\n"
62   addItem i                        = "\\item " ++ (striptrail $ boost 8 $ wrap $ striplead $ tl i)
63   escapify s                       = s
64   escapeMath s                     = s
65   tl (Special _ BulletList l)      = "\\begin{itemize}\n" ++ (concatMap addItem l) ++ "\\end{itemize}\n"
66   tl (Special _ NumberList l)      = "\\begin{enumerate}\n" ++ (concatMap addItem l) ++ "\\end{enumerate}\n"
67   tl (Special _ Section (h:t))     = "\n\n\\hypertarget{"++(tl h)++"}{\\sec{"++(tl h)++"}}\n"++(concatMap tl t)
68   tl (Special _ NumberedSection (h:t)) = "\n\n\\hypertarget{"++(tl h)++"}{\\section{"++(tl h)++"}}\n"++(concatMap tl t)
69   tl (Special _ (Glyph EmDash) []) = "{\\emdash}"
70 --tl (Special _ Superscript l)     = 
71 --tl (Special _ Subscript l)       = 
72 --tl (Special _ (Image u) l)       = 
73 --tl (Special _ (Cite u) l)        = 
74   tl (Special _ BlockQuote l)      = "\n\n\\begin{quote}\n     "++
75                                      (striptrail $ boost 4 $ wrap $ striplead $ concatMap tl l)++"\n\\end{quote}\n\n"
76   tl (Special _ HorizontalRule []) = "\\\\\\rule{4in}{0.5pt}\\\\"
77   tl (Special _ Italic l)          = "\\textit{"++(concatMap tl l)++"}"
78   tl (Special _ Bold l)            = "\\textbf{"++(concatMap tl l)++"}"
79   tl (Special _ Typewriter l)      = "\\texttt{"++(concatMap tl l)++"}"
80   tl (Special _ StrikeThrough l)   = "\\sout{"++(concatMap tl l)++"}"
81   tl (Special _ Quotes l)          = "``"++(concatMap tl l)++"''"
82   tl (Special _ Underline l)       = "\\uline{"++(concatMap tl l)++"}"
83   tl (Special _ Underline2 l)      = "\\uuline{"++(concatMap tl l)++"}"
84   tl (Special _ (Math s) [])       = "$" ++ (escapeMath s) ++ "$"
85   tl (Special _ Footnote l)        = "\\footnote{"++(concatMap tl l)++"}"
86   tl (Special _ Float l)           = "\n\n\\begin{wrapfigure}{r}{0.4\\textwidth} \\framebox[0.4\\textwidth]{"++
87                                      (concatMap tl l)++"} \\label{x}\\end{wrapfigure}\n\n"
88   tl (Special _ (Link u) l)        = "\\href{"++(escapify u)++"}{"++(concatMap tl l)++"}"
89   tl (Special _ (Verbatim s) [])   = "\\begin{Verbatim}[gobble=4,formatcom=\\color{red},frame=single,"++
90                                      "framesep=5mm,numbers=left,firstnumber=100]\n    " ++ (boost 4 s) ++ "\\end{Verbatim}\n"
91 --  tl (Special _ TwoColumn l)       = "\\begin{multicols}{2}\n"++(concatMap tl l)++"\n\\end{multicol}"
92 --  tl (Special _ Title l)           = "\\title{"++(concatMap tl l)++"}\n\\maketitle\n\n\n"
93   tl (Special _ (Command c) l)     = "\\"++c++"{"++(concatMap tl l)++"}"
94   tl (Special _ t l)               = error $ "formatting code "++(show t)++" not supported on {"++(concatMap show l)++"})"
95   tl (WS _)                        = " "
96   tl (BlankLine _)                 = "\n\n"
97   tl (Block _ l)                   = concatMap tl l
98   tl (Letter _ c)                  = escapify [c]
99   tl z                             = (show z)
100
101