{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
module Language.Ltml.ToLaTeX.Format
( Stylable (..)
, emptyIdentifierFormat
, emptyAppendixFormat
, emptyHeadingFormat
, emptySectionFormat
, formatHeading
, formatKey
, staticDocumentFormat
, getIdentifier
, getEnumStyle
, formatHeaderFooterItem
) where
import Data.Char (chr)
import qualified Data.Text as T
import Data.Typography
( FontSize (..)
, FontStyle (..)
, TextAlignment (..)
, Typography (..)
)
import Data.Void (Void, absurd)
import Language.Lsd.AST.Format
( EnumStyle (AlphabeticLower, AlphabeticUpper, Arabic)
, FormatAtom (InsertedPlaceholderAtom, PlaceholderAtom, StringAtom)
, FormatString (..)
, HeadingFormat (..)
, HeadingPlaceholderAtom (..)
, IdentifierFormat
, KeyFormat
, KeyPlaceholderAtom (KeyIdentifierPlaceholder)
, TocKeyFormat (..)
)
import Language.Lsd.AST.Type.AppendixSection
( AppendixElementFormat (AppendixElementFormat)
)
import Language.Lsd.AST.Type.DocumentContainer
( HeaderFooterFormatAtom (..)
, HeaderFooterItemFormat (HeaderFooterItemFormat)
)
import Language.Lsd.AST.Type.Section (SectionFormat (SectionFormat))
import Language.Ltml.ToLaTeX.PreLaTeXType
( PreLaTeX (IRaw, ISequence, IText)
, bold
, center
, documentclass
, flushleft
, flushright
, italic
, large
, linebreak
, renewlist
, setfontArabic
, setlistdepth
, small
, underline
, usepackage
)
class Stylable a where
applyTextStyle :: a -> PreLaTeX -> PreLaTeX
instance Stylable Void where
applyTextStyle :: Void -> PreLaTeX -> PreLaTeX
applyTextStyle = Void -> PreLaTeX -> PreLaTeX
forall a. Void -> a
absurd
instance Stylable FontStyle where
applyTextStyle :: FontStyle -> PreLaTeX -> PreLaTeX
applyTextStyle FontStyle
Bold = PreLaTeX -> PreLaTeX
bold
applyTextStyle FontStyle
Italics = PreLaTeX -> PreLaTeX
italic
applyTextStyle FontStyle
Underlined = PreLaTeX -> PreLaTeX
underline
instance Stylable TextAlignment where
applyTextStyle :: TextAlignment -> PreLaTeX -> PreLaTeX
applyTextStyle TextAlignment
LeftAligned = [PreLaTeX] -> PreLaTeX
flushleft ([PreLaTeX] -> PreLaTeX)
-> (PreLaTeX -> [PreLaTeX]) -> PreLaTeX -> PreLaTeX
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PreLaTeX -> [PreLaTeX] -> [PreLaTeX]
forall a. a -> [a] -> [a]
: [])
applyTextStyle TextAlignment
Centered = [PreLaTeX] -> PreLaTeX
center ([PreLaTeX] -> PreLaTeX)
-> (PreLaTeX -> [PreLaTeX]) -> PreLaTeX -> PreLaTeX
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PreLaTeX -> [PreLaTeX] -> [PreLaTeX]
forall a. a -> [a] -> [a]
: [])
applyTextStyle TextAlignment
RightAligned = [PreLaTeX] -> PreLaTeX
flushright ([PreLaTeX] -> PreLaTeX)
-> (PreLaTeX -> [PreLaTeX]) -> PreLaTeX -> PreLaTeX
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PreLaTeX -> [PreLaTeX] -> [PreLaTeX]
forall a. a -> [a] -> [a]
: [])
instance Stylable FontSize where
applyTextStyle :: FontSize -> PreLaTeX -> PreLaTeX
applyTextStyle FontSize
SmallFontSize = PreLaTeX -> PreLaTeX
small
applyTextStyle FontSize
MediumFontSize = PreLaTeX -> PreLaTeX
forall a. a -> a
id
applyTextStyle FontSize
LargeFontSize = PreLaTeX -> PreLaTeX
large
instance Stylable Typography where
applyTextStyle :: Typography -> PreLaTeX -> PreLaTeX
applyTextStyle (Typography TextAlignment
alignment FontSize
fontsize [FontStyle]
styles) =
TextAlignment -> PreLaTeX -> PreLaTeX
forall a. Stylable a => a -> PreLaTeX -> PreLaTeX
applyTextStyle TextAlignment
alignment
(PreLaTeX -> PreLaTeX)
-> (PreLaTeX -> PreLaTeX) -> PreLaTeX -> PreLaTeX
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FontSize -> PreLaTeX -> PreLaTeX
forall a. Stylable a => a -> PreLaTeX -> PreLaTeX
applyTextStyle FontSize
fontsize
(PreLaTeX -> PreLaTeX)
-> (PreLaTeX -> PreLaTeX) -> PreLaTeX -> PreLaTeX
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FontStyle -> (PreLaTeX -> PreLaTeX) -> PreLaTeX -> PreLaTeX)
-> (PreLaTeX -> PreLaTeX) -> [FontStyle] -> PreLaTeX -> PreLaTeX
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\FontStyle
style PreLaTeX -> PreLaTeX
acc -> PreLaTeX -> PreLaTeX
acc (PreLaTeX -> PreLaTeX)
-> (PreLaTeX -> PreLaTeX) -> PreLaTeX -> PreLaTeX
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FontStyle -> PreLaTeX -> PreLaTeX
forall a. Stylable a => a -> PreLaTeX -> PreLaTeX
applyTextStyle FontStyle
style) PreLaTeX -> PreLaTeX
forall a. a -> a
id [FontStyle]
styles
emptyIdentifierFormat :: IdentifierFormat
emptyIdentifierFormat :: IdentifierFormat
emptyIdentifierFormat = [FormatAtom EnumStyle] -> IdentifierFormat
forall a. [FormatAtom a] -> FormatString a
FormatString []
emptyKeyFormat :: KeyFormat
emptyKeyFormat :: KeyFormat
emptyKeyFormat = [FormatAtom KeyPlaceholderAtom] -> KeyFormat
forall a. [FormatAtom a] -> FormatString a
FormatString []
emptyHeadingFormat :: HeadingFormat b
emptyHeadingFormat :: forall (b :: Bool). HeadingFormat b
emptyHeadingFormat = Typography
-> FormatString (HeadingPlaceholderAtom b) -> HeadingFormat b
forall (permitIdentifier :: Bool).
Typography
-> FormatString (HeadingPlaceholderAtom permitIdentifier)
-> HeadingFormat permitIdentifier
HeadingFormat (TextAlignment -> FontSize -> [FontStyle] -> Typography
Typography TextAlignment
LeftAligned FontSize
MediumFontSize []) ([FormatAtom (HeadingPlaceholderAtom b)]
-> FormatString (HeadingPlaceholderAtom b)
forall a. [FormatAtom a] -> FormatString a
FormatString [])
emptyTocKeyFormat :: TocKeyFormat
emptyTocKeyFormat :: TocKeyFormat
emptyTocKeyFormat = KeyFormat -> TocKeyFormat
TocKeyFormat KeyFormat
emptyKeyFormat
emptyAppendixFormat :: AppendixElementFormat
emptyAppendixFormat :: AppendixElementFormat
emptyAppendixFormat =
IdentifierFormat
-> TocKeyFormat -> InnerHeadingFormat -> AppendixElementFormat
AppendixElementFormat IdentifierFormat
emptyIdentifierFormat TocKeyFormat
emptyTocKeyFormat InnerHeadingFormat
forall (b :: Bool). HeadingFormat b
emptyHeadingFormat
emptySectionFormat :: SectionFormat
emptySectionFormat :: SectionFormat
emptySectionFormat = IdentifierFormat -> TocKeyFormat -> Bool -> SectionFormat
SectionFormat IdentifierFormat
emptyIdentifierFormat TocKeyFormat
emptyTocKeyFormat Bool
False
formatHeading
:: FormatString (HeadingPlaceholderAtom b) -> PreLaTeX -> PreLaTeX -> PreLaTeX
formatHeading :: forall (b :: Bool).
FormatString (HeadingPlaceholderAtom b)
-> PreLaTeX -> PreLaTeX -> PreLaTeX
formatHeading (FormatString []) PreLaTeX
_ PreLaTeX
_ = PreLaTeX
forall a. Monoid a => a
mempty
formatHeading (FormatString (StringAtom String
s : [FormatAtom (HeadingPlaceholderAtom b)]
rest)) PreLaTeX
i PreLaTeX
latex =
[PreLaTeX] -> PreLaTeX
ISequence ((Char -> PreLaTeX) -> String -> [PreLaTeX]
forall a b. (a -> b) -> [a] -> [b]
map Char -> PreLaTeX
replace String
s) PreLaTeX -> PreLaTeX -> PreLaTeX
forall a. Semigroup a => a -> a -> a
<> FormatString (HeadingPlaceholderAtom b)
-> PreLaTeX -> PreLaTeX -> PreLaTeX
forall (b :: Bool).
FormatString (HeadingPlaceholderAtom b)
-> PreLaTeX -> PreLaTeX -> PreLaTeX
formatHeading ([FormatAtom (HeadingPlaceholderAtom b)]
-> FormatString (HeadingPlaceholderAtom b)
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom (HeadingPlaceholderAtom b)]
rest) PreLaTeX
i PreLaTeX
latex
where
replace :: Char -> PreLaTeX
replace Char
'\n' = PreLaTeX
linebreak
replace Char
c = Text -> PreLaTeX
IText (String -> Text
T.pack [Char
c])
formatHeading (FormatString (PlaceholderAtom HeadingPlaceholderAtom b
a : [FormatAtom (HeadingPlaceholderAtom b)]
rest)) PreLaTeX
i PreLaTeX
latex =
case HeadingPlaceholderAtom b
a of
HeadingPlaceholderAtom b
HeadingTextPlaceholder -> PreLaTeX
latex PreLaTeX -> PreLaTeX -> PreLaTeX
forall a. Semigroup a => a -> a -> a
<> FormatString (HeadingPlaceholderAtom b)
-> PreLaTeX -> PreLaTeX -> PreLaTeX
forall (b :: Bool).
FormatString (HeadingPlaceholderAtom b)
-> PreLaTeX -> PreLaTeX -> PreLaTeX
formatHeading ([FormatAtom (HeadingPlaceholderAtom b)]
-> FormatString (HeadingPlaceholderAtom b)
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom (HeadingPlaceholderAtom b)]
rest) PreLaTeX
i PreLaTeX
latex
HeadingPlaceholderAtom b
IdentifierPlaceholder -> PreLaTeX
i PreLaTeX -> PreLaTeX -> PreLaTeX
forall a. Semigroup a => a -> a -> a
<> FormatString (HeadingPlaceholderAtom b)
-> PreLaTeX -> PreLaTeX -> PreLaTeX
forall (b :: Bool).
FormatString (HeadingPlaceholderAtom b)
-> PreLaTeX -> PreLaTeX -> PreLaTeX
formatHeading ([FormatAtom (HeadingPlaceholderAtom b)]
-> FormatString (HeadingPlaceholderAtom b)
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom (HeadingPlaceholderAtom b)]
rest) PreLaTeX
i PreLaTeX
latex
formatHeading (FormatString (InsertedPlaceholderAtom HeadingPlaceholderAtom b
_ : [FormatAtom (HeadingPlaceholderAtom b)]
_)) PreLaTeX
_ PreLaTeX
_ = PreLaTeX
forall a. HasCallStack => a
undefined
formatKey :: KeyFormat -> PreLaTeX -> PreLaTeX
formatKey :: KeyFormat -> PreLaTeX -> PreLaTeX
formatKey (FormatString []) PreLaTeX
_ = PreLaTeX
forall a. Monoid a => a
mempty
formatKey (FormatString (StringAtom String
s : [FormatAtom KeyPlaceholderAtom]
rest)) PreLaTeX
n =
Text -> PreLaTeX
IText (String -> Text
T.pack String
s) PreLaTeX -> PreLaTeX -> PreLaTeX
forall a. Semigroup a => a -> a -> a
<> KeyFormat -> PreLaTeX -> PreLaTeX
formatKey ([FormatAtom KeyPlaceholderAtom] -> KeyFormat
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom KeyPlaceholderAtom]
rest) PreLaTeX
n
formatKey (FormatString (PlaceholderAtom KeyPlaceholderAtom
KeyIdentifierPlaceholder : [FormatAtom KeyPlaceholderAtom]
rest)) PreLaTeX
n =
PreLaTeX
n PreLaTeX -> PreLaTeX -> PreLaTeX
forall a. Semigroup a => a -> a -> a
<> KeyFormat -> PreLaTeX -> PreLaTeX
formatKey ([FormatAtom KeyPlaceholderAtom] -> KeyFormat
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom KeyPlaceholderAtom]
rest) PreLaTeX
n
formatKey (FormatString (InsertedPlaceholderAtom KeyPlaceholderAtom
_ : [FormatAtom KeyPlaceholderAtom]
_)) PreLaTeX
_ = PreLaTeX
forall a. HasCallStack => a
undefined
staticDocumentFormat :: PreLaTeX
staticDocumentFormat :: PreLaTeX
staticDocumentFormat =
[PreLaTeX] -> PreLaTeX
ISequence
[ [Text] -> Text -> PreLaTeX
documentclass [] Text
"article"
, PreLaTeX
setfontArabic
, [Text] -> Text -> PreLaTeX
usepackage
[ Text
"letterpaper"
, Text
"top=2cm"
, Text
"bottom=2cm"
, Text
"left=3cm"
, Text
"right=3cm"
, Text
"marginparwidth=1.75cm"
]
Text
"geometry"
, [Text] -> Text -> PreLaTeX
usepackage [] Text
"hyperref"
, [Text] -> Text -> PreLaTeX
usepackage [] Text
"enumitem"
, [Text] -> Text -> PreLaTeX
usepackage [] Text
"longtable"
, [Text] -> Text -> PreLaTeX
usepackage [Text
"T1"] Text
"fontenc"
, [Text] -> Text -> PreLaTeX
usepackage [Text
"utf8"] Text
"inputenc"
, [Text] -> Text -> PreLaTeX
usepackage [] Text
"fancyhdr"
, [Text] -> Text -> PreLaTeX
usepackage [] Text
"lastpage"
, [Text] -> Text -> PreLaTeX
usepackage [] Text
"multirow"
, [Text] -> Text -> PreLaTeX
usepackage [Text
"ngerman"] Text
"babel"
, [Text] -> Text -> PreLaTeX
usepackage [Text
"htt"] Text
"hyphenat"
, [Text] -> Text -> PreLaTeX
usepackage [Text
"table"] Text
"xcolor"
, [Text] -> Text -> PreLaTeX
usepackage [] Text
"makecell"
, [Text] -> Text -> PreLaTeX
usepackage [] Text
"color"
, Text -> PreLaTeX
IRaw Text
"\\pagestyle{fancy}"
, Text -> PreLaTeX
IRaw Text
"\\fancyhf{}"
, Text -> PreLaTeX
IRaw Text
"\\setlist[enumerate]{align=left}"
, PreLaTeX
setlistdepth
, PreLaTeX
renewlist
]
getIdentifier :: IdentifierFormat -> Int -> Int -> T.Text
getIdentifier :: IdentifierFormat -> Int -> Int -> Text
getIdentifier (FormatString []) Int
_ Int
_ = Text
forall a. Monoid a => a
mempty
getIdentifier (FormatString (StringAtom String
s : [FormatAtom EnumStyle]
rest)) Int
i Int
ii =
String -> Text
T.pack String
s Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> IdentifierFormat -> Int -> Int -> Text
getIdentifier ([FormatAtom EnumStyle] -> IdentifierFormat
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom EnumStyle]
rest) Int
i Int
ii
getIdentifier (FormatString (PlaceholderAtom EnumStyle
a : [FormatAtom EnumStyle]
rest)) Int
i Int
ii =
case EnumStyle
a of
EnumStyle
Arabic -> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
i) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> IdentifierFormat -> Int -> Int -> Text
getIdentifier ([FormatAtom EnumStyle] -> IdentifierFormat
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom EnumStyle]
rest) Int
i Int
ii
EnumStyle
AlphabeticLower ->
String -> Text
T.pack [Int -> Char
chr ((Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
27 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
97)] Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> IdentifierFormat -> Int -> Int -> Text
getIdentifier ([FormatAtom EnumStyle] -> IdentifierFormat
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom EnumStyle]
rest) Int
i Int
ii
EnumStyle
AlphabeticUpper ->
String -> Text
T.pack [Int -> Char
chr ((Int
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
27 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
65)] Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> IdentifierFormat -> Int -> Int -> Text
getIdentifier ([FormatAtom EnumStyle] -> IdentifierFormat
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom EnumStyle]
rest) Int
i Int
ii
getIdentifier (FormatString (InsertedPlaceholderAtom EnumStyle
a : [FormatAtom EnumStyle]
rest)) Int
i Int
ii =
case EnumStyle
a of
EnumStyle
Arabic -> String -> Text
T.pack (Int -> String
forall a. Show a => a -> String
show Int
ii) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> IdentifierFormat -> Int -> Int -> Text
getIdentifier ([FormatAtom EnumStyle] -> IdentifierFormat
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom EnumStyle]
rest) Int
i Int
ii
EnumStyle
AlphabeticLower ->
String -> Text
T.pack [Int -> Char
chr ((Int
ii Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
27 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
97)] Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> IdentifierFormat -> Int -> Int -> Text
getIdentifier ([FormatAtom EnumStyle] -> IdentifierFormat
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom EnumStyle]
rest) Int
i Int
ii
EnumStyle
AlphabeticUpper ->
String -> Text
T.pack [Int -> Char
chr ((Int
ii Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
27 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
65)] Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> IdentifierFormat -> Int -> Int -> Text
getIdentifier ([FormatAtom EnumStyle] -> IdentifierFormat
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom EnumStyle]
rest) Int
i Int
ii
getEnumStyle :: IdentifierFormat -> KeyFormat -> T.Text
getEnumStyle :: IdentifierFormat -> KeyFormat -> Text
getEnumStyle IdentifierFormat
ident KeyFormat
key = Text
"label=" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> KeyFormat -> Text
buildKey (IdentifierFormat -> Text
getEnumIdentifier' IdentifierFormat
ident) KeyFormat
key
where
buildKey :: T.Text -> KeyFormat -> T.Text
buildKey :: Text -> KeyFormat -> Text
buildKey Text
_ ((FormatString [])) = Text
forall a. Monoid a => a
mempty
buildKey Text
i ((FormatString (StringAtom String
s : [FormatAtom KeyPlaceholderAtom]
rest))) =
String -> Text
T.pack String
s Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> KeyFormat -> Text
buildKey Text
i ([FormatAtom KeyPlaceholderAtom] -> KeyFormat
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom KeyPlaceholderAtom]
rest)
buildKey
Text
i
((FormatString (PlaceholderAtom KeyPlaceholderAtom
KeyIdentifierPlaceholder : [FormatAtom KeyPlaceholderAtom]
rest))) =
Text
i Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> KeyFormat -> Text
buildKey Text
i ([FormatAtom KeyPlaceholderAtom] -> KeyFormat
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom KeyPlaceholderAtom]
rest)
buildKey
Text
_
((FormatString (InsertedPlaceholderAtom KeyPlaceholderAtom
KeyIdentifierPlaceholder : [FormatAtom KeyPlaceholderAtom]
_))) = Text
forall a. HasCallStack => a
undefined
getEnumIdentifier' :: IdentifierFormat -> T.Text
getEnumIdentifier' :: IdentifierFormat -> Text
getEnumIdentifier' (FormatString []) = Text
forall a. Monoid a => a
mempty
getEnumIdentifier' (FormatString (StringAtom String
s : [FormatAtom EnumStyle]
rest)) =
String -> Text
T.pack String
s Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> IdentifierFormat -> Text
getEnumIdentifier' ([FormatAtom EnumStyle] -> IdentifierFormat
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom EnumStyle]
rest)
getEnumIdentifier' (FormatString (PlaceholderAtom EnumStyle
a : [FormatAtom EnumStyle]
rest)) =
case EnumStyle
a of
EnumStyle
Arabic -> Text
"\\arabic*" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> IdentifierFormat -> Text
getEnumIdentifier' ([FormatAtom EnumStyle] -> IdentifierFormat
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom EnumStyle]
rest)
EnumStyle
AlphabeticLower -> Text
"\\alph*" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> IdentifierFormat -> Text
getEnumIdentifier' ([FormatAtom EnumStyle] -> IdentifierFormat
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom EnumStyle]
rest)
EnumStyle
AlphabeticUpper -> Text
"\\Alph*" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> IdentifierFormat -> Text
getEnumIdentifier' ([FormatAtom EnumStyle] -> IdentifierFormat
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom EnumStyle]
rest)
getEnumIdentifier' (FormatString (InsertedPlaceholderAtom EnumStyle
a : [FormatAtom EnumStyle]
rest)) =
case EnumStyle
a of
EnumStyle
Arabic -> Text
"\\arabic*" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> IdentifierFormat -> Text
getEnumIdentifier' ([FormatAtom EnumStyle] -> IdentifierFormat
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom EnumStyle]
rest)
EnumStyle
AlphabeticLower -> Text
"\\alph*" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> IdentifierFormat -> Text
getEnumIdentifier' ([FormatAtom EnumStyle] -> IdentifierFormat
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom EnumStyle]
rest)
EnumStyle
AlphabeticUpper -> Text
"\\Alph*" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> IdentifierFormat -> Text
getEnumIdentifier' ([FormatAtom EnumStyle] -> IdentifierFormat
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom EnumStyle]
rest)
formatHeaderFooterItem
:: PreLaTeX -> PreLaTeX -> PreLaTeX -> HeaderFooterItemFormat -> PreLaTeX
PreLaTeX
superTitle PreLaTeX
title PreLaTeX
date (HeaderFooterItemFormat FontSize
fontsize [FontStyle]
styles FormatString HeaderFooterFormatAtom
fstring) =
FontSize -> PreLaTeX -> PreLaTeX
forall a. Stylable a => a -> PreLaTeX -> PreLaTeX
applyTextStyle FontSize
fontsize (PreLaTeX -> PreLaTeX) -> PreLaTeX -> PreLaTeX
forall a b. (a -> b) -> a -> b
$
(FontStyle -> (PreLaTeX -> PreLaTeX) -> PreLaTeX -> PreLaTeX)
-> (PreLaTeX -> PreLaTeX) -> [FontStyle] -> PreLaTeX -> PreLaTeX
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\FontStyle
style PreLaTeX -> PreLaTeX
acc -> PreLaTeX -> PreLaTeX
acc (PreLaTeX -> PreLaTeX)
-> (PreLaTeX -> PreLaTeX) -> PreLaTeX -> PreLaTeX
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FontStyle -> PreLaTeX -> PreLaTeX
forall a. Stylable a => a -> PreLaTeX -> PreLaTeX
applyTextStyle FontStyle
style) PreLaTeX -> PreLaTeX
forall a. a -> a
id [FontStyle]
styles (PreLaTeX -> PreLaTeX) -> PreLaTeX -> PreLaTeX
forall a b. (a -> b) -> a -> b
$
FormatString HeaderFooterFormatAtom -> PreLaTeX
formatHeaderFooterFstring FormatString HeaderFooterFormatAtom
fstring
where
formatHeaderFooterFstring :: FormatString HeaderFooterFormatAtom -> PreLaTeX
formatHeaderFooterFstring :: FormatString HeaderFooterFormatAtom -> PreLaTeX
formatHeaderFooterFstring (FormatString []) = PreLaTeX
forall a. Monoid a => a
mempty
formatHeaderFooterFstring (FormatString (StringAtom String
s : [FormatAtom HeaderFooterFormatAtom]
rest)) =
[PreLaTeX] -> PreLaTeX
ISequence ((Char -> PreLaTeX) -> String -> [PreLaTeX]
forall a b. (a -> b) -> [a] -> [b]
map Char -> PreLaTeX
replace String
s) PreLaTeX -> PreLaTeX -> PreLaTeX
forall a. Semigroup a => a -> a -> a
<> FormatString HeaderFooterFormatAtom -> PreLaTeX
formatHeaderFooterFstring ([FormatAtom HeaderFooterFormatAtom]
-> FormatString HeaderFooterFormatAtom
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom HeaderFooterFormatAtom]
rest)
where
replace :: Char -> PreLaTeX
replace Char
'\n' = PreLaTeX
linebreak
replace Char
c = Text -> PreLaTeX
IText (String -> Text
T.pack [Char
c])
formatHeaderFooterFstring (FormatString (PlaceholderAtom HeaderFooterFormatAtom
a : [FormatAtom HeaderFooterFormatAtom]
rest)) =
case HeaderFooterFormatAtom
a of
HeaderFooterFormatAtom
HeaderFooterSuperTitleAtom -> PreLaTeX
superTitle PreLaTeX -> PreLaTeX -> PreLaTeX
forall a. Semigroup a => a -> a -> a
<> FormatString HeaderFooterFormatAtom -> PreLaTeX
formatHeaderFooterFstring ([FormatAtom HeaderFooterFormatAtom]
-> FormatString HeaderFooterFormatAtom
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom HeaderFooterFormatAtom]
rest)
HeaderFooterFormatAtom
HeaderFooterTitleAtom -> PreLaTeX
title PreLaTeX -> PreLaTeX -> PreLaTeX
forall a. Semigroup a => a -> a -> a
<> FormatString HeaderFooterFormatAtom -> PreLaTeX
formatHeaderFooterFstring ([FormatAtom HeaderFooterFormatAtom]
-> FormatString HeaderFooterFormatAtom
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom HeaderFooterFormatAtom]
rest)
HeaderFooterFormatAtom
HeaderFooterDateAtom -> PreLaTeX
date PreLaTeX -> PreLaTeX -> PreLaTeX
forall a. Semigroup a => a -> a -> a
<> FormatString HeaderFooterFormatAtom -> PreLaTeX
formatHeaderFooterFstring ([FormatAtom HeaderFooterFormatAtom]
-> FormatString HeaderFooterFormatAtom
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom HeaderFooterFormatAtom]
rest)
HeaderFooterFormatAtom
HeaderFooterCurPageNumAtom -> Text -> PreLaTeX
IRaw Text
"\\thepage" PreLaTeX -> PreLaTeX -> PreLaTeX
forall a. Semigroup a => a -> a -> a
<> FormatString HeaderFooterFormatAtom -> PreLaTeX
formatHeaderFooterFstring ([FormatAtom HeaderFooterFormatAtom]
-> FormatString HeaderFooterFormatAtom
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom HeaderFooterFormatAtom]
rest)
HeaderFooterFormatAtom
HeaderFooterLastPageNumAtom -> Text -> PreLaTeX
IRaw Text
"\\pageref{LastPage}" PreLaTeX -> PreLaTeX -> PreLaTeX
forall a. Semigroup a => a -> a -> a
<> FormatString HeaderFooterFormatAtom -> PreLaTeX
formatHeaderFooterFstring ([FormatAtom HeaderFooterFormatAtom]
-> FormatString HeaderFooterFormatAtom
forall a. [FormatAtom a] -> FormatString a
FormatString [FormatAtom HeaderFooterFormatAtom]
rest)
formatHeaderFooterFstring (FormatString (InsertedPlaceholderAtom HeaderFooterFormatAtom
_ : [FormatAtom HeaderFooterFormatAtom]
_)) = PreLaTeX
forall a. HasCallStack => a
undefined