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{}") , ("&", "\\&{}") ]