{-# LANGUAGE CPP, OverloadedStrings, TypeFamilies #-}
#if __GLASGOW_HASKELL__ >= 801
{-# OPTIONS_GHC -Wno-orphans #-}
#else
{-# OPTIONS_GHC -fno-warn-orphans #-}
#endif
module Text.LaTeX.Packages.AMSMath
(
amsmath
, math, mathDisplay
, equation , equation_
, align , align_
, cases
, eqref , nonumber
, autoParens
, autoSquareBrackets, autoBraces, autoAngleBrackets
, autoBrackets
, langle , rangle
, lfloor , rfloor
, lceil , rceil
, dblPipe
, (^:) , (!:), (!^)
, tsin , arcsin
, tcos , arccos
, ttan , arctan
, cot , arccot
, tsinh , tcosh , ttanh , coth
, sec , csc
, texp
, tlog , ln
, tsqrt
, operatorname
, tsum , sumFromTo
, prod , prodFromTo
, coprod, coprodFromTo
, integral , integralFromTo
, partial, totald, partialOf, totaldOf
, bigcup, bigcupFromTo
, bigcap, bigcapFromTo
, (+-), (-+)
, cdot , times , div_
, frac, tfrac
, (*:) , star
, circ , bullet
, (=:) , (/=:)
, (<:) , (<=:)
, (>:) , (>=:)
, ll , gg
, equiv
, propto
, parallel
, perp
, approx
, sim
, simeq
, cong
, in_ , ni , notin
, subset , supset
, subseteq , supseteq
, cap , cup
, setminus
, vee , wedge
, oplus , ominus , otimes
, oslash , odot
, hat, tilde, bar, vec, widehat, widetilde
, dot, ddot, dddot
, overline
, alpha , beta , gamma
, gammau , delta , deltau
, epsilon , varepsilon , zeta
, eta , theta , vartheta , thetau
, iota , kappa , lambda
, lambdau , mu , nu
, xi , xiu , pi_
, varpi , piu , rho
, varrho , sigma , varsigma
, sigmau , tau , upsilon
, upsilonu , phi , varphi
, phiu , chi , psi
, psiu , omega , omegau
, pm , mp
, to , mapsto, implies
, forall , exists
, dagger, ddagger
, infty
, imath, jmath
, bot
, mathdefault
, mathbf
, mathrm
, text
, mathcal
, mathsf
, mathtt
, mathit
, pmatrix , bmatrix
, b2matrix , vmatrix
, v2matrix
, quad, qquad
, thinspace, medspace, thickspace, negspace, space
) where
import Text.LaTeX.Base
import Text.LaTeX.Base.Syntax
import Text.LaTeX.Base.Class
import Data.List
import Data.Ratio
import Data.Matrix
amsmath :: PackageName
amsmath = "amsmath"
eqref :: LaTeXC l => l -> l
eqref = liftL $ \l -> TeXComm "eqref" [FixArg . TeXRaw $ render l]
align :: LaTeXC l => [l] -> l
align = liftL(TeXEnv "align" []) . mconcat . intersperse lnbk
align_ :: LaTeXC l => [l] -> l
align_ = liftL(TeXEnv "align*" []) . mconcat . intersperse lnbk
cases :: LaTeXC l => l -> l
cases = liftL $ TeXEnv "cases" []
tfrac :: LaTeXC l => l -> l -> l
tfrac = liftL2 $ \p q -> TeXComm "tfrac" [FixArg p, FixArg q]
ddot :: LaTeXC l => l -> l
ddot = comm1 "ddot"
dddot :: LaTeXC l => l -> l
dddot = comm1 "dddot"
text :: LaTeXC l => l -> l
text = comm1 "text"
matrix2tex :: (Texy a, LaTeXC l) => Matrix a -> l
matrix2tex m = mconcat
[ foldr1 (&) [ texy $ m ! (i,j)
| j <- [1 .. ncols m]
] <> lnbk
| i <- [1 .. nrows m]
]
toMatrix :: (Texy a, LaTeXC l) => String -> Maybe HPos -> Matrix a -> l
toMatrix str Nothing = liftL (TeXEnv str []) . matrix2tex
toMatrix str (Just p) = liftL (TeXEnv (str ++ "*") [OptArg $ rendertex p]) . matrix2tex
pmatrix :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l
pmatrix = toMatrix "pmatrix"
bmatrix :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l
bmatrix = toMatrix "bmatrix"
b2matrix :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l
b2matrix = toMatrix "Bmatrix"
vmatrix :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l
vmatrix = toMatrix "vmatrix"
v2matrix :: (Texy a, LaTeXC l) => Maybe HPos -> Matrix a -> l
v2matrix = toMatrix "Vmatrix"
#if MIN_VERSION_base(4,9,0)
instance Texy a => Texy (Ratio a) where
#else
instance (Integral a, Texy a) => Texy (Ratio a) where
#endif
texy x = frac (texy $ numerator x) (texy $ denominator x)
instance (Texy a, Texy b) => Texy (a,b) where
texy (x,y) = autoParens $ texy x <> "," <> texy y
instance (Texy a, Texy b, Texy c) => Texy (a,b,c) where
texy (x,y,z) = autoParens $ texy x <> "," <> texy y <> "," <> texy z
instance (Texy a, Texy b, Texy c, Texy d) => Texy (a,b,c,d) where
texy (a,b,c,d) = autoParens $ texy a <> "," <> texy b <> "," <> texy c <> "," <> texy d
instance Texy a => Texy (Matrix a) where
texy = pmatrix Nothing
instance Texy a => Texy [a] where
texy = autoSquareBrackets . mconcat . intersperse "," . fmap texy
thinspace :: LaTeXC l => l
thinspace = comm0 ","
medspace :: LaTeXC l => l
medspace = comm0 ":"
thickspace :: LaTeXC l => l
thickspace = comm0 ";"
negspace :: LaTeXC l => l
negspace = comm0 "!"
space :: LaTeXC l => l
space = comm0 " "