texmath 0.11.1.2 → 0.11.2
raw patch · 3 files changed
+59/−26 lines, 3 files
Files
- changelog +11/−0
- src/Text/TeXMath/Readers/TeX.hs +47/−25
- texmath.cabal +1/−1
changelog view
@@ -1,3 +1,14 @@+texmath (0.11.2)++ * Improved handling of \mathop etc (#126). We now allow operators like+ `arg\,min`, converting the space into unicode.+ * Support \hspace (#126).+ * Support \hdots as synonym of \ldots (#126).+ * Support \mathds (#126).+ * In parsing array, ignore `|` in column specs (#127).+ We have no way to represent this in EArray, currently.+ Ignoring them seems better than failing altogether.+ texmath (0.11.1.2) * Eqn writer: properly escape `{` and `}`.
src/Text/TeXMath/Readers/TeX.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE TupleSections #-}+{-# LANGUAGE ScopedTypeVariables #-} {- Copyright (C) 2009 John MacFarlane <jgm@berkeley.edu> @@ -28,6 +29,7 @@ import Control.Monad import Data.Char (isDigit, isAscii, isLetter) import qualified Data.Map as M+import Data.Maybe (mapMaybe) import Text.Parsec hiding (label) import Text.Parsec.Error import Text.Parsec.String@@ -38,6 +40,7 @@ import Text.TeXMath.Unicode.ToTeX (getSymbolType) import Data.Maybe (fromJust) import Text.TeXMath.Unicode.ToUnicode (toUnicode)+import Text.TeXMath.Shared (getSpaceChars) type TP = Parser @@ -52,6 +55,7 @@ , styled , root , mspace+ , hspace , mathop , phantom , boxed@@ -108,8 +112,11 @@ return result ignorable :: TP ()-ignorable = skipMany (comment <|> label <|> () <$ ctrlseq "nonumber" <|>- (skipMany1 space <?> "whitespace"))+ignorable = skipMany $+ comment+ <|> label+ <|> () <$ ctrlseq "nonumber"+ <|> (skipMany1 space <?> "whitespace") comment :: TP () comment = char '%' *> skipMany (noneOf "\n") *> optional newline@@ -172,7 +179,7 @@ toStr sty (ENumber s) = Just $ toUnicode sty s toStr sty (EMathOperator s) = Just $ toUnicode sty s toStr sty (ESymbol _ s) = Just $ toUnicode sty s- toStr _ (ESpace _) = Just $ " "+ toStr _ (ESpace n) = Just $ getSpaceChars n toStr _ (EStyled sty' exps) = concat <$> sequence (map (toStr sty') exps) toStr _ _ = Nothing@@ -343,12 +350,12 @@ arrayAlignments :: TP [Alignment] arrayAlignments = try $ do- as <- braces (many letter)+ as <- braces (many (letter <|> char '|')) let letterToAlignment 'l' = AlignLeft letterToAlignment 'c' = AlignCenter letterToAlignment 'r' = AlignRight letterToAlignment _ = AlignCenter- return $ map letterToAlignment as+ return $ map letterToAlignment $ filter (/= '|') as environment :: TP Exp environment = do@@ -530,6 +537,7 @@ , ("\\mathsf", EStyled TextSansSerif) , ("\\mathsfup", EStyled TextSansSerif) , ("\\mathbb", EStyled TextDoubleStruck)+ , ("\\mathds", EStyled TextDoubleStruck) -- mathds package , ("\\mathcal", EStyled TextScript) , ("\\mathscr", EStyled TextScript) , ("\\mathfrak", EStyled TextFraktur)@@ -605,15 +613,29 @@ mspace :: TP Exp mspace = do ctrlseq "mspace"- lexeme $ char '{'- len <- many1 digit- lexeme $ string "mu"- lexeme $ char '}'- case reads len of- ((n,[]):_) -> return $ ESpace (n/18)- _ -> mzero+ braces $ do+ len <- many1 digit+ lexeme $ string "mu"+ case reads len of+ ((n :: Integer,[]):_) -> return $ ESpace (fromIntegral n/18)+ _ -> mzero +hspace :: TP Exp+hspace = do+ ctrlseq "hspace"+ braces $ do+ len <- many1 digit+ scaleFactor <-+ 1 <$ (string "em")+ <|> (1/12) <$ (string "pt")+ <|> 6 <$ (string "in")+ <|> (50/21) <$ (string "cm")+ case reads len of+ ((n :: Integer,[]):_) -> return $ ESpace (fromIntegral n * scaleFactor)+ _ -> mzero++ mathop :: TP Exp mathop = mathopWith "mathop" Op <|> mathopWith "mathrel" Rel@@ -626,19 +648,18 @@ mathopWith :: String -> TeXSymbolType -> TP Exp mathopWith name ty = try $ do ctrlseq name- e <- expr1- let e' = case e of- EGrouped [x] -> x- _ -> e- case e' of- ESymbol _ x -> return $ ESymbol ty x- EIdentifier x -> return $ ESymbol ty x- EText TextNormal x -> return $ ESymbol ty x- EText sty x -> return $ EStyled sty [ESymbol ty x]- x | ty == Op -> case expToOperatorName x of- Just y -> return $ EMathOperator y- _ -> return x- | otherwise -> return x+ e <- inbraces <|> expr1+ let es' = case e of+ EGrouped xs -> xs+ x -> [x]+ case es' of+ [ESymbol _ x] -> return $ ESymbol ty x+ [EIdentifier x] -> return $ ESymbol ty x+ [EText TextNormal x] -> return $ ESymbol ty x+ [EText sty x] -> return $ EStyled sty [ESymbol ty x]+ xs | ty == Op -> return $ EMathOperator $+ concat $ mapMaybe expToOperatorName xs+ | otherwise -> return $ EGrouped xs binary :: TP Exp binary = do@@ -988,6 +1009,7 @@ , ("\\prime",ESymbol Ord "\8242") , ("\\dots",ESymbol Ord "\8230") , ("\\ldots",ESymbol Ord "\8230")+ , ("\\hdots",ESymbol Ord "\8230") , ("\\cdots",ESymbol Ord "\8943") , ("\\vdots",ESymbol Ord "\8942") , ("\\ddots",ESymbol Ord "\8945")
texmath.cabal view
@@ -1,5 +1,5 @@ Name: texmath-Version: 0.11.1.2+Version: 0.11.2 Cabal-Version: >= 1.10 Build-type: Simple Synopsis: Conversion between formats used to represent mathematics.