{- |
Module      : Language.Egison.MathOutput
Licence     : MIT

This module provides translation from mathematical Egison expression into
other languages / format of other computer algebra systems.
-}

module Language.Egison.MathOutput
  ( prettyMath
  ) where

import           Language.Egison.Data
import           Language.Egison.PrettyMath.AST
import qualified Language.Egison.PrettyMath.AsciiMath   as AsciiMath
import qualified Language.Egison.PrettyMath.Latex       as Latex
import qualified Language.Egison.PrettyMath.Mathematica as Mathematica
import qualified Language.Egison.PrettyMath.Maxima      as Maxima

prettyMath :: String -> EgisonValue -> String
prettyMath :: String -> EgisonValue -> String
prettyMath String
lang EgisonValue
val =
  -- 'lang' is either "asciimath", "latex", "mathematica" or "maxima"
  -- Other invalid options are rejected in Interpreter/egison.hs
  case String -> MathExpr -> String
showMathExpr String
lang (EgisonValue -> MathExpr
forall a. ToMathExpr a => a -> MathExpr
toMathExpr EgisonValue
val) of
    String
"undefined" -> String
"undefined"
    String
output      -> String
"#" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
lang String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"|" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
output String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"|#"

showMathExpr :: String -> MathExpr -> String
showMathExpr :: String -> MathExpr -> String
showMathExpr String
"asciimath"   = MathExpr -> String
AsciiMath.showMathExpr
showMathExpr String
"latex"       = MathExpr -> String
Latex.showMathExpr
showMathExpr String
"mathematica" = MathExpr -> String
Mathematica.showMathExpr
showMathExpr String
"maxima"      = MathExpr -> String
Maxima.showMathExpr
showMathExpr String
"haskell"     = MathExpr -> String
forall a. Show a => a -> String
show
showMathExpr String
_             = String -> MathExpr -> String
forall a. HasCallStack => String -> a
error String
"Unreachable"