packages feed

lambdatex 0.1.0.4 → 0.1.1.0

raw patch · 5 files changed

+72/−19 lines, 5 filesdep ~HaTeXdep ~asyncdep ~directory

Dependency ranges changed: HaTeX, async, directory, transformers

Files

lambdatex.cabal view
@@ -1,5 +1,5 @@ name:                lambdatex-version:             0.1.0.4+version:             0.1.1.0 synopsis:            Type-Safe LaTeX EDSL description:            ΛTeX, pronounced 'LambdaTeX' is a Haskell EDSL that adds type-safety to LaTeX.@@ -35,13 +35,13 @@                        Text.LaTeX.LambdaTeX.Types                        Text.LaTeX.LambdaTeX.Utils   build-depends:       base             >= 4.8      && < 5.0-                     , HaTeX            >= 3.16     && < 3.17+                     , HaTeX            >= 3.16     && < 3.18                      , mtl              >= 2.2      && < 2.3                      , text             >= 1.2      && < 1.3                      , containers       >= 0.5      && < 0.6-                     , transformers     >= 0.4      && < 0.5+                     , transformers     >= 0.4      && < 0.6                      , directory        >= 1.2      && < 1.3-                     , async            >= 2.0      && < 2.1+                     , async            >= 2.0      && < 2.2   ghc-options:        -Wall                       -fwarn-unused-imports                       -fwarn-incomplete-patterns
src/Text/LaTeX/LambdaTeX.hs view
@@ -23,7 +23,7 @@      ) where -import           Control.Monad                           (forM_)+import           Control.Monad                           (forM_, void) import           Control.Monad.IO.Class                  (MonadIO (..))  import           Control.Concurrent.Async                (async, wait)@@ -70,7 +70,7 @@             T.appendFile mainBibFile $ renderReferences refs      let performAction (name, action) = do-            action+            void action             putStrLn $ "Job " ++ name ++ " done."      -- Perform all the IO actions asynchronously@@ -94,7 +94,12 @@ execLambdaTeXT :: Monad m => ΛTeXT m a -> GenerationConfig -> m ([ΛError], LaTeX, [Reference], [(String, IO ())]) execLambdaTeXT func conf = do     ((_,latex), _, output) <- runΛTeX func (ΛConfig $ generationSelection conf) initState-    let result = injectPackageDependencies (S.toList $ outputPackageDependencies output) latex++    let mresult = injectPackageDependencies (S.toList $ outputPackageDependencies output) latex+    let (extraErrs, result) = case mresult of+            Nothing -> ([IncompatibleDependencies], latex)+            Just res -> ([], res)+     let refs = S.toList $ outputExternalReferences output     let actions = outputActions output @@ -105,7 +110,7 @@      let referss = map ReferenceMissing $ S.toList diff -    return (referss, result, refs, actions)+    return (extraErrs ++ referss, result, refs, actions)    where     initState :: ΛState
src/Text/LaTeX/LambdaTeX/Error.hs view
@@ -2,5 +2,7 @@  import           Data.Text (Text) -data ΛError = ReferenceMissing Text+data ΛError+    = ReferenceMissing Text+    | IncompatibleDependencies     deriving (Show, Eq)
src/Text/LaTeX/LambdaTeX/Package/Internal.hs view
@@ -1,5 +1,9 @@+{-# LANGUAGE OverloadedStrings #-} module Text.LaTeX.LambdaTeX.Package.Internal where +import           Control.Monad+import           Data.List+ import           Text.LaTeX.Base.Syntax  import           Text.LaTeX.LambdaTeX.Package.Types@@ -7,18 +11,60 @@  -- | Inject package dependencies into a given LaTeX document. --   This is done by top-level functions in @Text.LaTeX.LambdaTeX@ automatically-injectPackageDependencies :: [PackageDep] -> LaTeX -> LaTeX-injectPackageDependencies ps = go-    -- We're looking for this: TeXComm "documentclass" ...+injectPackageDependencies :: [PackageDep] -> LaTeX -> Maybe LaTeX+injectPackageDependencies packages latex = do+    ps <- reorderPackages packages+    let packageDecs = mconcat $ map (\(PackageDep name args) -> usepackage args name) ps+    pure (inject packageDecs latex)   where-    -- We have to go looking through the LaTeX :(-    go t@(TeXComm "documentclass" _) = TeXSeq t packages-    go (TeXSeq t1 t2) = TeXSeq (go t1) (go t2)-    go c = c+    inject ps = go+      where+        -- We're looking for this: TeXComm "documentclass" ...+        -- We have to go looking through the LaTeX :(+        go t@(TeXComm "documentclass" _) = TeXSeq t ps+        go (TeXSeq t1 t2) = TeXSeq (go t1) (go t2)+        go c = c -    packages :: LaTeX-    packages = mconcat $ map (\(PackageDep name args) -> usepackage args name) ps ++reorderPackages :: [PackageDep] -> Maybe [PackageDep]+reorderPackages deps = do+    bestEffort <- foldM (flip reorderToSatisfy) deps allPackageCombinationRules+    if all (`ruleIsSatisfied` bestEffort) allPackageCombinationRules+    then Just bestEffort+    else Nothing++data PackageRule+    = PackageOrder Text Text+    deriving (Show, Eq)++-- Yes it's dumb, but it works for now.+reorderToSatisfy :: PackageRule -> [PackageDep] -> Maybe [PackageDep]+reorderToSatisfy (PackageOrder n1 n2) ps = Just $+    case (,) <$> elemIndex n1 names <*> elemIndex n2 names of+        Nothing -> ps+        Just (ix1, ix2) ->+            if ix1 < ix2+            then ps+            else (ps !! ix1)+                : (ps !! ix2)+                : map snd (filter (\(ix, _) -> ix /= ix1 && ix /= ix2) (zip [0..] ps))+  where names = map packageDepName ps++ruleIsSatisfied :: PackageRule -> [PackageDep] -> Bool+ruleIsSatisfied (PackageOrder n1 n2) ps+    = case (<) <$> elemIndex n1 names <*> elemIndex n2 names of+        Just False -> False+        _ -> True+  where names = map packageDepName ps++allPackageCombinationRules :: [PackageRule]+allPackageCombinationRules =+    [ mintedLibertineRule+    ]++mintedLibertineRule :: PackageRule+mintedLibertineRule = PackageOrder "minted" "libertine"  -- | Redefinition of @usepackage@ to use Text --   Don't use this directly, use the packageDep instead!
src/Text/LaTeX/LambdaTeX/Types.hs view
@@ -80,7 +80,7 @@  -- TODO(kerckhove) Also instantiate floating? -runΛTeX :: Monad m => ΛTeXT m a -> ΛConfig -> ΛState -> m ((a, LaTeX), ΛState, ΛOutput)+runΛTeX :: ΛTeXT m a -> ΛConfig -> ΛState -> m ((a, LaTeX), ΛState, ΛOutput) runΛTeX func conf state = runRWST (runLaTeXT $ unwrapΛTeXT func) conf state  instance MonadTrans ΛTeXT where