packages feed

texmath 0.9 → 0.9.1

raw patch · 7 files changed

+61/−34 lines, 7 files

Files

changelog view
@@ -1,3 +1,11 @@+texmath (0.9.1)++  * Pandoc writer:  add thin space after math operators.+  * TeX reader: improve parsing of `\mathop` to allow+    multi-character operator names.+  * Minor optimizations.+  * Added Ord instances to Exp and associated types.+ texmath (0.9)    * OMML writer: Properly handle nary inside delimiters (#92).
src/Text/TeXMath/Readers/TeX.hs view
@@ -143,6 +143,7 @@ operatorname :: TP (Exp, Bool) operatorname = do     ctrlseq "operatorname"+    -- these are slightly different but we won't worry about that here...     convertible <- (char '*' >> spaces >> return True) <|> return False     op <- expToOperatorName <$> texToken     maybe mzero (\s -> return (EMathOperator s, convertible)) op@@ -187,10 +188,11 @@   <|> return Nothing  binomCmd :: TP String-binomCmd = oneOfCommands (map fst binomCmds)+binomCmd = oneOfCommands (M.keys binomCmds) -binomCmds :: [(String, Exp -> Exp -> Exp)]-binomCmds = [ ("\\choose", \x y ->+binomCmds :: M.Map String (Exp -> Exp -> Exp)+binomCmds = M.fromList+            [ ("\\choose", \x y ->                 EDelimited "(" ")" [Right (EFraction NoLineFrac x y)])             , ("\\brack", \x y ->                 EDelimited "[" "]" [Right (EFraction NoLineFrac x y)])@@ -233,7 +235,7 @@                 else many (notFollowedBy binomCmd >> p)   let withCmd :: String -> TP Exp       withCmd cmd =-         case lookup cmd binomCmds of+         case M.lookup cmd binomCmds of               Just f  -> f <$> (asGroup <$> pure initial)                            <*> (asGroup <$> many p)               Nothing -> fail $ "Unknown command " ++ cmd@@ -622,7 +624,10 @@   case e of      ESymbol _ x   -> return $ ESymbol ty x      EIdentifier x -> return $ ESymbol ty x-     x             -> return x+     x | ty == Op  -> case expToOperatorName x of+                           Just y -> return $ EMathOperator y+                           _      -> return x+       | otherwise -> return x  binary :: TP Exp binary = do
src/Text/TeXMath/Shared.hs view
@@ -39,6 +39,7 @@ import Text.TeXMath.Types import Text.TeXMath.TeX import qualified Data.Map as M+import qualified Data.Set as Set import Data.Maybe (fromMaybe) import Data.Ratio ((%)) import Data.List (sort)@@ -83,7 +84,7 @@                   (snd <$> M.lookup t textTypesMap) in   if textPackage textCmd e     then textCmd-    else fromMaybe "\\mathrm" (lookup textCmd alts)+    else fromMaybe "\\mathrm" (M.lookup textCmd alts)  -- | Maps MathML mathvariant to the corresponing TextType getTextType :: String -> TextType@@ -127,10 +128,10 @@ -- Operator Table  getOperator :: Exp -> Maybe TeX-getOperator op = fmap ControlSeq $ lookup op operators+getOperator op = fmap ControlSeq $ M.lookup op operators -operators :: [(Exp, String)]-operators =+operators :: M.Map Exp String+operators = M.fromList            [ (EMathOperator "arccos", "\\arccos")            , (EMathOperator "arcsin", "\\arcsin")            , (EMathOperator "arctan", "\\arctan")@@ -212,18 +213,28 @@   , ( TextBoldFraktur         , ("bold-fraktur","\\mathbffrak"))   , ( TextSansSerifItalic     , ("sans-serif-italic","\\mathsfit")) ] -unicodeMath, base :: [String]-unicodeMath = ["\\mathbfit", "\\mathbfsfup", "\\mathbfsfit", "\\mathbfscr", "\\mathbffrak", "\\mathsfit"]-base = ["\\mathbb", "\\mathrm", "\\mathbf", "\\mathit", "\\mathsf", "\\mathtt", "\\mathfrak", "\\mathcal"]+unicodeMath, base :: Set.Set String+unicodeMath = Set.fromList+  ["\\mathbfit", "\\mathbfsfup", "\\mathbfsfit", "\\mathbfscr",+   "\\mathbffrak", "\\mathsfit"]+base = Set.fromList+  ["\\mathbb", "\\mathrm", "\\mathbf", "\\mathit", "\\mathsf",+   "\\mathtt", "\\mathfrak", "\\mathcal"] -alts :: [(String, String)]-alts = [ ("\\mathbfit", "\\mathbf"), ("\\mathbfsfup", "\\mathbf"), ("\\mathbfsfit", "\\mathbf")-       , ("\\mathbfscr", "\\mathcal"), ("\\mathbffrak", "\\mathfrak"), ("\\mathsfit", "\\mathsf")]+alts :: M.Map String String+alts = M.fromList+  [ ("\\mathbfit", "\\mathbf")+  , ("\\mathbfsfup", "\\mathbf")+  , ("\\mathbfsfit", "\\mathbf")+  , ("\\mathbfscr", "\\mathcal")+  , ("\\mathbffrak", "\\mathfrak")+  , ("\\mathsfit", "\\mathsf")+  ]  textPackage :: String -> [String] -> Bool textPackage s e-  | s `elem` unicodeMath = "unicode-math" `elem` e-  | s `elem` base    = True+  | s `Set.member` unicodeMath = "unicode-math" `elem` e+  | s `Set.member` base    = True   | otherwise = True  -- | Mapping between LaTeX scaling commands and the scaling factor@@ -325,10 +336,9 @@  -- Converts unit to multiplier to reach em unitToMultiplier :: String -> Maybe Rational-unitToMultiplier s = lookup s units+unitToMultiplier s = M.lookup s units   where-    units =-                        [ ( "pt" , 10)+    units = M.fromList  [ ( "pt" , 10)                         , ( "mm" , (351/10))                         , ( "cm" , (35/100))                         , ( "in" , (14/100))
src/Text/TeXMath/Types.hs view
@@ -32,16 +32,16 @@  data TeXSymbolType = Ord | Op | Bin | Rel | Open | Close | Pun | Accent                      | Fence | TOver | TUnder | Alpha | BotAccent | Rad-                     deriving (Show, Read, Eq, Data, Typeable)+                     deriving (Show, Read, Eq, Ord, Data, Typeable)  data Alignment = AlignLeft | AlignCenter | AlignRight | AlignDefault-                 deriving (Show, Read, Eq, Data, Typeable)+                 deriving (Show, Read, Eq, Ord, Data, Typeable)  data FractionType = NormalFrac   -- ^ Displayed or textual, acc to 'DisplayType'                   | DisplayFrac  -- ^ Force display mode                   | InlineFrac   -- ^ Force inline mode (textual)                   | NoLineFrac   -- ^ No line between top and bottom-                  deriving (Show, Read, Eq, Data, Typeable)+                  deriving (Show, Read, Eq, Ord, Data, Typeable)  type ArrayLine = [[Exp]] @@ -90,7 +90,7 @@                   -- the same length.   | EText TextType String  -- ^ Some normal text, possibly styled.   | EStyled TextType [Exp] -- ^  A group of styled expressions.-  deriving (Show, Read, Eq, Data, Typeable)+  deriving (Show, Read, Eq, Ord, Data, Typeable)  -- | An @EDelimited@ element contains a string of ordinary expressions -- (represented here as @Right@ values) or fences (represented here as@@ -100,7 +100,7 @@  data DisplayType = DisplayBlock  -- ^ A displayed formula.                  | DisplayInline  -- ^ A formula rendered inline in text.-                 deriving (Show, Eq)+                 deriving (Show, Eq, Ord)  data TextType = TextNormal               | TextBold@@ -116,7 +116,7 @@               | TextBoldScript               | TextBoldFraktur               | TextSansSerifItalic-              deriving (Show, Ord, Read, Eq, Data, Typeable)+              deriving (Show, Read, Eq, Ord, Data, Typeable)  data FormType = FPrefix | FPostfix | FInfix deriving (Show, Ord, Eq) 
src/Text/TeXMath/Unicode/Fonts.hs view
@@ -28,7 +28,7 @@ Utilities to convert between MS font codepoints and unicode characters. -} module Text.TeXMath.Unicode.Fonts (getUnicode, Font(..), stringToFont) where-+import qualified Data.Map as M  -- | Enumeration of recognised fonts data Font = Symbol -- ^ <http://en.wikipedia.org/wiki/Symbol_(typeface) Adobe Symbol>@@ -42,11 +42,11 @@ -- | Given a font and codepoint, returns the corresponding unicode -- character getUnicode :: Font -> Char -> Maybe Char-getUnicode Symbol c = lookup c symbol+getUnicode Symbol c = M.lookup c symbol  -- Generated from lib/fonts/symbol.txt-symbol :: [(Char, Char)]-symbol =+symbol :: M.Map Char Char+symbol = M.fromList   [ (' ',' ')   , (' ','\160')   , ('!','!')
src/Text/TeXMath/Writers/Pandoc.hs view
@@ -47,6 +47,8 @@ addSpaces (x : ESymbol t2 s2 : xs)   | not (null xs) =     x : addSpace t2 (ESymbol t2 s2) ++ addSpaces xs+addSpaces (EMathOperator s : xs) =+  EMathOperator s : thinspace : addSpaces xs addSpaces (x : xs) = x : addSpaces xs addSpaces [] = [] @@ -57,9 +59,11 @@       Rel -> [widespace, x, widespace]       Pun -> [x, thinspace]       _   -> [x]-  where thinspace = EText TextNormal "\x2006"-        medspace  = EText TextNormal "\x2005"-        widespace = EText TextNormal "\x2004"++thinspace, medspace, widespace :: Exp+thinspace = EText TextNormal "\x2006"+medspace  = EText TextNormal "\x2005"+widespace = EText TextNormal "\x2004"  renderStr :: TextType -> String -> Inline renderStr tt s =
texmath.cabal view
@@ -1,5 +1,5 @@ Name:                texmath-Version:             0.9+Version:             0.9.1 Cabal-Version:       >= 1.10 Build-type:          Simple Synopsis:            Conversion between formats used to represent mathematics.