module Text.LaTeX.Packages.AMSMath
(
amsmath
, math, mathDisplay
, equation , equation_
, align , align_
, 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
, tsum , sumFromTo
, prod , prodFromTo
, integral , integralFromTo
, pm , mp
, cdot , times , div_
, frac
, (*:) , star
, circ , bullet
, (=:) , (/=:)
, (<:) , (<=:)
, (>:) , (>=:)
, ll , gg
, equiv
, propto
, in_ , ni , notin
, subset , supset
, cap , cup
, setminus
, vee , wedge
, oplus , ominus , otimes
, oslash , odot
, 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
, to , mapsto
, forall , exists
, dagger, ddagger
, infty
, mathdefault
, mathbf
, mathrm
, mathcal
, mathsf
, mathtt
, mathit
, pmatrix , bmatrix
, b2matrix , vmatrix
, v2matrix
) 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"
math :: LaTeXC l => l -> l
math = liftL $ TeXMath Dollar
mathDisplay :: LaTeXC l => l -> l
mathDisplay = liftL $ TeXMath Square
instance Num LaTeX where
(+) = between "+"
() = between "-"
(*) = (<>)
negate = (TeXEmpty )
fromInteger = rendertex
abs = autoBrackets "|" "|"
signum _ = error "Cannot use \"signum\" Num method with a LaTeX value."
instance Fractional LaTeX where
(/) = frac
fromRational = rendertex . (fromRational :: Rational -> Double)
instance Floating LaTeX where
pi = pi_
exp = (texp <>)
sqrt = tsqrt Nothing
log = (tlog <>)
(**) = (^:)
logBase b x = (tlog !: b) <> x
sin = (tsin <>)
tan = (ttan <>)
cos = (tcos <>)
asin = (arcsin <>)
atan = (arctan <>)
acos = (arccos <>)
sinh = (tsinh <>)
tanh = (ttanh <>)
cosh = (tcosh <>)
asinh = error "Function 'asinh' is not defined in AMSMath!"
atanh = error "Function 'atabh' is not defined in AMSMath!"
acosh = error "Function 'acosh' is not defined in AMSMath!"
instance Eq (LaTeXT m a) where
_ == _ = error "Cannot use \"(==)\" Eq method with a LaTeXT value."
instance Show (LaTeXT m a) where
show _ = error "Cannot use \"show\" Show method with a LaTeXT value."
instance (Monad m, a ~ ()) => Num (LaTeXT m a) where
(+) = liftOp (+)
() = liftOp ()
(*) = (>>)
negate = liftFun negate
fromInteger = fromLaTeX . fromInteger
abs = liftFun abs
signum _ = error "Cannot use \"signum\" Num method with a LaTeXT value."
instance (Monad m, a ~ ()) => Fractional (LaTeXT m a) where
(/) = liftOp (/)
fromRational = fromLaTeX . fromRational
instance (Monad m, a ~ ()) => Floating (LaTeXT m a) where
pi = pi_
exp = liftFun exp
sqrt = liftFun sqrt
log = liftFun log
(**) = liftOp (**)
logBase = liftOp logBase
sin = liftFun sin
tan = liftFun tan
cos = liftFun cos
asin = liftFun asin
atan = liftFun atan
acos = liftFun acos
sinh = liftFun sinh
tanh = liftFun tanh
cosh = liftFun cosh
asinh = error "Function 'asinh' is not defined in AMSMath!"
atanh = error "Function 'atabh' is not defined in AMSMath!"
acosh = error "Function 'acosh' is not defined in AMSMath!"
eqref :: LaTeXC l => l -> l
eqref = liftL $ \l -> TeXComm "eqref" [FixArg . TeXRaw $ render l]
nonumber :: LaTeXC l => l
nonumber = comm0 "nonumber"
equation :: LaTeXC l => l -> l
equation = liftL $ TeXEnv "equation" []
equation_ :: LaTeXC l => l -> l
equation_ = liftL $ TeXEnv "equation*" []
align :: LaTeXC l => [l] -> l
align = liftL(TeXEnv "align" []) . mconcat . intersperse lnbk
align_ :: LaTeXC l => [l] -> l
align_ = liftL(TeXEnv "align*" []) . mconcat . intersperse lnbk
autoParens :: LaTeXC l => l -> l
autoParens x = commS "left(" <> x <> commS "right)"
autoSquareBrackets :: LaTeXC l => l -> l
autoSquareBrackets x = commS "left[" <> x <> commS "right]"
autoBraces :: LaTeXC l => l -> l
autoBraces x = commS "left"<>"{" <> x <> commS "right"<>"}"
autoAngleBrackets :: LaTeXC l => l -> l
autoAngleBrackets x = commS "left"<>langle <> x <> commS "right"<>rangle
autoBrackets :: LaTeXC l => LaTeX -> LaTeX -> l -> l
autoBrackets lBrack rBrack x
= commS "left" <> braces (fromLaTeX lBrack) <> x <> commS "right" <> braces (fromLaTeX rBrack)
langle :: LaTeXC l => l
langle = comm0 "langle"
rangle :: LaTeXC l => l
rangle = comm0 "rangle"
lfloor :: LaTeXC l => l
lfloor = comm0 "lfloor"
rfloor :: LaTeXC l => l
rfloor = comm0 "rfloor"
lceil :: LaTeXC l => l
lceil = comm0 "lceil"
rceil :: LaTeXC l => l
rceil = comm0 "rceil"
dblPipe :: LaTeXC l => l
dblPipe = comm0 "|"
(^:) :: LaTeXC l => l -> l -> l
x ^: y = x <> raw "^" <> braces y
(!:) :: LaTeXC l => l -> l -> l
x !: y = x <> raw "_" <> braces y
tsin :: LaTeXC l => l
tsin = comm0 "sin"
arcsin :: LaTeXC l => l
arcsin = comm0 "arcsin"
tcos :: LaTeXC l => l
tcos = comm0 "cos"
arccos :: LaTeXC l => l
arccos = comm0 "arccos"
ttan :: LaTeXC l => l
ttan = comm0 "tan"
arctan :: LaTeXC l => l
arctan = comm0 "arctan"
cot :: LaTeXC l => l
cot = comm0 "cot"
arccot :: LaTeXC l => l
arccot = comm0 "arccot"
tsinh :: LaTeXC l => l
tsinh = comm0 "sinh"
tcosh :: LaTeXC l => l
tcosh = comm0 "cosh"
ttanh :: LaTeXC l => l
ttanh = comm0 "tanh"
coth :: LaTeXC l => l
coth = comm0 "coth"
sec :: LaTeXC l => l
sec = comm0 "sec"
csc :: LaTeXC l => l
csc = comm0 "csc"
texp :: LaTeXC l => l
texp = comm0 "exp"
tlog :: LaTeXC l => l
tlog = comm0 "log"
ln :: LaTeXC l => l
ln = comm0 "ln"
tsqrt :: LaTeXC l => Maybe l -> l -> l
tsqrt Nothing = liftL $ \x -> TeXComm "sqrt" [FixArg x]
tsqrt (Just n) = liftL2 (\m x -> TeXComm "sqrt" [OptArg m, FixArg x]) n
tsum :: LaTeXC l => l
tsum = comm0 "sum"
sumFromTo :: LaTeXC l
=> l
-> l
-> l
sumFromTo x y = commS "sum" !: x ^: y
prod :: LaTeXC l => l
prod = comm0 "prod"
prodFromTo :: LaTeXC l
=> l
-> l
-> l
prodFromTo x y = commS "prod" !: x ^: y
integral :: LaTeXC l => l
integral = comm0 "int"
integralFromTo :: LaTeXC l
=> l
-> l
-> l
integralFromTo x y = commS "int" !: x ^: y
notop :: LaTeXC l =>
(l -> l -> l)
-> l -> l -> l
notop op =
\l1 l2 ->
(l1 <> commS "not") `op` l2
pm :: LaTeXC l => l -> l -> l
pm = between $ comm0 "pm"
mp :: LaTeXC l => l -> l -> l
mp = between $ comm0 "mp"
cdot :: LaTeXC l => l -> l -> l
cdot = between $ comm0 "cdot"
times :: LaTeXC l => l -> l -> l
times = between $ comm0 "times"
div_ :: LaTeXC l => l -> l -> l
div_ = between $ comm0 "div"
frac :: LaTeXC l => l -> l -> l
frac = liftL2 $ \p q -> TeXComm "frac" [FixArg p, FixArg q]
infixl 7 *:
(*:) :: LaTeXC l => l -> l -> l
(*:) = between $ comm0 "ast"
star :: LaTeXC l => l -> l -> l
star = between $ comm0 "star"
circ :: LaTeXC l => l -> l -> l
circ = between $ comm0 "circ"
bullet :: LaTeXC l => l -> l -> l
bullet = between $ comm0 "bullet"
infixr 4 =: , /=:
(=:) :: LaTeXC l => l -> l -> l
(=:) = between "="
(/=:) :: LaTeXC l => l -> l -> l
(/=:) = notop (=:)
(>:) :: LaTeXC l => l -> l -> l
(>:) = between ">"
(>=:) :: LaTeXC l => l -> l -> l
(>=:) = between $ comm0 "geq"
(<:) :: LaTeXC l => l -> l -> l
(<:) = between "<"
(<=:) :: LaTeXC l => l -> l -> l
(<=:) = between $ comm0 "leq"
ll :: LaTeXC l => l -> l -> l
ll = between $ comm0 "ll"
gg :: LaTeXC l => l -> l -> l
gg = between $ comm0 "gg"
propto :: LaTeXC l => l -> l -> l
propto = between $ comm0 "propto"
equiv :: LaTeXC l => l -> l -> l
equiv = between $ comm0 "equiv"
in_ :: LaTeXC l => l -> l -> l
in_ = between $ comm0 "in"
ni :: LaTeXC l => l -> l -> l
ni = between $ comm0 "ni"
notin :: LaTeXC l => l -> l -> l
notin = between $ comm0 "notin"
subset :: LaTeXC l => l -> l -> l
subset = between $ comm0 "subset"
supset :: LaTeXC l => l -> l -> l
supset = between $ comm0 "supset"
cap :: LaTeXC l => l -> l -> l
cap = between $ comm0 "cap"
cup :: LaTeXC l => l -> l -> l
cup = between $ comm0 "cup"
setminus :: LaTeXC l => l -> l -> l
setminus = between $ comm0 "setminus"
vee :: LaTeXC l => l -> l -> l
vee = between $ comm0 "vee"
wedge :: LaTeXC l => l -> l -> l
wedge = between $ comm0 "wedge"
oplus :: LaTeXC l => l -> l -> l
oplus = between $ comm0 "oplus"
ominus :: LaTeXC l => l -> l -> l
ominus = between $ comm0 "ominus"
otimes :: LaTeXC l => l -> l -> l
otimes = between $ comm0 "otimes"
oslash :: LaTeXC l => l -> l -> l
oslash = between $ comm0 "oslash"
odot :: LaTeXC l => l -> l -> l
odot = between $ comm0 "odot"
alpha :: LaTeXC l => l
alpha = comm0 "alpha"
beta :: LaTeXC l => l
beta = comm0 "beta"
gamma :: LaTeXC l => l
gamma = comm0 "gamma"
gammau :: LaTeXC l => l
gammau = comm0 "Gamma"
delta :: LaTeXC l => l
delta = comm0 "delta"
deltau :: LaTeXC l => l
deltau = comm0 "Delta"
epsilon :: LaTeXC l => l
epsilon = comm0 "epsilon"
varepsilon :: LaTeXC l => l
varepsilon = comm0 "varepsilon"
zeta :: LaTeXC l => l
zeta = comm0 "zeta"
eta :: LaTeXC l => l
eta = comm0 "eta"
theta :: LaTeXC l => l
theta = comm0 "theta"
vartheta :: LaTeXC l => l
vartheta = comm0 "vartheta"
thetau :: LaTeXC l => l
thetau = comm0 "thetau"
iota :: LaTeXC l => l
iota = comm0 "iota"
kappa :: LaTeXC l => l
kappa = comm0 "kappa"
lambda :: LaTeXC l => l
lambda = comm0 "lambda"
lambdau :: LaTeXC l => l
lambdau = comm0 "Lambda"
mu :: LaTeXC l => l
mu = comm0 "mu"
nu :: LaTeXC l => l
nu = comm0 "nu"
xi :: LaTeXC l => l
xi = comm0 "xi"
xiu :: LaTeXC l => l
xiu = comm0 "Xi"
pi_ :: LaTeXC l => l
pi_ = comm0 "pi"
varpi :: LaTeXC l => l
varpi = comm0 "varpi"
piu :: LaTeXC l => l
piu = comm0 "Pi"
rho :: LaTeXC l => l
rho = comm0 "rho"
varrho :: LaTeXC l => l
varrho = comm0 "varrho"
sigma :: LaTeXC l => l
sigma = comm0 "sigma"
varsigma :: LaTeXC l => l
varsigma = comm0 "varsigma"
sigmau :: LaTeXC l => l
sigmau = comm0 "Sigma"
tau :: LaTeXC l => l
tau = comm0 "tau"
upsilon :: LaTeXC l => l
upsilon = comm0 "upsilon"
upsilonu :: LaTeXC l => l
upsilonu = comm0 "Upsilon"
phi :: LaTeXC l => l
phi = comm0 "phi"
varphi :: LaTeXC l => l
varphi = comm0 "varphi"
phiu :: LaTeXC l => l
phiu = comm0 "Phi"
chi :: LaTeXC l => l
chi = comm0 "chi"
psi :: LaTeXC l => l
psi = comm0 "psi"
psiu :: LaTeXC l => l
psiu = comm0 "Psi"
omega :: LaTeXC l => l
omega = comm0 "omega"
omegau :: LaTeXC l => l
omegau = comm0 "Omega"
to :: LaTeXC l => l
to = comm0 "to"
mapsto :: LaTeXC l => l
mapsto = comm0 "mapsto"
forall :: LaTeXC l => l
forall = comm0 "forall"
exists :: LaTeXC l => l
exists = comm0 "exists"
dagger :: LaTeXC l => l
dagger = comm0 "dagger"
ddagger :: LaTeXC l => l
ddagger = comm0 "ddagger"
infty :: LaTeXC l => l
infty = comm0 "infty"
mathdefault :: LaTeXC l => l -> l
mathdefault = liftL $ \l -> TeXComm "mathdefault" [FixArg l]
mathbf :: LaTeXC l => l -> l
mathbf = liftL $ \l -> TeXComm "mathbf" [FixArg l]
mathrm :: LaTeXC l => l -> l
mathrm = liftL $ \l -> TeXComm "mathrm" [FixArg l]
mathcal :: LaTeXC l => l -> l
mathcal = liftL $ \l -> TeXComm "mathcal" [FixArg l]
mathsf :: LaTeXC l => l -> l
mathsf = liftL $ \l -> TeXComm "mathsf" [FixArg l]
mathtt :: LaTeXC l => l -> l
mathtt = liftL $ \l -> TeXComm "mathtt" [FixArg l]
mathit :: LaTeXC l => l -> l
mathit = liftL $ \l -> TeXComm "mathit" [FixArg l]
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"
instance (Integral a, Texy a) => Texy (Ratio a) where
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