@@ -8,20 +8,19 @@ This module provides utility functions.
8
8
9
9
module Language.Egison.MathOutput (mathExprToHaskell , mathExprToAsciiMath , mathExprToLatex , mathExprToMathematica ) where
10
10
11
- import Data.List (intercalate )
12
11
import Control.Monad
13
12
import System.Environment
14
13
import Text.ParserCombinators.Parsec hiding (spaces )
15
14
16
15
mathExprToHaskell :: String -> String
17
16
mathExprToHaskell input = case parse parseExpr " math-expr" input of
18
17
Left err -> input
19
- Right val -> " #haskell\" " ++ show val ++ " \" "
18
+ Right val -> " #haskell| " ++ show val ++ " |# "
20
19
21
20
mathExprToAsciiMath :: String -> String
22
21
mathExprToAsciiMath input = case parse parseExpr " math-expr" input of
23
22
Left err -> input
24
- Right val -> " #asciimath\" " ++ showMathExprAsciiMath val ++ " \" "
23
+ Right val -> " #asciimath| " ++ showMathExprAsciiMath val ++ " |# "
25
24
26
25
mathExprToLatex :: String -> String
27
26
mathExprToLatex input = case parse parseExpr " math-expr" input of
@@ -132,6 +131,7 @@ showMathExprLatex (Plus (x:xs)) = showMathExprLatex x ++ showMathExprLatexForPlu
132
131
showMathExprLatexForPlus :: [MathExpr ] -> String
133
132
showMathExprLatexForPlus [] = " "
134
133
showMathExprLatexForPlus ((NegativeAtom a): xs) = " - " ++ a ++ showMathExprLatexForPlus xs
134
+ showMathExprLatexForPlus ((Multiply (NegativeAtom " 1" : ys)): xs) = " - " ++ showMathExprLatex (Multiply ys) ++ showMathExprLatexForPlus xs
135
135
showMathExprLatexForPlus ((Multiply (NegativeAtom a: ys)): xs) = " - " ++ showMathExprLatex (Multiply ((Atom a [] ): ys)) ++ showMathExprLatexForPlus xs
136
136
showMathExprLatexForPlus (x: xs) = " + " ++ showMathExprLatex x ++ showMathExprLatexForPlus xs
137
137
showMathExprLatex (Multiply [] ) = " "
@@ -195,6 +195,7 @@ showMathExprMathematica (Plus (x:xs)) = showMathExprMathematica x ++ showMathExp
195
195
showMathExprMathematicaForPlus :: [MathExpr ] -> String
196
196
showMathExprMathematicaForPlus [] = " "
197
197
showMathExprMathematicaForPlus ((NegativeAtom a): xs) = " - " ++ a ++ showMathExprMathematicaForPlus xs
198
+ showMathExprMathematicaForPlus ((Multiply (NegativeAtom " 1" : ys)): xs) = " - " ++ showMathExprMathematica (Multiply ys) ++ showMathExprMathematicaForPlus xs
198
199
showMathExprMathematicaForPlus ((Multiply (NegativeAtom a: ys)): xs) = " - " ++ showMathExprMathematica (Multiply ((Atom a [] ): ys)) ++ showMathExprMathematicaForPlus xs
199
200
showMathExprMathematicaForPlus (x: xs) = " + " ++ showMathExprMathematica x ++ showMathExprMathematicaForPlus xs
200
201
showMathExprMathematica (Multiply [] ) = " "
0 commit comments