texmath-0.13.1.2: Conversion between math formats.

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 Data.Text (Text)
    import Text.TeXMath (writeMathML, readTeX)

    texMathToMathML :: DisplayType -> Text -> Either Text 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.

    {-# LANGUAGE OverloadedStrings -#}

    import Control.Applicative ((<$>))
    import Data.Text (Text)
    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 -> Text -> Either Text Element
    texToMMLWithChangeIdent dt s =
      writeMathML dt . everywhere (mkT changeIdent) <$> readTeX s

Synopsis

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

# Documentation

readMathML :: Text -> Either Text [Exp] Source #

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

readOMML :: Text -> Either Text [Exp] Source #

readTeX :: Text -> Either Text [Exp] Source #

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

writeTeX :: [Exp] -> Text Source #

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

writeTeXWith :: Env -> [Exp] -> Text Source #

Transforms an expression tree to equivalent LaTeX with the specified packages

addLaTeXEnvironment :: DisplayType -> Text -> Text Source #

Adds the correct LaTeX environment around a TeXMath fragment

writeEqn :: DisplayType -> [Exp] -> Text Source #

Transforms an expression tree to equivalent Eqn

writeTypst :: DisplayType -> [Exp] -> Text Source #

Transforms an expression tree to equivalent Typst

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

Transforms an expression tree to an OMML XML Tree

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

Transforms an expression tree to a MathML XML tree

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

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

data DisplayType Source #

Constructors

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

#### Instances

Instances details

Show DisplayType Source # |
Instance details Defined in Text.TeXMath.Types Methods showsPrec :: Int -> DisplayType -> ShowS Source # show :: DisplayType -> String Source # showList :: [DisplayType] -> ShowS Source #
Eq DisplayType Source # |
Instance details Defined in Text.TeXMath.Types Methods (==) :: DisplayType -> DisplayType -> Bool Source # (/=) :: DisplayType -> DisplayType -> Bool Source #
Ord DisplayType Source # |

Instance details

Defined in Text.TeXMath.Types

Methods

compare :: DisplayType -> DisplayType -> Ordering Source #

(<) :: DisplayType -> DisplayType -> Bool Source #

(<=) :: DisplayType -> DisplayType -> Bool Source #

(>) :: DisplayType -> DisplayType -> Bool Source #

(>=) :: DisplayType -> DisplayType -> Bool Source #

max :: DisplayType -> DisplayType -> DisplayType Source #

min :: DisplayType -> DisplayType -> DisplayType Source #

data Exp Source #

#### Instances

Instances details

Data Exp Source # |

Instance details

Defined in Text.TeXMath.Types

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Exp -> c Exp Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Exp Source #

toConstr :: Exp -> Constr Source #

dataTypeOf :: Exp -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Exp) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Exp) Source #

gmapT :: (forall b. Data b => b -> b) -> Exp -> Exp Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Exp -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Exp -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Exp -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Exp -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Exp -> m Exp Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Exp -> m Exp Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Exp -> m Exp Source #

Read Exp Source # |
Instance details Defined in Text.TeXMath.Types Methods readsPrec :: Int -> ReadS Exp Source # readList :: ReadS [Exp] Source # readPrec :: ReadPrec Exp Source # readListPrec :: ReadPrec [Exp] Source #
Show Exp Source # |
Instance details Defined in Text.TeXMath.Types Methods showsPrec :: Int -> Exp -> ShowS Source # show :: Exp -> String Source # showList :: [Exp] -> ShowS Source #
Eq Exp Source # |
Instance details Defined in Text.TeXMath.Types Methods (==) :: Exp -> Exp -> Bool Source # (/=) :: Exp -> Exp -> Bool Source #
Ord Exp Source # |
Instance details Defined in Text.TeXMath.Types Methods compare :: Exp -> Exp -> Ordering Source # (<) :: Exp -> Exp -> Bool Source # (<=) :: Exp -> Exp -> Bool Source # (>) :: Exp -> Exp -> Bool Source # (>=) :: Exp -> Exp -> Bool Source # max :: Exp -> Exp -> Exp Source # min :: Exp -> Exp -> Exp Source #