aboutsummaryrefslogtreecommitdiff
path: root/LaTeX.icl
diff options
context:
space:
mode:
Diffstat (limited to 'LaTeX.icl')
-rw-r--r--LaTeX.icl41
1 files changed, 41 insertions, 0 deletions
diff --git a/LaTeX.icl b/LaTeX.icl
new file mode 100644
index 0000000..fba573e
--- /dev/null
+++ b/LaTeX.icl
@@ -0,0 +1,41 @@
+implementation module LaTeX
+
+from StdFunc import seq
+from StdList import ++, map
+from StdOverloaded import class toString(..), class +++(..)
+from StdString import instance +++ {#Char}
+
+from Text import class Text(replaceSubString,concat), instance Text String
+
+instance toString [a] | toString a
+where toString xs = concat (map toString xs)
+
+instance toString LaTeX
+where
+ toString (Command "justifies" []) = "\n\\justifies{}"
+ toString (Command cmd lts) = "\\" +++ cmd +++
+ concat ["{" +++ toString lt +++ "}" \\ lt <- lts]
+ toString (Environment env lt) = toString
+ ([Command "begin" [Text env]] ++ lt ++ [Command "env" [Text env]])
+ toString (Math True lt) = "$$" +++ toString lt +++ "$$"
+ toString (Math False lt) = "$" +++ toString lt +++ "$"
+ toString (List lts) = concat (map toString lts)
+ toString (Raw s) = s
+ toString (Text s) = escape s
+ where
+ escape :: !String -> String // From Text.LaTeX
+ escape s = seq (map (\(x,y) -> replaceSubString x y) escape`) s
+ where
+ escape` = [ ("\\", "\\textbackslash{}")
+ , ("^", "\\textasciicircum{}")
+ , ("~", "\\textasciitilde{}")
+ , ("*", "\\textasteriskcentered{}")
+ , ("|", "\\textbar{}")
+ , ("$", "\\textdollar{}")
+ , (">", "\\textgreater{}")
+ , ("<", "\\textless{}")
+ , ("\"", "\\textquotedblright{}")
+ , ("'", "\\textquoteright{}")
+ , ("_", "\\textunderscore{}")
+ , ("&", "\\&{}")
+ ]