{-# LANGUAGE DoAndIfThenElse #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# OPTIONS_GHC -w #-}
module Uniform.Latex
( module Uniform.Latex
) where
import Uniform.PandocImports
import Text.DocTemplates as DocTemplates
import Text.DocLayout (render)
import UniformBase
import Data.Aeson
data LatexParam = LatexParam
{ LatexParam -> Text
latTitle :: Text
, LatexParam -> Text
latAuthor :: Text
, LatexParam -> Text
latAbstract :: Text
, LatexParam -> Text
latLanguage :: Text
, LatexParam -> Text
latFn :: Text
, LatexParam -> Text
latBakedDir :: Text
, LatexParam -> Text
latDainoVersion :: Text
, LatexParam -> Text
latBibliography :: Text
, LatexParam -> Text
latBiblioTitle :: Text
, LatexParam -> Text
latStyle :: Text
, LatexParam -> Text
latReferences :: Text
, LatexParam -> Text
latBook :: Text
, LatexParam -> IndexEntry
latIndex :: IndexEntry
, LatexParam -> Text
latContent :: Text
}
deriving (LatexParam -> LatexParam -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LatexParam -> LatexParam -> Bool
$c/= :: LatexParam -> LatexParam -> Bool
== :: LatexParam -> LatexParam -> Bool
$c== :: LatexParam -> LatexParam -> Bool
Eq, Eq LatexParam
LatexParam -> LatexParam -> Bool
LatexParam -> LatexParam -> Ordering
LatexParam -> LatexParam -> LatexParam
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: LatexParam -> LatexParam -> LatexParam
$cmin :: LatexParam -> LatexParam -> LatexParam
max :: LatexParam -> LatexParam -> LatexParam
$cmax :: LatexParam -> LatexParam -> LatexParam
>= :: LatexParam -> LatexParam -> Bool
$c>= :: LatexParam -> LatexParam -> Bool
> :: LatexParam -> LatexParam -> Bool
$c> :: LatexParam -> LatexParam -> Bool
<= :: LatexParam -> LatexParam -> Bool
$c<= :: LatexParam -> LatexParam -> Bool
< :: LatexParam -> LatexParam -> Bool
$c< :: LatexParam -> LatexParam -> Bool
compare :: LatexParam -> LatexParam -> Ordering
$ccompare :: LatexParam -> LatexParam -> Ordering
Ord, ReadPrec [LatexParam]
ReadPrec LatexParam
Int -> ReadS LatexParam
ReadS [LatexParam]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LatexParam]
$creadListPrec :: ReadPrec [LatexParam]
readPrec :: ReadPrec LatexParam
$creadPrec :: ReadPrec LatexParam
readList :: ReadS [LatexParam]
$creadList :: ReadS [LatexParam]
readsPrec :: Int -> ReadS LatexParam
$creadsPrec :: Int -> ReadS LatexParam
Read, Int -> LatexParam -> ShowS
[LatexParam] -> ShowS
LatexParam -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [LatexParam] -> ShowS
$cshowList :: [LatexParam] -> ShowS
show :: LatexParam -> FilePath
$cshow :: LatexParam -> FilePath
showsPrec :: Int -> LatexParam -> ShowS
$cshowsPrec :: Int -> LatexParam -> ShowS
Show, forall x. Rep LatexParam x -> LatexParam
forall x. LatexParam -> Rep LatexParam x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LatexParam x -> LatexParam
$cfrom :: forall x. LatexParam -> Rep LatexParam x
Generic, [LatexParam] -> Encoding
[LatexParam] -> Value
LatexParam -> Encoding
LatexParam -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [LatexParam] -> Encoding
$ctoEncodingList :: [LatexParam] -> Encoding
toJSONList :: [LatexParam] -> Value
$ctoJSONList :: [LatexParam] -> Value
toEncoding :: LatexParam -> Encoding
$ctoEncoding :: LatexParam -> Encoding
toJSON :: LatexParam -> Value
$ctoJSON :: LatexParam -> Value
ToJSON)
instance Zeros LatexParam where
zero :: LatexParam
zero = Text
-> Text
-> Text
-> Text
-> Text
-> Text
-> Text
-> Text
-> Text
-> Text
-> Text
-> Text
-> IndexEntry
-> Text
-> LatexParam
LatexParam forall z. Zeros z => z
zero forall z. Zeros z => z
zero forall z. Zeros z => z
zero forall z. Zeros z => z
zero forall z. Zeros z => z
zero forall z. Zeros z => z
zero forall z. Zeros z => z
zero forall z. Zeros z => z
zero forall z. Zeros z => z
zero forall z. Zeros z => z
zero
forall z. Zeros z => z
zero forall z. Zeros z => z
zero forall z. Zeros z => z
zero forall z. Zeros z => z
zero
data IndexEntry = IndexEntry
{
IndexEntry -> FilePath
ixfn :: FilePath
,
IndexEntry -> FilePath
link :: FilePath
, IndexEntry -> Text
title :: Text
, IndexEntry -> Text
abstract :: Text
, IndexEntry -> Text
author :: Text
, IndexEntry -> Text
date :: Text
, IndexEntry -> Text
content :: Text
, IndexEntry -> [IndexEntry]
dirEntries :: [IndexEntry]
, IndexEntry -> [IndexEntry]
fileEntries :: [IndexEntry]
, :: Int
} deriving (Int -> IndexEntry -> ShowS
[IndexEntry] -> ShowS
IndexEntry -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [IndexEntry] -> ShowS
$cshowList :: [IndexEntry] -> ShowS
show :: IndexEntry -> FilePath
$cshow :: IndexEntry -> FilePath
showsPrec :: Int -> IndexEntry -> ShowS
$cshowsPrec :: Int -> IndexEntry -> ShowS
Show, ReadPrec [IndexEntry]
ReadPrec IndexEntry
Int -> ReadS IndexEntry
ReadS [IndexEntry]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IndexEntry]
$creadListPrec :: ReadPrec [IndexEntry]
readPrec :: ReadPrec IndexEntry
$creadPrec :: ReadPrec IndexEntry
readList :: ReadS [IndexEntry]
$creadList :: ReadS [IndexEntry]
readsPrec :: Int -> ReadS IndexEntry
$creadsPrec :: Int -> ReadS IndexEntry
Read, IndexEntry -> IndexEntry -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IndexEntry -> IndexEntry -> Bool
$c/= :: IndexEntry -> IndexEntry -> Bool
== :: IndexEntry -> IndexEntry -> Bool
$c== :: IndexEntry -> IndexEntry -> Bool
Eq, Eq IndexEntry
IndexEntry -> IndexEntry -> Bool
IndexEntry -> IndexEntry -> Ordering
IndexEntry -> IndexEntry -> IndexEntry
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: IndexEntry -> IndexEntry -> IndexEntry
$cmin :: IndexEntry -> IndexEntry -> IndexEntry
max :: IndexEntry -> IndexEntry -> IndexEntry
$cmax :: IndexEntry -> IndexEntry -> IndexEntry
>= :: IndexEntry -> IndexEntry -> Bool
$c>= :: IndexEntry -> IndexEntry -> Bool
> :: IndexEntry -> IndexEntry -> Bool
$c> :: IndexEntry -> IndexEntry -> Bool
<= :: IndexEntry -> IndexEntry -> Bool
$c<= :: IndexEntry -> IndexEntry -> Bool
< :: IndexEntry -> IndexEntry -> Bool
$c< :: IndexEntry -> IndexEntry -> Bool
compare :: IndexEntry -> IndexEntry -> Ordering
$ccompare :: IndexEntry -> IndexEntry -> Ordering
Ord, forall x. Rep IndexEntry x -> IndexEntry
forall x. IndexEntry -> Rep IndexEntry x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IndexEntry x -> IndexEntry
$cfrom :: forall x. IndexEntry -> Rep IndexEntry x
Generic, IndexEntry
Eq IndexEntry => IndexEntry -> Bool
forall z.
z -> (Eq z => z -> Bool) -> (Eq z => z -> Bool) -> Zeros z
notZero :: Eq IndexEntry => IndexEntry -> Bool
$cnotZero :: Eq IndexEntry => IndexEntry -> Bool
isZero :: Eq IndexEntry => IndexEntry -> Bool
$cisZero :: Eq IndexEntry => IndexEntry -> Bool
zero :: IndexEntry
$czero :: IndexEntry
Zeros)
instance ToJSON IndexEntry
instance FromJSON IndexEntry
tex2latex :: NoticeLevel -> Path Abs Dir -> LatexParam -> Path Abs File -> ErrIO Text
tex2latex :: NoticeLevel
-> Path Abs Dir -> LatexParam -> Path Abs File -> ErrIO Text
tex2latex NoticeLevel
debug Path Abs Dir
webroot LatexParam
latpar Path Abs File
templFn = do
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (NoticeLevel -> Bool
inform NoticeLevel
debug) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadIO m => [Text] -> m ()
putIOwords [Text
"tex2latex start for latFn", LatexParam -> Text
latFn LatexParam
latpar]
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (NoticeLevel -> Bool
inform NoticeLevel
debug) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadIO m => [Text] -> m ()
putIOwords [Text
"tex2latex template fn", forall {a}. Show a => a -> Text
showT Path Abs File
templFn]
Either FilePath (Template Text)
templ1<- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a.
TemplateTarget a =>
FilePath -> IO (Either FilePath (Template a))
compileTemplateFile (forall b t. Path b t -> FilePath
toFilePath Path Abs File
templFn)
let templ3 :: Template Text
templ3 = case Either FilePath (Template Text)
templ1 of
Left FilePath
msg -> forall a. [Text] -> a
errorT [Text
"applyTemplate4 error", FilePath -> Text
s2t FilePath
msg]
Right Template Text
tmp2 -> Template Text
tmp2
let latparJ :: Value
latparJ = forall a. ToJSON a => a -> Value
toJSON LatexParam
latpar
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (NoticeLevel -> Bool
inform NoticeLevel
debug) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadIO m => [Text] -> m ()
putIOwords [Text
"tex2latex latparJ", forall {a}. Show a => a -> Text
showT Value
latparJ]
let doc1 :: Doc Text
doc1 = forall a b.
(TemplateTarget a, ToContext a b) =>
Template a -> b -> Doc a
renderTemplate Template Text
templ3 Value
latparJ
let doc2 :: Text
doc2 = forall a. HasChars a => Maybe Int -> Doc a -> a
render forall a. Maybe a
Nothing Doc Text
doc1
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (NoticeLevel -> Bool
inform NoticeLevel
debug) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadIO m => [Text] -> m ()
putIOwords [Text
"tex2latex result", Text
doc2]
forall (m :: * -> *) a. Monad m => a -> m a
return Text
doc2
latexLangConversion :: Text -> Text
latexLangConversion :: Text -> Text
latexLangConversion Text
inlang =
case Text
lang2 of
Text
"de" -> Text
"ngerman"
Text
"en" -> Text
"english"
Text
_ -> Text
"english"
where
lang2 :: Text
lang2 = forall a. CharChains a => Int -> a -> a
take' Int
2 Text
inlang