module Language.LaTeX.Builder
( (!$), (!$?), ($?), HaveC(..), HaveL(..), HaveR(..),
Spaces(..),
decl, decls, parDecls, parDecl,
_AA, _AE, _H, _Huge, _L, _LARGE, _LaTeX,
_Large, _O, _OE, _P, _S, _TeX, _l, XChar, a4paper, aa,
acute, addvspace, ae, allTexDecls, appendix,
article, author, authors,
bf, bfseries, bigskip,
bibliography, bibliographystyle, book, boxedminipage,
caption, caption', cedil, cell, cells, center, chapter, chapter',
check, circ, cite, cite', cleardoublepage, clearpage, cline,
comment, compressSpaces, copyright, corrspace, dag, dash1,
dash2, dash3, date, ddag,
description, displaymath,
document, documentclass, dot, dotfill, dquote, em, emph, enumerate,
fbox, figure, flushleft, footnote,
footnotesize, framebox, fussy, grave, group, hat, hchar,
hfill, hline, hr, href, hrulefill, space, hspace, hspace', hspaces,
hstring, huge, hyphen, hyphenation, hyphenationPar, i, institute, it, item,
item', itemize, itshape, j, label,
large, ldots, letter, linebreak, linebr,
lq, ldq, makebox, maketitle,
math, mbox, mdseries, medskip,
minipage, nbsp, negthinspace, newline, rawNewline,
newpage, nocite, noindent, nolinebreak, nopagebreak, normalfont,
normalmarginpar, normalsize, num, o, oe, overbar, overdot, pagebreak,
pageref, pagestyle, para, paragraph, paragraph', parbox, part, part', person, phantom, pounds,
protect, protector, quotation, quote, raisebox, raisebox',
rat, ref, report, reversemarginpar, ring, rm, rmfamily, rq, rdq,
rtext, rule, rule', samepage, savebox, sbox, sc, scriptsize, scshape, section,
section', sep, setlength, addtolength, settowidth, sf, sffamily, sl, sloppy, sloppypar,
slshape, small, smallskip, spaceProtector, ss, subparagraph,
subparagraph', subsection, subsection',
subsubsection, subsubsection', subtitle, table,
tableofcontents, tabular, textbf, textdegree,
textit, textmd, textnormal, textrm, textsc, textsf,
textsl, texttt, textup, textsuperscript, textsubscript, textunderscore,
thinspace, thispagestyle, tieafter, tilde,
tiny, title, titlepage, tt, ttchar, ttfamily, uml,
underbar, unwords, upshape, usebox, verb, verse, vfill, vline,
vphantom, vspace, vspace', (★), vbox, vtop, hbox, here, top, bot, bottom, page, normal,
centered, flushLeft, flushRight, stretch,
utf8,latin1,inputenc,fromEncoding,
)
where
import Prelude hiding (sqrt, min, max, lcm, gcd, log, mod, tanh, cosh, tan, sinh,
sin, cos, succ, sum, pi, mapM, unwords)
import Data.List hiding (sum, and, group, unwords)
import qualified Data.List as L
import Data.Ratio
import Data.Monoid
import Data.Char
import Data.Maybe
import Data.Foldable (foldMap)
import Data.Traversable
import Data.String (IsString(..))
import Control.Applicative hiding (optional)
import Control.Monad hiding (mapM)
import Control.Monad.Error (throwError)
import Control.Monad.Writer (Writer, execWriter, tell)
import Control.Arrow
import Language.LaTeX.Types
import Language.LaTeX.Builder.Internal
import qualified Language.LaTeX.Length as L
import Language.LaTeX.Builder.MonoidUtils
(★) :: Star
(★) = Star
group :: LatexItem -> LatexItem
group = liftM TexGroup
infixr 0 !$
infixr 0 $?
infixr 0 !$?
(!$) :: Monoid b => (a -> b) -> a -> Writer b ()
(!$) f x = tell $ f x
($?) :: (a -> b) -> Writer a () -> b
($?) f m = f $ execWriter m
(!$?) :: Monoid b => (a -> b) -> Writer a () -> Writer b ()
(!$?) f m = tell $ f $ execWriter m
math :: MathItem -> LatexItem
math = latexCast . mathItem
displaymath :: MathItem -> ParItem
displaymath = parCast . mathItem
decls :: [TexDecl] -> LatexItem -> LatexItem
decls ds x = group (rawDecls ds ⊕ x)
decl :: TexDecl -> LatexItem -> LatexItem
decl = decls . pure
parDecls :: [TexDecl] -> ParItem
parDecls = para . rawDecls
parDecl :: TexDecl -> ParItem
parDecl = parDecls . pure
document :: DocumentClass -> PreambleItem -> ParItem -> LatexM Document
document = liftM3 Document
dash1, dash2, dash3, nbsp :: LatexItem
dash1 = rawTex "{-}"
dash2 = rawTex "{--}"
dash3 = rawTex "{---}"
nbsp = rawTex "{~}"
sep :: LatexItem
sep = group ø
newtype Spaces = Spaces { countSpaces :: Int }
hspaces :: Spaces -> LatexItem
hspaces = mbox . hspace . L.em . (1%2 *) . fromIntegral . countSpaces
compressSpaces :: String -> [Either Char Spaces]
compressSpaces [] = []
compressSpaces (' ':xs)
= uncurry (:) . (Right . Spaces . (+1) . length *** compressSpaces) . span (==' ') $ xs
compressSpaces (x:xs) = Left x : compressSpaces xs
type XChar = Char -> LatexItem
spaceProtector :: XChar -> String -> LatexItem
spaceProtector xchar = foldMap (either xchar hspaces) . compressSpaces
protector :: XChar -> String -> LatexItem
protector = spaceProtector . nlchar
protect :: String -> LatexItem
protect = protector hchar
nlchar :: XChar -> XChar
nlchar _ '\n' = rawNewline ø
nlchar xchar ch = xchar ch
hchar :: XChar
hchar = rawTex . rawhchar
ttchar :: XChar
ttchar ch | isAscii ch &&
isPrint ch &&
not (isAlphaNum ch) = rawTex $ "{\\char `\\" ++ ch : "}"
| isAscii ch &&
not (isPrint ch) = verb . show $ ch
| otherwise = rawTex [ch]
verb :: String -> LatexItem
verb = texttt . protector ttchar
comment :: String -> LatexItem
comment s = latexNote (MkKey "comment") (stringNote s) ø
href :: LatexItem -> LatexItem -> LatexItem
href x y = latexCmdArgs "href" [mandatory x,mandatory y]
person :: String -> String -> LatexItem
person name email = href (hstring ("mailto:"++email)) (hstring name)
hr :: LatexItem
hr = group $ noindent ⊕ rule L.linewidth (L.pt 1.5)
hstring :: String -> LatexItem
hstring = fromString
tableofcontents :: ParItem
tableofcontents = parCmdArgs "tableofcontents" []
maketitle :: ParItem
maketitle = parCmdArgs "maketitle" []
noindent :: LatexItem
noindent = texCmdNoArg "noindent"
reversemarginpar :: TexDecl
reversemarginpar = texDecl "reversemarginpar"
normalmarginpar :: TexDecl
normalmarginpar = texDecl "normalmarginpar"
hspace' :: Star -> LatexLength -> LatexItem
hspace' s = latexCmdAnyArg (starize "hspace" s) . texLength
hspace :: LatexLength -> LatexItem
hspace = hspace' ø
vspace' :: Star -> LatexLength -> ParItem
vspace' s = parCmdArg (starize "vspace" s) . texLength
vspace :: LatexLength -> ParItem
vspace = vspace' ø
vfill :: ParItem
vfill = parCmdArgs "vfill" []
hfill :: LatexItem
hfill = texCmdNoArg "hfill"
dotfill :: LatexItem
dotfill = texCmdNoArg "dotfill"
hrulefill :: LatexItem
hrulefill = texCmdNoArg "hrulefill"
thinspace :: LatexItem
thinspace = texCmdNoArg "thinspace"
negthinspace :: LatexItem
negthinspace = texCmdNoArg "!"
corrspace :: LatexItem
corrspace = texCmdNoArg "/"
bigskip :: ParItem
bigskip = parCmdArgs "bigskip" []
medskip :: ParItem
medskip = parCmdArgs "medskip" []
smallskip :: ParItem
smallskip = parCmdArgs "smallskip" []
addvspace :: LatexLength -> ParItem
addvspace = parCmdArg "addvspace" . texLength
unwords :: [LatexItem] -> LatexItem
unwords = mconcat . intersperse space
tiny, scriptsize, footnotesize, small, normalsize, large,
_LARGE, _Large, huge, _Huge, mdseries, bfseries,
itshape, slshape, scshape, upshape,
rmfamily, sffamily, ttfamily, normalfont :: TexDecl
tiny = texDecl "tiny"
scriptsize = texDecl "scriptsize"
footnotesize = texDecl "footnotesize"
small = texDecl "small"
normalsize = texDecl "normalsize"
large = texDecl "large"
_LARGE = texDecl "LARGE"
_Large = texDecl "Large"
huge = texDecl "huge"
_Huge = texDecl "Huge"
bfseries = texDecl "bfseries"
mdseries = texDecl "mdseries"
rmfamily = texDecl "rmfamily"
sffamily = texDecl "sffamily"
ttfamily = texDecl "ttfamily"
upshape = texDecl "upshape"
itshape = texDecl "itshape"
slshape = texDecl "slshape"
scshape = texDecl "scshape"
normalfont = texDecl "normalfont"
emph, textrm, textsf, texttt, textmd, textbf,
textup, textit, textsl, textsc, textnormal,
textsuperscript, textsubscript :: LatexItem -> LatexItem
emph = latexCmdArg "emph"
textrm = latexCmdArg "textrm"
textsf = latexCmdArg "textsf"
texttt = latexCmdArg "texttt"
textmd = latexCmdArg "textmd"
textbf = latexCmdArg "textbf"
textup = latexCmdArg "textup"
textit = latexCmdArg "textit"
textsl = latexCmdArg "textsl"
textsc = latexCmdArg "textsc"
textnormal = latexCmdArg "textnormal"
textsuperscript = latexCmdArg "textsuperscript"
textsubscript x = latexCmdArgs "textsubscript" [packageDependency (pkgName "fixltxe2")
,mandatory x]
textunderscore :: LatexItem
textunderscore = texCmdNoArg "textunderscore"
linebreak :: Maybe Int -> TexDecl
linebreak = (texDecl' "linebreak" =<<) . check0to4 "linebreak"
nolinebreak :: Maybe Int -> TexDecl
nolinebreak = (texDecl' "nolinebreak" =<<) . check0to4 "nolinebreak"
linebr :: Star -> Maybe LatexLength -> LatexItem
linebr s extraSpace =
latexCmdAnyArgs "\\" [starToArg s
,maybe noArg optTexLength extraSpace
,rawArg "%\n"]
rawNewline :: Maybe LatexLength -> LatexItem
rawNewline mlen =
latexCmdAnyArgs "newline" [maybe noArg optTexLength mlen
,rawArg "%\n"]
newline :: Maybe LatexLength -> ParItem
newline = para . rawNewline
hyphen :: LatexItem
hyphen = rawTex "{\\-}"
hyphenation :: [String] -> PreambleItem
hyphenation = preambleCmdArg "hyphenation" . rawAnyTex . L.unwords
hyphenationPar :: [String] -> ParItem
hyphenationPar = parCmdArg "hyphenation" . rawAnyTex . L.unwords
sloppy, fussy :: TexDecl
sloppy = texDecl "sloppy"
fussy = texDecl "fussy"
sloppypar :: ParItem -> ParItem
sloppypar = parEnvironmentPar "sloppypar" []
pagebreak :: Maybe Int -> TexDecl
pagebreak = (texDecl' "pagebreak" =<<) . check0to4 "pagebreak"
nopagebreak :: Maybe Int -> TexDecl
nopagebreak = (texDecl' "nopagebreak" =<<) . check0to4 "nopagebreak"
samepage :: TexDecl
samepage = texDecl "samepage"
newpage :: ParItem
newpage = parCmdArgs "newpage" []
clearpage :: ParItem
clearpage = parCmdArgs "clearpage" []
cleardoublepage :: ParItem
cleardoublepage = parCmdArgs "cleardoublepage" []
hbox :: LatexItem -> LatexItem
hbox = latexCmdArg "hbox"
vbox :: ParItem -> LatexItem
vbox = latexParModeArgs "vbox" []
vtop :: ParItem -> LatexItem
vtop = latexParModeArgs "vtop" []
mbox :: LatexItem -> LatexItem
mbox = latexCmdArg "mbox"
posArg :: Pos -> Arg AnyItem
posArg = optional . rawAnyTex . pure . charPos
makebox :: LatexLength -> Pos -> LatexItem -> LatexItem
makebox width pos txt =
latexCmdAnyArgs "makebox" [optTexLength width
,posArg pos
,mandatoryLatexItem txt]
fbox :: LatexItem -> LatexItem
fbox = latexCmdArg "fbox"
framebox :: LatexLength -> Pos -> LatexItem -> LatexItem
framebox width pos txt = latexCmdAnyArgs "framebox" [optTexLength width
,posArg pos
,mandatoryLatexItem txt]
phantom :: LatexItem -> LatexItem
phantom = latexCmdArg "phantom"
vphantom :: LatexItem -> LatexItem
vphantom = latexCmdArg "vphantom"
sbox :: SaveBin -> LatexItem -> LatexItem
sbox bin txt = latexCmdAnyArgs "sbox" [mandatory $ latexSaveBin bin, mandatoryLatexItem txt]
savebox :: SaveBin -> Maybe LatexLength -> Maybe (Either () ()) -> LatexItem -> LatexItem
savebox bin width dir txt =
latexCmdAnyArgs "savebox" [mandatory $ latexSaveBin bin
,maybe noArg optTexLength width
,maybe noArg (optionalLatexItem . either ll rr) dir
,mandatoryLatexItem txt]
where ll _ = rawTex "l"
rr _ = rawTex "r"
usebox :: SaveBin -> LatexItem
usebox bin = latexCmdAnyArgs "usebox" [mandatory $ latexSaveBin bin]
data VPos = Normal
| Top
| Bot
vposArg :: VPos -> Arg AnyItem
vposArg Normal = noArg
vposArg Top = optional . rawAnyTex $ "t"
vposArg Bot = optional . rawAnyTex $ "b"
parbox :: VPos -> LatexLength -> LatexItem -> LatexItem
parbox pos width txt =
latexCmdAnyArgs "parbox" [vposArg pos, mandatory $ texLength width, mandatoryLatexItem txt]
minipage :: VPos -> LatexLength -> ParItem -> LatexItem
minipage pos width = latexEnvironmentPar "minipage" [vposArg pos, mandatory $ texLength width]
rule :: LatexLength -> LatexLength -> LatexItem
rule width height = latexCmdAnyArgs "rule" [mandatory $ texLength width
,mandatory $ texLength height]
rule' :: LatexLength -> LatexLength -> LatexLength -> LatexItem
rule' raise_len width height = latexCmdAnyArgs "rule" [optTexLength raise_len
,mandatory $ texLength width
,mandatory $ texLength height]
raisebox :: LatexLength -> LatexItem -> LatexItem
raisebox raise_len txt =
latexCmdAnyArgs "raisebox" [mandatory $ texLength raise_len
,mandatoryLatexItem txt]
raisebox' :: LatexLength -> LatexLength -> LatexLength -> LatexItem -> LatexItem
raisebox' raise_len height depth txt =
latexCmdAnyArgs "raisebox" [mandatory $ texLength raise_len
,optTexLength height
,optTexLength depth
,mandatoryLatexItem txt]
footnote :: LatexItem -> LatexItem
footnote = latexCmdArg "footnote"
caption :: LatexItem -> LatexItem
caption txt = latexCmdArgs "caption" [mandatory txt]
caption' :: String -> LatexItem -> LatexItem
caption' lstentry txt = latexCmdArgs "caption" [optional $ checkentry lstentry, mandatory txt]
where checkentry x
| all isAlphaNum x = rawTex x
| otherwise = throwError "caption': restriction to alphanumeric characters for the lstentry"
label :: Key -> LatexItem
label = latexCmdAnyArg "label" . latexKey
ref :: Key -> LatexItem
ref = latexCmdAnyArg "ref" . latexKey
pageref :: Key -> LatexItem
pageref = latexCmdAnyArg "pageref" . latexKey
cite :: [Key] -> LatexItem
cite = latexCmdAnyArgs "cite" . pure . latexKeysArg
cite' :: LatexItem -> [Key] -> LatexItem
cite' txt keys = latexCmdAnyArgs "cite" [optionalLatexItem txt, latexKeysArg keys]
nocite :: [Key] -> LatexItem
nocite = latexCmdAnyArgs "nocite" . pure . latexKeysArg
part, chapter, section, subsection, subsubsection, paragraph,
subparagraph :: LatexItem -> ParItem
part', chapter', section', subsection', subsubsection', paragraph',
subparagraph' :: Star -> Maybe LatexItem -> LatexItem -> ParItem
(part, part') = sectioning "part"
(chapter, chapter') = sectioning "chapter"
(section, section') = sectioning "section"
(subsection, subsection') = sectioning "subsection"
(subsubsection, subsubsection') = sectioning "subsubsection"
(paragraph, paragraph') = sectioning "paragraph"
(subparagraph , subparagraph') = sectioning "subparagraph"
para :: LatexItem -> ParItem
para = parCast . latexItem
bibliography :: LatexItem -> ParItem
bibliography = parCmdArg "bibliography" . latexItem
bibliographystyle :: LatexItem -> ParItem
bibliographystyle = parCmdArg "bibliographystyle" . latexItem
thispagestyle :: LatexItem -> ParItem
thispagestyle = parCmdArg "thispagestyle" . latexItem
pagestyle :: LatexItem -> ParItem
pagestyle = parCmdArg "pagestyle" . latexItem
appendix :: ParItem
appendix = parCmdArgs "appendix" []
setlength :: LatexLength -> LatexLength -> ParItem
setlength lengthName newLength
| isJust (lengthCst lengthName)
= throwError "setlength: the first argument should be a length name not a constant"
| otherwise
= parCmdArgs "setlength" [mandatory (texLength lengthName)
,mandatory (texLength newLength)]
addtolength :: LatexLength -> LatexLength -> ParItem
addtolength lengthName newLength
| isJust (lengthCst lengthName)
= throwError "addtolength: the first argument should be a length name not a constant"
| otherwise
= parCmdArgs "addtolength" [mandatory (texLength lengthName)
,mandatory (texLength newLength)]
settowidth :: LatexLength -> LatexItem -> ParItem
settowidth lengthName text
| isJust (lengthCst lengthName)
= throwError "settowidth: the first argument should be a length name not a constant"
| otherwise
= parCmdArgs "settowidth" [mandatory (texLength lengthName)
,mandatoryLatexItem text]
item :: ParItem -> ListItem
item = liftM $ ListItm []
item' :: LatexItem -> ParItem -> ListItem
item' a = liftM2 ListItm (pure . optional <$> a)
itemize :: Maybe LatexItem -> [ListItem] -> ParItem
itemize = listLikeEnv "itemize" . pure . maybe noArg optional
enumerate :: Maybe LatexItem -> [ListItem] -> ParItem
enumerate = listLikeEnv "enumerate" . pure . maybe noArg optional
description :: Maybe LatexItem -> [ListItem] -> ParItem
description = listLikeEnv "description" . pure . maybe noArg optional
figure, table :: Star -> [LocSpec] -> ParItem -> ParItem
figure = figureLike "figure"
table = figureLike "table"
cedil :: LatexItem -> LatexItem
cedil = latexCmdArg "c"
grave :: LatexItem -> LatexItem
grave = latexCmdArg "`"
acute :: LatexItem -> LatexItem
acute = latexCmdArg "'"
uml :: LatexItem -> LatexItem
uml = latexCmdArg "\""
circ :: LatexItem -> LatexItem
circ = latexCmdArg "^"
hat :: LatexItem -> LatexItem
hat = latexCmdArg "^"
check :: LatexItem -> LatexItem
check = latexCmdArg "v"
i :: LatexItem
i = texCmdNoArg "i"
j :: LatexItem
j = texCmdNoArg "j"
tilde :: LatexItem -> LatexItem
tilde = latexCmdArg "~"
dot :: LatexItem -> LatexItem
dot = latexCmdArg "d"
ring :: LatexItem -> LatexItem
ring = latexCmdArg "r"
_H :: LatexItem -> LatexItem
_H = latexCmdArg "H"
overdot :: LatexItem -> LatexItem
overdot = latexCmdArg "."
overbar :: LatexItem -> LatexItem
overbar = latexCmdArg "="
underbar :: LatexItem -> LatexItem
underbar = latexCmdArg "b"
tieafter :: LatexItem -> LatexItem
tieafter = latexCmdArg "t"
aa :: LatexItem
aa = texCmdNoArg "aa"
_AA :: LatexItem
_AA = texCmdNoArg "AA"
ae :: LatexItem
ae = texCmdNoArg "ae"
_AE :: LatexItem
_AE = texCmdNoArg "AE"
oe :: LatexItem
oe = texCmdNoArg "oe"
_OE :: LatexItem
_OE = texCmdNoArg "OE"
ss :: LatexItem
ss = texCmdNoArg "ss"
_l :: LatexItem
_l = texCmdNoArg "l"
_L :: LatexItem
_L = texCmdNoArg "L"
o :: LatexItem
o = texCmdNoArg "o"
_O :: LatexItem
_O = texCmdNoArg "O"
copyright :: LatexItem
copyright = texCmdNoArg "copyright"
dag :: LatexItem
dag = texCmdNoArg "dag"
ddag :: LatexItem
ddag = texCmdNoArg "ddag"
_LaTeX :: LatexItem
_LaTeX = texCmdNoArg "LaTeX"
_TeX :: LatexItem
_TeX = texCmdNoArg "TeX"
ldots :: LatexItem
ldots = texCmdNoArg "ldots"
lq :: LatexItem
lq = texCmdNoArg "lq"
rq :: LatexItem
rq = texCmdNoArg "rq"
ldq :: LatexItem
ldq = rawTex "{``}"
rdq :: LatexItem
rdq = rawTex "{''}"
dquote :: LatexItem -> LatexItem
dquote x = ldq ⊕ x ⊕ rdq
_P :: LatexItem
_P = texCmdNoArg "P"
pounds :: LatexItem
pounds = texCmdNoArg "pounds"
_S :: LatexItem
_S = texCmdNoArg "S"
textdegree :: LatexItem
textdegree = latexCmdArgs "textdegree" [packageDependency (pkgName "textcomp"), mandatory ø]
titlepage, flushleft, center, boxedminipage, quotation, verse :: ParItem -> ParItem
titlepage = parEnvironmentPar "titlepage" []
flushleft = parEnvironmentPar "flushleft" []
center = parEnvironmentPar "center" []
boxedminipage = parEnvironmentPar "boxedminipage" []
quotation = parEnvironmentPar "quotation" []
verse = parEnvironmentPar "verse" []
quote :: LatexItem -> ParItem
quote = liftM $ ParEnv "quote" [] . LatexItm
tabular :: [RowSpec LatexItem] -> [Row LatexItem] -> ParItem
tabular = tabularLike Tabular
cells :: [a] -> Row a
cells = Cells
cell :: a -> Row a
cell = Cells . pure
hline :: Row a
hline = Hline
cline :: Int -> Int -> Row a
cline = Cline
vline :: RowSpec a
vline = Rvline
rtext :: a -> RowSpec a
rtext = Rtext
class HaveC a where c :: a
class HaveL a where l :: a
class HaveR a where r :: a
instance HaveC (RowSpec a) where c = Rc
instance HaveL (RowSpec a) where l = Rl
instance HaveR (RowSpec a) where r = Rr
class HaveTop a where top :: a
instance HaveTop LocSpec where top = Lt
instance HaveTop VPos where top = Top
class HaveBot a where bot :: a
instance HaveBot LocSpec where bot = Lb
instance HaveBot VPos where bot = Bot
class HaveNormal a where normal :: a
instance HaveNormal VPos where normal = Normal
bottom :: HaveBot a => a
bottom = bot
here, page :: LocSpec
here = Lh
page = Lp
centered, flushLeft, flushRight, stretch :: Pos
centered = Centered
flushLeft = FlushLeft
flushRight = FlushRight
stretch = Stretch
a4paper :: LatexPaperSize
a4paper = A4paper
documentclass :: DocumentClassKind -> [AnyItem] ->
DocumentClass
documentclass dc = (DocClass dc <$>) . mapM anyItmM
article :: Maybe LatexLength -> Maybe LatexPaperSize ->
[AnyItem] -> DocumentClass
article msize mpaper args =
documentclass Article $ maybeToList (latexPaper <$> mpaper) ++
maybeToList (texLength <$> msize) ++
args
letter :: [AnyItem] -> DocumentClass
letter = documentclass Letter
book :: Maybe LatexLength -> Maybe LatexPaperSize ->
[AnyItem] -> DocumentClass
book msize mpaper args =
documentclass Book $ maybeToList (latexPaper <$> mpaper) ++
maybeToList (texLength <$> msize) ++
args
report :: [AnyItem] -> DocumentClass
report = documentclass Report
author, title, subtitle, date, institute :: LatexItem -> PreambleItem
title = preambleCmdArg "title" . latexItem
subtitle = preambleCmdArg "subtitle" . latexItem
date = preambleCmdArg "date" . latexItem
author = preambleCmdArg "author" . latexItem
institute = preambleCmdArg "institute" . latexItem
authors :: [LatexItem] -> PreambleItem
authors = author . mconcat . intersperse (rawTex " & ")
utf8 :: Encoding
utf8 = rawEncoding "utf8"
latin1 :: Encoding
latin1 = rawEncoding "latin1"
inputenc :: Encoding -> PreambleItem
inputenc (Encoding enc)
= usepackage [latexItem $ fromString enc] (pkgName "inputenc")
em :: TexDecl
em = texDecl "em"
rm :: TexDecl
rm = texDecl "rm"
bf :: TexDecl
bf = texDecl "bf"
sf :: TexDecl
sf = texDecl "sf"
sl :: TexDecl
sl = texDecl "sl"
sc :: TexDecl
sc = texDecl "sc"
it :: TexDecl
it = texDecl "it"
tt :: TexDecl
tt = texDecl "tt"
allTexDecls :: [TexDecl]
allTexDecls = [rm, em, bf, sf, sl, sc, it, tt
,rmfamily, bfseries, sffamily, slshape
,scshape, itshape, ttfamily, upshape, normalfont
,reversemarginpar,normalmarginpar
,sloppy, fussy,samepage
,tiny, scriptsize, footnotesize, small, normalsize, large
,_LARGE, _Large, huge, _Huge]
check0to4 :: String -> Maybe Int -> LatexM [Arg AnyItem]
check0to4 _ Nothing = return []
check0to4 s (Just n)
| n >= 0 && n <= 4 = return [optional $ num n]
| otherwise = throwError $ s ++ ": option must be between 0 and 4 not " ++ show i