{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
module Text.LaTeX.Base.Class (
LaTeXC (..)
, Monoid (..)
, fromLaTeX
, liftL, liftL2, liftL3, liftL4, liftL5, liftL6, liftL7, liftL8, liftL9
, comm0, comm1, comm2, comm3, comm4, comm5, comm6, comm7, comm8, comm9
, commS
, fixComm, optFixComm
, env0, env1, env2, env3, env4, env5, env6, env7, env8, env9
, fixEnv
, braces, squareBraces
, raw
) where
import Text.LaTeX.Base.Syntax
import Data.String
#if !MIN_VERSION_base(4,8,0)
import Data.Monoid
#endif
import Data.Text (Text)
class (Monoid l,IsString l) => LaTeXC l where
liftListL :: ([LaTeX] -> LaTeX) -> [l] -> l
instance LaTeXC LaTeX where
liftListL :: ([LaTeX] -> LaTeX) -> [LaTeX] -> LaTeX
liftListL = forall a. a -> a
id
fromLaTeX :: LaTeXC l => LaTeX -> l
fromLaTeX :: forall l. LaTeXC l => LaTeX -> l
fromLaTeX LaTeX
l = forall l. LaTeXC l => ([LaTeX] -> LaTeX) -> [l] -> l
liftListL (forall a b. a -> b -> a
const LaTeX
l) []
liftL :: LaTeXC l => (LaTeX -> LaTeX) -> l -> l
liftL :: forall l. LaTeXC l => (LaTeX -> LaTeX) -> l -> l
liftL LaTeX -> LaTeX
f l
x1 = forall l. LaTeXC l => ([LaTeX] -> LaTeX) -> [l] -> l
liftListL (\[LaTeX
x1] -> LaTeX -> LaTeX
f LaTeX
x1) [l
x1]
liftL2 :: LaTeXC l => (LaTeX -> LaTeX -> LaTeX) -> l -> l -> l
liftL2 :: forall l. LaTeXC l => (LaTeX -> LaTeX -> LaTeX) -> l -> l -> l
liftL2 LaTeX -> LaTeX -> LaTeX
f l
x1 l
x2 = forall l. LaTeXC l => ([LaTeX] -> LaTeX) -> [l] -> l
liftListL (\[LaTeX
x1,LaTeX
x2] -> LaTeX -> LaTeX -> LaTeX
f LaTeX
x1 LaTeX
x2) [l
x1,l
x2]
liftL3 :: LaTeXC l => (LaTeX -> LaTeX -> LaTeX -> LaTeX) -> l -> l -> l -> l
liftL3 :: forall l.
LaTeXC l =>
(LaTeX -> LaTeX -> LaTeX -> LaTeX) -> l -> l -> l -> l
liftL3 LaTeX -> LaTeX -> LaTeX -> LaTeX
f l
x1 l
x2 l
x3 = forall l. LaTeXC l => ([LaTeX] -> LaTeX) -> [l] -> l
liftListL (\[LaTeX
x1,LaTeX
x2,LaTeX
x3] -> LaTeX -> LaTeX -> LaTeX -> LaTeX
f LaTeX
x1 LaTeX
x2 LaTeX
x3) [l
x1,l
x2,l
x3]
liftL4 :: LaTeXC l => (LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX) -> l -> l -> l -> l -> l
liftL4 :: forall l.
LaTeXC l =>
(LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX)
-> l -> l -> l -> l -> l
liftL4 LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX
f l
x1 l
x2 l
x3 l
x4 = forall l. LaTeXC l => ([LaTeX] -> LaTeX) -> [l] -> l
liftListL (\[LaTeX
x1,LaTeX
x2,LaTeX
x3,LaTeX
x4] -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX
f LaTeX
x1 LaTeX
x2 LaTeX
x3 LaTeX
x4) [l
x1,l
x2,l
x3,l
x4]
liftL5 :: LaTeXC l => (LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX) -> l -> l -> l -> l -> l -> l
liftL5 :: forall l.
LaTeXC l =>
(LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX)
-> l -> l -> l -> l -> l -> l
liftL5 LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX
f l
x1 l
x2 l
x3 l
x4 l
x5 = forall l. LaTeXC l => ([LaTeX] -> LaTeX) -> [l] -> l
liftListL (\[LaTeX
x1,LaTeX
x2,LaTeX
x3,LaTeX
x4,LaTeX
x5] -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX
f LaTeX
x1 LaTeX
x2 LaTeX
x3 LaTeX
x4 LaTeX
x5) [l
x1,l
x2,l
x3,l
x4,l
x5]
liftL6 :: LaTeXC l => (LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX) -> l -> l -> l -> l -> l -> l -> l
liftL6 :: forall l.
LaTeXC l =>
(LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX)
-> l -> l -> l -> l -> l -> l -> l
liftL6 LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX
f l
x1 l
x2 l
x3 l
x4 l
x5 l
x6 = forall l. LaTeXC l => ([LaTeX] -> LaTeX) -> [l] -> l
liftListL (\[LaTeX
x1,LaTeX
x2,LaTeX
x3,LaTeX
x4,LaTeX
x5,LaTeX
x6] -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX
f LaTeX
x1 LaTeX
x2 LaTeX
x3 LaTeX
x4 LaTeX
x5 LaTeX
x6) [l
x1,l
x2,l
x3,l
x4,l
x5,l
x6]
liftL7 :: LaTeXC l => (LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX) -> l -> l -> l -> l -> l -> l -> l -> l
liftL7 :: forall l.
LaTeXC l =>
(LaTeX
-> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX)
-> l -> l -> l -> l -> l -> l -> l -> l
liftL7 LaTeX
-> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX
f l
x1 l
x2 l
x3 l
x4 l
x5 l
x6 l
x7 = forall l. LaTeXC l => ([LaTeX] -> LaTeX) -> [l] -> l
liftListL (\[LaTeX
x1,LaTeX
x2,LaTeX
x3,LaTeX
x4,LaTeX
x5,LaTeX
x6,LaTeX
x7] -> LaTeX
-> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX
f LaTeX
x1 LaTeX
x2 LaTeX
x3 LaTeX
x4 LaTeX
x5 LaTeX
x6 LaTeX
x7) [l
x1,l
x2,l
x3,l
x4,l
x5,l
x6,l
x7]
liftL8 :: LaTeXC l => (LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX) -> l -> l -> l -> l -> l -> l -> l -> l -> l
liftL8 :: forall l.
LaTeXC l =>
(LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX)
-> l -> l -> l -> l -> l -> l -> l -> l -> l
liftL8 LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
f l
x1 l
x2 l
x3 l
x4 l
x5 l
x6 l
x7 l
x8 = forall l. LaTeXC l => ([LaTeX] -> LaTeX) -> [l] -> l
liftListL (\[LaTeX
x1,LaTeX
x2,LaTeX
x3,LaTeX
x4,LaTeX
x5,LaTeX
x6,LaTeX
x7,LaTeX
x8] -> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
f LaTeX
x1 LaTeX
x2 LaTeX
x3 LaTeX
x4 LaTeX
x5 LaTeX
x6 LaTeX
x7 LaTeX
x8) [l
x1,l
x2,l
x3,l
x4,l
x5,l
x6,l
x7,l
x8]
liftL9 :: LaTeXC l => (LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX -> LaTeX) -> l -> l -> l -> l -> l -> l -> l -> l -> l -> l
liftL9 :: forall l.
LaTeXC l =>
(LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX)
-> l -> l -> l -> l -> l -> l -> l -> l -> l -> l
liftL9 LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
f l
x1 l
x2 l
x3 l
x4 l
x5 l
x6 l
x7 l
x8 l
x9 = forall l. LaTeXC l => ([LaTeX] -> LaTeX) -> [l] -> l
liftListL (\[LaTeX
x1,LaTeX
x2,LaTeX
x3,LaTeX
x4,LaTeX
x5,LaTeX
x6,LaTeX
x7,LaTeX
x8,LaTeX
x9] -> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
-> LaTeX
f LaTeX
x1 LaTeX
x2 LaTeX
x3 LaTeX
x4 LaTeX
x5 LaTeX
x6 LaTeX
x7 LaTeX
x8 LaTeX
x9) [l
x1,l
x2,l
x3,l
x4,l
x5,l
x6,l
x7,l
x8,l
x9]
fixArgs :: Functor f => f LaTeX -> f TeXArg
fixArgs :: forall (f :: * -> *). Functor f => f LaTeX -> f TeXArg
fixArgs = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap LaTeX -> TeXArg
FixArg
optFixArgs :: Int -> [LaTeX] -> [TeXArg]
optFixArgs :: Int -> [LaTeX] -> [TeXArg]
optFixArgs Int
_ [] = []
optFixArgs Int
k xa :: [LaTeX]
xa@(LaTeX
x:[LaTeX]
xs) | Int
k forall a. Ord a => a -> a -> Bool
<= Int
0 = forall a b. (a -> b) -> [a] -> [b]
map LaTeX -> TeXArg
FixArg [LaTeX]
xa
| Bool
otherwise = LaTeX -> TeXArg
OptArg LaTeX
x forall a. a -> [a] -> [a]
: Int -> [LaTeX] -> [TeXArg]
optFixArgs (Int
kforall a. Num a => a -> a -> a
-Int
1) [LaTeX]
xs
fixComm :: LaTeXC l => String -> [l] -> l
fixComm :: forall l. LaTeXC l => String -> [l] -> l
fixComm String
str = forall l. LaTeXC l => ([LaTeX] -> LaTeX) -> [l] -> l
liftListL (String -> [TeXArg] -> LaTeX
TeXComm String
str forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *). Functor f => f LaTeX -> f TeXArg
fixArgs)
optFixComm :: LaTeXC l => String -> Int -> [l] -> l
optFixComm :: forall l. LaTeXC l => String -> Int -> [l] -> l
optFixComm String
str Int
k = forall l. LaTeXC l => ([LaTeX] -> LaTeX) -> [l] -> l
liftListL (String -> [TeXArg] -> LaTeX
TeXComm String
str forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> [LaTeX] -> [TeXArg]
optFixArgs Int
k)
fixEnv :: LaTeXC l => String -> [l] -> l -> l
fixEnv :: forall l. LaTeXC l => String -> [l] -> l -> l
fixEnv String
str [l]
args l
inner = forall l. LaTeXC l => ([LaTeX] -> LaTeX) -> [l] -> l
liftListL (\(LaTeX
inn:[LaTeX]
as) -> String -> [TeXArg] -> LaTeX -> LaTeX
TeXEnv String
str (forall (f :: * -> *). Functor f => f LaTeX -> f TeXArg
fixArgs [LaTeX]
as) LaTeX
inn) (l
innerforall a. a -> [a] -> [a]
:[l]
args)
comm0 :: LaTeXC l => String -> l
comm0 :: forall l. LaTeXC l => String -> l
comm0 String
str = forall l. LaTeXC l => LaTeX -> l
fromLaTeX forall a b. (a -> b) -> a -> b
$ String -> [TeXArg] -> LaTeX
TeXComm String
str []
comm1 :: LaTeXC l => String -> l -> l
comm1 :: forall l. LaTeXC l => String -> l -> l
comm1 String
str l
l1 = forall l. LaTeXC l => String -> [l] -> l
fixComm String
str [l
l1]
comm2 :: LaTeXC l => String -> l -> l -> l
comm2 :: forall l. LaTeXC l => String -> l -> l -> l
comm2 String
str l
l1 l
l2 = forall l. LaTeXC l => String -> [l] -> l
fixComm String
str [l
l1, l
l2]
comm3 :: LaTeXC l => String -> l -> l -> l -> l
comm3 :: forall l. LaTeXC l => String -> l -> l -> l -> l
comm3 String
str l
l1 l
l2 l
l3 = forall l. LaTeXC l => String -> [l] -> l
fixComm String
str [l
l1, l
l2, l
l3]
comm4 :: LaTeXC l => String -> l -> l -> l -> l -> l
comm4 :: forall l. LaTeXC l => String -> l -> l -> l -> l -> l
comm4 String
str l
l1 l
l2 l
l3 l
l4 = forall l. LaTeXC l => String -> [l] -> l
fixComm String
str [l
l1, l
l2, l
l3, l
l4]
comm5 :: LaTeXC l => String -> l -> l -> l -> l -> l -> l
comm5 :: forall l. LaTeXC l => String -> l -> l -> l -> l -> l -> l
comm5 String
str l
l1 l
l2 l
l3 l
l4 l
l5 = forall l. LaTeXC l => String -> [l] -> l
fixComm String
str [l
l1, l
l2, l
l3, l
l4, l
l5]
comm6 :: LaTeXC l => String -> l -> l -> l -> l -> l -> l -> l
comm6 :: forall l. LaTeXC l => String -> l -> l -> l -> l -> l -> l -> l
comm6 String
str l
l1 l
l2 l
l3 l
l4 l
l5 l
l6 = forall l. LaTeXC l => String -> [l] -> l
fixComm String
str [l
l1, l
l2, l
l3, l
l4, l
l5, l
l6]
comm7 :: LaTeXC l => String -> l -> l -> l -> l -> l -> l -> l -> l
comm7 :: forall l.
LaTeXC l =>
String -> l -> l -> l -> l -> l -> l -> l -> l
comm7 String
str l
l1 l
l2 l
l3 l
l4 l
l5 l
l6 l
l7 = forall l. LaTeXC l => String -> [l] -> l
fixComm String
str [l
l1, l
l2, l
l3, l
l4, l
l5, l
l6, l
l7]
comm8 :: LaTeXC l => String -> l -> l -> l -> l -> l -> l -> l -> l -> l
comm8 :: forall l.
LaTeXC l =>
String -> l -> l -> l -> l -> l -> l -> l -> l -> l
comm8 String
str l
l1 l
l2 l
l3 l
l4 l
l5 l
l6 l
l7 l
l8 = forall l. LaTeXC l => String -> [l] -> l
fixComm String
str [l
l1, l
l2, l
l3, l
l4, l
l5, l
l6, l
l7, l
l8]
comm9 :: LaTeXC l => String -> l -> l -> l -> l -> l -> l -> l -> l -> l -> l
comm9 :: forall l.
LaTeXC l =>
String -> l -> l -> l -> l -> l -> l -> l -> l -> l -> l
comm9 String
str l
l1 l
l2 l
l3 l
l4 l
l5 l
l6 l
l7 l
l8 l
l9 = forall l. LaTeXC l => String -> [l] -> l
fixComm String
str [l
l1, l
l2, l
l3, l
l4, l
l5, l
l6, l
l7, l
l8, l
l9]
commS :: LaTeXC l => String -> l
commS :: forall l. LaTeXC l => String -> l
commS = forall l. LaTeXC l => LaTeX -> l
fromLaTeX forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> LaTeX
TeXCommS
env0 :: LaTeXC l => String -> l -> l
env0 :: forall l. LaTeXC l => String -> l -> l
env0 String
str = forall l. LaTeXC l => String -> [l] -> l -> l
fixEnv String
str []
env1 :: LaTeXC l => String -> l -> l -> l
env1 :: forall l. LaTeXC l => String -> l -> l -> l
env1 String
str l
l1 = forall l. LaTeXC l => String -> [l] -> l -> l
fixEnv String
str [l
l1]
env2 :: LaTeXC l => String -> l -> l -> l -> l
env2 :: forall l. LaTeXC l => String -> l -> l -> l -> l
env2 String
str l
l1 l
l2 = forall l. LaTeXC l => String -> [l] -> l -> l
fixEnv String
str [l
l1, l
l2]
env3 :: LaTeXC l => String -> l -> l -> l -> l -> l
env3 :: forall l. LaTeXC l => String -> l -> l -> l -> l -> l
env3 String
str l
l1 l
l2 l
l3 = forall l. LaTeXC l => String -> [l] -> l -> l
fixEnv String
str [l
l1, l
l2, l
l3]
env4 :: LaTeXC l => String -> l -> l -> l -> l -> l -> l
env4 :: forall l. LaTeXC l => String -> l -> l -> l -> l -> l -> l
env4 String
str l
l1 l
l2 l
l3 l
l4 = forall l. LaTeXC l => String -> [l] -> l -> l
fixEnv String
str [l
l1, l
l2, l
l3, l
l4]
env5 :: LaTeXC l => String -> l -> l -> l -> l -> l -> l -> l
env5 :: forall l. LaTeXC l => String -> l -> l -> l -> l -> l -> l -> l
env5 String
str l
l1 l
l2 l
l3 l
l4 l
l5 = forall l. LaTeXC l => String -> [l] -> l -> l
fixEnv String
str [l
l1, l
l2, l
l3, l
l4, l
l5]
env6 :: LaTeXC l => String -> l -> l -> l -> l -> l -> l -> l -> l
env6 :: forall l.
LaTeXC l =>
String -> l -> l -> l -> l -> l -> l -> l -> l
env6 String
str l
l1 l
l2 l
l3 l
l4 l
l5 l
l6 = forall l. LaTeXC l => String -> [l] -> l -> l
fixEnv String
str [l
l1, l
l2, l
l3, l
l4, l
l5, l
l6]
env7 :: LaTeXC l => String -> l -> l -> l -> l -> l -> l -> l -> l -> l
env7 :: forall l.
LaTeXC l =>
String -> l -> l -> l -> l -> l -> l -> l -> l -> l
env7 String
str l
l1 l
l2 l
l3 l
l4 l
l5 l
l6 l
l7 = forall l. LaTeXC l => String -> [l] -> l -> l
fixEnv String
str [l
l1, l
l2, l
l3, l
l4, l
l5, l
l6, l
l7]
env8 :: LaTeXC l => String -> l -> l -> l -> l -> l -> l -> l -> l -> l -> l
env8 :: forall l.
LaTeXC l =>
String -> l -> l -> l -> l -> l -> l -> l -> l -> l -> l
env8 String
str l
l1 l
l2 l
l3 l
l4 l
l5 l
l6 l
l7 l
l8 = forall l. LaTeXC l => String -> [l] -> l -> l
fixEnv String
str [l
l1, l
l2, l
l3, l
l4, l
l5, l
l6, l
l7, l
l8]
env9 :: LaTeXC l => String -> l -> l -> l -> l -> l -> l -> l -> l -> l -> l -> l
env9 :: forall l.
LaTeXC l =>
String -> l -> l -> l -> l -> l -> l -> l -> l -> l -> l -> l
env9 String
str l
l1 l
l2 l
l3 l
l4 l
l5 l
l6 l
l7 l
l8 l
l9 = forall l. LaTeXC l => String -> [l] -> l -> l
fixEnv String
str [l
l1, l
l2, l
l3, l
l4, l
l5, l
l6, l
l7, l
l8, l
l9]
braces :: LaTeXC l => l -> l
braces :: forall l. LaTeXC l => l -> l
braces = forall l. LaTeXC l => (LaTeX -> LaTeX) -> l -> l
liftL LaTeX -> LaTeX
TeXBraces
squareBraces :: LaTeXC l => l -> l
squareBraces :: forall l. LaTeXC l => l -> l
squareBraces = forall l. LaTeXC l => (LaTeX -> LaTeX) -> l -> l
liftL forall a b. (a -> b) -> a -> b
$ \LaTeX
l -> Text -> LaTeX
TeXRaw Text
"[" forall a. Semigroup a => a -> a -> a
<> LaTeX
l forall a. Semigroup a => a -> a -> a
<> Text -> LaTeX
TeXRaw Text
"]"
raw :: LaTeXC l => Text -> l
raw :: forall l. LaTeXC l => Text -> l
raw = forall l. LaTeXC l => LaTeX -> l
fromLaTeX forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> LaTeX
TeXRaw