Text.TeXMath

texmath-0.8.5: Conversion between formats used to represent mathematics.

Safe Haskell | None
Language | Haskell2010

Text.TeXMath

Description

Functions for converting between different representations of mathematical formulas.

Also note that in general `writeLaTeX . readLaTeX /= id`.

A typical use is to combine together a reader and writer.

    import Control.Applicative ((<$>))
    import Text.TeXMath (writeMathML, readTeX)

    texMathToMathML :: DisplayType -> String -> Either String Element
    texMathToMathML dt s = writeMathML dt <$> readTeX s

It is also possible to manipulate the AST using `Generics`. For example, if you wanted to replace all occurences of the identifier x in your expression, you do could do so with the following script.

    import Control.Applicative ((<$>))
    import Data.Generics (everywhere, mkT)
    import Text.TeXMath (writeMathML, readTeX)
    import Text.TeXMath.Types
    import Text.XML.Light (Element)

    changeIdent :: Exp -> Exp
    changeIdent (EIdentifier "x") = EIdentifier "y"
    changeIdent e = e

    texToMMLWithChangeIdent :: DisplayType -> String -> Either String Element
    texToMMLWithChangeIdent dt s =
      writeMathML dt . everywhere (mkT changeIdent) <$> readTeX s

Synopsis

- readMathML :: String -> Either String [Exp]
- readOMML :: String -> Either String [Exp]
- readTeX :: String -> Either String [Exp]
- writeTeX :: [Exp] -> String
- writeTeXWith :: Env -> [Exp] -> String
- addLaTeXEnvironment :: DisplayType -> String -> String
- writeOMML :: DisplayType -> [Exp] -> Element
- writeMathML :: DisplayType -> [Exp] -> Element
- writePandoc :: DisplayType -> [Exp] -> Maybe [Inline]
- data DisplayType
  - = DisplayBlock
  - | DisplayInline
- data Exp

# Documentation

readMathML :: String -> Either String [Exp]

Parse a MathML expression to a list of `Exp`.

readOMML :: String -> Either String [Exp]

readTeX :: String -> Either String [Exp]

Parse a formula, returning a list of `Exp`.

writeTeX :: [Exp] -> String

Transforms an expression tree to equivalent LaTeX with the default packages (amsmath and amssymb)

writeTeXWith :: Env -> [Exp] -> String

Transforms an expression tree to equivalent LaTeX with the specified packages

addLaTeXEnvironment :: DisplayType -> String -> String

Adds the correct LaTeX environment around a TeXMath fragment

writeOMML :: DisplayType -> [Exp] -> Element

Transforms an expression tree to an OMML XML Tree

writeMathML :: DisplayType -> [Exp] -> Element

Transforms an expression tree to a MathML XML tree

writePandoc :: DisplayType -> [Exp] -> Maybe [Inline]

Attempts to convert a formula to a list of `Pandoc` inlines.

data DisplayType

Constructors

DisplayBlock | A displayed formula.
DisplayInline | A formula rendered inline in text.

Instances

Eq DisplayType |
Show DisplayType |

data Exp

Instances

Eq Exp |
Data Exp |
Read Exp |
Show Exp |