packages feed

texmath 0.13 → 0.13.0.1

raw patch · 5 files changed

+40/−33 lines, 5 files

Files

changelog.md view
@@ -1,3 +1,11 @@+texmath (0.13.0.1)++  * TeX reader: fix parsing of primes (#273).+    We previously misparsed `a_i'` as `a_{i'}` rather than `{a_i}'`.++  * Typst writer: fix position of primes with ESubSup.+    In typst, unlike tex, the primes must come after the base.+ texmath (0.13)    * Add cancellation of terms for most formats. (#271, #251, #269).
src/Text/TeXMath/Readers/TeX.hs view
@@ -52,28 +52,22 @@  -- The parser -expr1 :: TP Exp-expr1 = do-  e <- expr2-  -- check for primes and add them as a subscript-  -- in TeX ' is shorthand for ^{\prime}-  primes <- many (char '\'')-  let getPrimes cs = case cs of-                       "" -> ""-                       "'" -> "\x2032"-                       "''" -> "\x2033"-                       "'''" -> "\x2034"-                       "''''" -> "\x2057"-                       _ -> "\x2057" ++ getPrimes (drop 4 cs)-  ignorable-  case getPrimes primes of-    "" -> return e-    cs -> return $ case e of-                     ESub b sub -> ESubsup b sub (ESymbol Pun (T.pack cs))-                     _ -> ESuper e (ESymbol Pun (T.pack cs))+primes :: TP Exp+primes = do+  ESymbol Pun . getPrimes <$> (many1 (char '\'') <* ignorable) -expr2 :: TP Exp-expr2 = choice+getPrimes :: [Char] -> Text+getPrimes cs =+  case cs of+    "" -> ""+    "'" -> "\x2032"+    "''" -> "\x2033"+    "'''" -> "\x2034"+    "''''" -> "\x2057"+    _ -> "\x2057" <> getPrimes (drop 4 cs)++expr1 :: TP Exp+expr1 = choice           [ inbraces           , variable           , number@@ -255,7 +249,7 @@     ctrlseq "operatorname"     -- these are slightly different but we won't worry about that here...     convertible <- (char '*' >> spaces >> return True) <|> return False-    tok' <- texSymbol <|> braces (manyExp expr2) <|> texChar+    tok' <- texSymbol <|> braces (manyExp expr1) <|> texChar     tok'' <- (EMathOperator <$> (expToOperatorName tok'))            <|> return (EStyled TextNormal [tok'])     return (tok'', convertible)@@ -613,8 +607,8 @@  subSup :: Maybe Bool -> Bool -> Exp -> TP Exp subSup limits convertible a = try $ do-  let sub1 = symbol "_" >> expr1-  let sup1 = symbol "^" >> expr1+  let sub1 = symbol "_" >> expr1  -- see #273+  let sup1 = (symbol "^" >> expr1) <|> primes   (b,c) <- try (do {m <- sub1; n <- sup1; return (m,n)})        <|> (do {n <- sup1; m <- sub1; return (m,n)})   return $ case limits of@@ -625,9 +619,8 @@  superOrSubscripted :: Maybe Bool -> Bool -> Exp -> TP Exp superOrSubscripted limits convertible a = try $ do-  c <- oneOf "^_"-  spaces-  b <- expr+  (c,b) <- ((,) <$> oneOf "^_" <*> (spaces >> expr))+          <|> (('^',) <$> primes)   case c of        '^' -> return $ case limits of                         Just True  -> EOver False a b
src/Text/TeXMath/Writers/Typst.hs view
@@ -141,11 +141,12 @@ writeExp (ESuper b e1) = writeExpB b <>   case S.toPrimes e1 of     Just ps -> ps-    _ -> "^" <> writeExpS e1-writeExp (ESubsup b e1 e2) = writeExpB b <> "_" <> writeExpS e1 <>-  case S.toPrimes e2 of-    Just ps -> ps-    _ -> "^" <> writeExpS e2+    Nothing -> "^" <> writeExpS e1+writeExp (ESubsup b e1 e2) =+  writeExpB b <>+    case S.toPrimes e2 of+      Just ps -> ps <> "_" <> writeExpS e1+      Nothing -> "_" <> writeExpS e1 <> "^" <> writeExpS e2 writeExp (EOver _ (EOver _ b (ESymbol TOver "\9182")) e1) =   "overbrace(" <> writeExp b <> ", " <> writeExp e1 <> ")" writeExp (EOver _ (EOver _ b (ESymbol TOver "\9140")) e1) =
+ test/regression/273.test view
@@ -0,0 +1,5 @@+<<< tex+a_i'+>>> native+[ ESubsup (EIdentifier "a") (EIdentifier "i") (ESymbol Pun "\8242")+]
texmath.cabal view
@@ -1,5 +1,5 @@ Name:                texmath-Version:             0.13+Version:             0.13.0.1 Cabal-Version:       >= 1.10 Build-type:          Simple Synopsis:            Conversion between math formats.