From d8297fec19292c544a32a474500eca49552215d0 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 6 Jun 2016 23:00:42 +0200 Subject: LaTeX formatting for derivation trees --- LaTeX.icl | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 LaTeX.icl (limited to 'LaTeX.icl') 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{}") + , ("&", "\\&{}") + ] -- cgit v1.2.3