packages feed

typst 0.5.0.5 → 0.6

raw patch · 6 files changed

+81/−46 lines, 6 files

Files

CHANGELOG.md view
@@ -1,5 +1,22 @@ # Revision history for typst-hs +## 0.6++  * Recognize figure.caption function (#52).++  * Allow defined identifiers to override math defaults (#51).+    Previously we evaluated all math in a special environment that+    shadowed any user-defined functions with the same-named functions+    from the math or sym modules. This change gives user-defined identifiers+    priority over the math defaults, allowing things like `bb` to be+    overridden.++  * Typst.Types: EvalState now has two new fields, `evalMathIdentifiers` and+    `evalStandardIdentifiers`. `evalIdentifiers` is now just for user-defined+    identifiers. [API change]++  * Don't implicitly load sys module for math.+ ## 0.5.0.5    * Allow numbers like `1.` in math mode (#50).
src/Typst/Evaluate.hs view
@@ -32,8 +32,7 @@ import Text.Parsec import Typst.Bind (destructuringBind) import Typst.Methods (getMethod)-import Typst.Module.Standard (loadFileText, standardModule, symModule,-                              sysModule)+import Typst.Module.Standard (loadFileText, standardModule, symModule) import Typst.Module.Math (mathModule) import Typst.MathClass (mathClassOf, MathClass(Relation)) import Typst.Parse (parseTypst)@@ -68,7 +67,10 @@  initialEvalState :: EvalState m initialEvalState =-  emptyEvalState { evalIdentifiers = [(BlockScope, standardModule')] }+  emptyEvalState { evalIdentifiers = [(BlockScope, mempty)]+                 , evalMathIdentifiers = [(BlockScope, mathModule <> symModule)]+                 , evalStandardIdentifiers = [(BlockScope, standardModule')]+                 }   where     standardModule' = M.insert "eval" evalFunction standardModule     evalFunction = makeFunction $ do@@ -240,13 +242,9 @@                 [("level", VInteger (fromIntegral level))]           }     Equation display ms -> inBlock BlockScope $ do-      importModule mathModule-      importModule symModule-      importModule sysModule       oldMath <- evalMath <$> getState       updateState $ \st -> st {evalMath = True}       content <- pInnerContents ms-      updateState $ \st -> st {evalMath = oldMath}       element         "equation"         Arguments@@ -256,7 +254,7 @@                 [ ("block", VBoolean display),                   ("numbering", VNone)                 ]-          }+          } <* updateState (\st -> st {evalMath = oldMath})     MFrac numexp denexp -> do       let handleParens (MGroup (Just "(") (Just ")") xs) = MGroup Nothing Nothing xs           handleParens x = x@@ -1100,9 +1098,7 @@   case identifiers of     [] -> fail "Empty evalIdentifiers"     ((s, i) : is) -> updateState $ \st ->-      st-        { evalIdentifiers = (s, M.insert ident val i) : is-        }+      st { evalIdentifiers = (s, M.insert ident val i) : is }  updateIdentifier :: Monad m => Identifier -> Val -> MP m () updateIdentifier ident val = do
src/Typst/Module/Standard.hs view
@@ -232,7 +232,11 @@   [ makeElement Nothing "bibliography" [("path", One (TString :|: TArray))],     makeElement Nothing "cite" [("key", One TLabel)],     makeElement Nothing "document" [],-    makeElement Nothing "figure" [("body", One TContent)],+    makeElementWithScope+      Nothing+      "figure"+      [("body", One TContent)]+      [makeElement (Just "figure") "caption" [("body", One TContent)]],     makeElement Nothing "heading" [("body", One TContent)],     makeElement Nothing "quote" [("body", One TContent)],     makeElement Nothing "layout" [("func", One TFunction)],@@ -643,7 +647,10 @@  initialEvalState :: MonadFail m => EvalState m initialEvalState =-  emptyEvalState { evalIdentifiers = [(BlockScope, standardModule)] }+  emptyEvalState { evalIdentifiers = [(BlockScope, mempty)]+                 , evalMathIdentifiers = [(BlockScope, mathModule <> symModule)]+                 , evalStandardIdentifiers = [(BlockScope, standardModule)]+                 }  -- mDigitsRev, mDigits from the unmaintained digits package -- https://hackage.haskell.org/package/digits-0.3.1
src/Typst/Types.hs view
@@ -606,6 +606,12 @@ data EvalState m = EvalState   { evalIdentifiers :: [(Scope, M.Map Identifier Val)],     -- first item is current block, then superordinate block, etc.+    -- The standard identifiers and the identifiers that+    -- are imported by default into math contexts are special,+    -- since both can be overridden by user-defined identifiers.+    -- So, we store them separately.+    evalStandardIdentifiers :: [(Scope, M.Map Identifier Val)],+    evalMathIdentifiers :: [(Scope, M.Map Identifier Val)],     evalCounters :: M.Map Counter Integer,     evalMath :: Bool,     evalShowRules :: [ShowRule],@@ -618,6 +624,8 @@ emptyEvalState :: EvalState m emptyEvalState = EvalState     { evalIdentifiers = [],+      evalStandardIdentifiers = [],+      evalMathIdentifiers = [],       evalCounters = mempty,       evalMath = False,       evalShowRules = [],@@ -977,4 +985,12 @@       go ((_, i) : is) = case M.lookup ident i of         Just v -> pure v         Nothing -> go is-  getState >>= go . evalIdentifiers+  identifiers <- evalIdentifiers <$> getState+  mathIdentifiers <- evalMathIdentifiers <$> getState+  standardIdentifiers <- evalStandardIdentifiers <$> getState+  math <- evalMath <$> getState+  go $ case identifiers of+         -- in math mode, we insert the sym and math modules right before+         -- the final module (standard module)+         (_:_) | math -> identifiers ++ mathIdentifiers ++ standardIdentifiers+         _ -> identifiers ++ standardIdentifiers
test/out/bugs/math-realize-02.out view
@@ -341,21 +341,21 @@                  text(body: [Inline ]),                   math.equation(block: false,                                 body: { text(body: [2]), -                                       text(body: [|]), -                                       text(body: [(]), -                                       text(body: [α]), -                                       text(body: [,]), -                                       math.lr(body: ({ [(], -                                                        text(body: [M]), -                                                        text(body: [+]), -                                                        math.equation(block: false, -                                                                      body: { text(body: [a]), -                                                                              math.attach(b: none, -                                                                                          base: text(body: [b]), -                                                                                          t: text(body: [2])) }, -                                                                      numbering: none), -                                                        [)] })), -                                       text(body: [)]) }, +                                       math.equation(block: true, +                                                     body: { text(body: [α]), +                                                             math.attach(b: none, +                                                                         base: math.lr(body: ({ [(], +                                                                                                text(body: [M]), +                                                                                                text(body: [+]), +                                                                                                math.equation(block: false, +                                                                                                              body: { text(body: [a]), +                                                                                                                      math.attach(b: none, +                                                                                                                                  base: text(body: [b]), +                                                                                                                                  t: text(body: [2])) }, +                                                                                                              numbering: none), +                                                                                                [)] })), +                                                                         t: text(body: [2])) }, +                                                     numbering: none) },                                 numbering: none),                   text(body: [.]),                   parbreak(), @@ -409,21 +409,21 @@ ]),                   math.equation(block: true,                                 body: { text(body: [2]), -                                       text(body: [|]), -                                       text(body: [(]), -                                       text(body: [α]), -                                       text(body: [,]), -                                       math.lr(body: ({ [(], -                                                        text(body: [M]), -                                                        text(body: [+]), -                                                        math.equation(block: false, -                                                                      body: { text(body: [a]), -                                                                              math.attach(b: none, -                                                                                          base: text(body: [b]), -                                                                                          t: text(body: [2])) }, -                                                                      numbering: none), -                                                        [)] })), -                                       text(body: [)]) }, +                                       math.equation(block: true, +                                                     body: { text(body: [α]), +                                                             math.attach(b: none, +                                                                         base: math.lr(body: ({ [(], +                                                                                                text(body: [M]), +                                                                                                text(body: [+]), +                                                                                                math.equation(block: false, +                                                                                                              body: { text(body: [a]), +                                                                                                                      math.attach(b: none, +                                                                                                                                  base: text(body: [b]), +                                                                                                                                  t: text(body: [2])) }, +                                                                                                              numbering: none), +                                                                                                [)] })), +                                                                         t: text(body: [2])) }, +                                                     numbering: none) },                                 numbering: none),                   text(body: [ ]), 
typst.cabal view
@@ -1,6 +1,6 @@ cabal-version:      2.4 name:               typst-version:            0.5.0.5+version:            0.6 synopsis:           Parsing and evaluating typst syntax. description:        A library for parsing and evaluating typst syntax.                     Typst (<https://typst.app>) is a document layout and@@ -27,7 +27,6 @@                     test/assets/files/*.txt                     test/assets/files/*.yaml                     test/assets/files/*.html-tested-with:        GHC == 8.10.7 || == 9.0.2 || == 9.2.7 || == 9.4.5 || == 9.6.2  source-repository head   type: git