{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
module Text.Pandoc.Readers.LaTeX.SIunitx
( siunitxCommands )
where
import Text.Pandoc.Builder
( space,
subscript,
superscript,
emph,
str,
fromList,
text,
Many(Many, unMany),
Inline(Superscript, Str),
Inlines )
import Text.Pandoc.Readers.LaTeX.Parsing
( anyControlSeq,
braced,
bracketed,
controlSeq,
grouped,
isWordTok,
keyvals,
satisfyTok,
skipopts,
spaces1,
symbol,
untokenize,
LP )
import Text.Pandoc.Readers.LaTeX.Types
( Tok(Tok), TokType(Word, CtrlSeq) )
import Text.Pandoc.Class.PandocMonad ( PandocMonad )
import Text.Pandoc.Parsing
( many1,
eof,
string,
satisfy,
skipMany,
option,
many,
char,
try,
skipMany1,
runParser,
Parser )
import Control.Applicative ((<|>))
import Control.Monad (void)
import qualified Data.Map as M
import Data.Char (isDigit)
import Data.Text (Text)
import qualified Data.Text as T
import Data.List (intersperse)
import qualified Data.Sequence as Seq
import Text.Pandoc.Walk (walk)
siunitxCommands :: PandocMonad m
=> LP m Inlines -> M.Map Text (LP m Inlines)
siunitxCommands :: LP m Inlines -> Map Text (LP m Inlines)
siunitxCommands tok :: LP m Inlines
tok = [(Text, LP m Inlines)] -> Map Text (LP m Inlines)
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
[ ("si", LP m Inlines -> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines -> LP m Inlines
dosi LP m Inlines
tok)
, ("unit", LP m Inlines -> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines -> LP m Inlines
dosi LP m Inlines
tok)
, ("SI", LP m Inlines -> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines -> LP m Inlines
doSI LP m Inlines
tok)
, ("qty", LP m Inlines -> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines -> LP m Inlines
doSI LP m Inlines
tok)
, ("SIrange", Bool -> LP m Inlines -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Bool -> LP m Inlines -> LP m Inlines
doSIrange Bool
True LP m Inlines
tok)
, ("qtyrange", Bool -> LP m Inlines -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Bool -> LP m Inlines -> LP m Inlines
doSIrange Bool
True LP m Inlines
tok)
, ("SIlist", LP m Inlines -> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines -> LP m Inlines
doSIlist LP m Inlines
tok)
, ("qtylist", LP m Inlines -> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines -> LP m Inlines
doSIlist LP m Inlines
tok)
, ("numrange", Bool -> LP m Inlines -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
Bool -> LP m Inlines -> LP m Inlines
doSIrange Bool
False LP m Inlines
tok)
, ("numlist", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
doSInumlist)
, ("num", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
doSInum)
, ("ang", LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
doSIang)
]
dosi :: PandocMonad m => LP m Inlines -> LP m Inlines
dosi :: LP m Inlines -> LP m Inlines
dosi tok :: LP m Inlines
tok = do
[(Text, Text)]
options <- [(Text, Text)]
-> ParsecT [Tok] LaTeXState m [(Text, Text)]
-> ParsecT [Tok] LaTeXState m [(Text, Text)]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] ParsecT [Tok] LaTeXState m [(Text, Text)]
forall (m :: * -> *). PandocMonad m => LP m [(Text, Text)]
keyvals
LP m Inlines -> LP m Inlines
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped ([(Text, Text)] -> LP m Inlines -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
[(Text, Text)] -> LP m Inlines -> LP m Inlines
siUnit [(Text, Text)]
options LP m Inlines
tok) LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [(Text, Text)] -> LP m Inlines -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
[(Text, Text)] -> LP m Inlines -> LP m Inlines
siUnit [(Text, Text)]
options LP m Inlines
tok
doSI :: PandocMonad m => LP m Inlines -> LP m Inlines
doSI :: LP m Inlines -> LP m Inlines
doSI tok :: LP m Inlines
tok = do
LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
Inlines
value <- LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
doSInum
Inlines
valueprefix <- Inlines -> LP m Inlines -> LP m Inlines
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option "" (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ LP m Inlines -> LP m Inlines
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
bracketed LP m Inlines
tok
Inlines
unit <- LP m Inlines -> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines -> LP m Inlines
dosi LP m Inlines
tok
Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> LP m Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> LP m Inlines) -> [Inlines] -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ [Inlines
valueprefix,
Inlines -> Inlines
emptyOr160 Inlines
valueprefix,
Inlines
value,
Inlines -> Inlines
emptyOr160 Inlines
unit,
Inlines
unit]
doSInum :: PandocMonad m => LP m Inlines
doSInum :: LP m Inlines
doSInum = LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts LP m () -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Text -> Inlines
tonum (Text -> Inlines) -> ([Tok] -> Text) -> [Tok] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize ([Tok] -> Inlines)
-> ParsecT [Tok] LaTeXState m [Tok] -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced)
tonum :: Text -> Inlines
tonum :: Text -> Inlines
tonum value :: Text
value =
case Parsec Text () Inlines
-> () -> SourceName -> Text -> Either ParseError Inlines
forall s t u a.
Stream s Identity t =>
Parsec s u a -> u -> SourceName -> s -> Either ParseError a
runParser Parsec Text () Inlines
parseNum () "" Text
value of
Left _ -> Text -> Inlines
text Text
value
Right num :: Inlines
num -> Inlines
num
doSInumlist :: PandocMonad m => LP m Inlines
doSInumlist :: LP m Inlines
doSInumlist = do
LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
[Inlines]
xs <- (Text -> Inlines) -> [Text] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Inlines
tonum ([Text] -> [Inlines]) -> ([Tok] -> [Text]) -> [Tok] -> [Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> [Text]
T.splitOn ";" (Text -> [Text]) -> ([Tok] -> Text) -> [Tok] -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize ([Tok] -> [Inlines])
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Inlines]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
case [Inlines]
xs of
[] -> Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty
[x :: Inlines
x] -> Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
x
_ -> Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$
[Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat (Inlines -> [Inlines] -> [Inlines]
forall a. a -> [a] -> [a]
intersperse (Text -> Inlines
str "," Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
space) ([Inlines] -> [Inlines]
forall a. [a] -> [a]
init [Inlines]
xs)) Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<>
Text -> Inlines
text ", & " Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> [Inlines] -> Inlines
forall a. [a] -> a
last [Inlines]
xs
doSIlist :: PandocMonad m => LP m Inlines -> LP m Inlines
doSIlist :: LP m Inlines -> LP m Inlines
doSIlist tok :: LP m Inlines
tok = do
[(Text, Text)]
options <- [(Text, Text)]
-> ParsecT [Tok] LaTeXState m [(Text, Text)]
-> ParsecT [Tok] LaTeXState m [(Text, Text)]
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option [] ParsecT [Tok] LaTeXState m [(Text, Text)]
forall (m :: * -> *). PandocMonad m => LP m [(Text, Text)]
keyvals
[Inlines]
nums <- (Text -> Inlines) -> [Text] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map Text -> Inlines
tonum ([Text] -> [Inlines]) -> ([Tok] -> [Text]) -> [Tok] -> [Inlines]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text -> [Text]
T.splitOn ";" (Text -> [Text]) -> ([Tok] -> Text) -> [Tok] -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize ([Tok] -> [Inlines])
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Inlines]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
Inlines
unit <- LP m Inlines -> LP m Inlines
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
grouped ([(Text, Text)] -> LP m Inlines -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
[(Text, Text)] -> LP m Inlines -> LP m Inlines
siUnit [(Text, Text)]
options LP m Inlines
tok) LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> [(Text, Text)] -> LP m Inlines -> LP m Inlines
forall (m :: * -> *).
PandocMonad m =>
[(Text, Text)] -> LP m Inlines -> LP m Inlines
siUnit [(Text, Text)]
options LP m Inlines
tok
let xs :: [Inlines]
xs = (Inlines -> Inlines) -> [Inlines] -> [Inlines]
forall a b. (a -> b) -> [a] -> [b]
map (Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> (Text -> Inlines
str "\xa0" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
unit)) [Inlines]
nums
case [Inlines]
xs of
[] -> Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty
[x :: Inlines
x] -> Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
x
_ -> Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$
[Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat (Inlines -> [Inlines] -> [Inlines]
forall a. a -> [a] -> [a]
intersperse (Text -> Inlines
str "," Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
space) ([Inlines] -> [Inlines]
forall a. [a] -> [a]
init [Inlines]
xs)) Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<>
Text -> Inlines
text ", & " Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> [Inlines] -> Inlines
forall a. [a] -> a
last [Inlines]
xs
parseNum :: Parser Text () Inlines
parseNum :: Parsec Text () Inlines
parseNum = ([Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ParsecT Text () Identity [Inlines] -> Parsec Text () Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parsec Text () Inlines -> ParsecT Text () Identity [Inlines]
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many Parsec Text () Inlines
parseNumPart) Parsec Text () Inlines
-> ParsecT Text () Identity () -> Parsec Text () Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Text () Identity ()
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof
minus :: Text
minus :: Text
minus = "\x2212"
hyphenToMinus :: Inline -> Inline
hyphenToMinus :: Inline -> Inline
hyphenToMinus (Str t :: Text
t) = Text -> Inline
Str (Text -> Text -> Text -> Text
T.replace "-" Text
minus Text
t)
hyphenToMinus x :: Inline
x = Inline
x
parseNumPart :: Parser Text () Inlines
parseNumPart :: Parsec Text () Inlines
parseNumPart =
Parsec Text () Inlines
parseDecimalNum Parsec Text () Inlines
-> Parsec Text () Inlines -> Parsec Text () Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
Parsec Text () Inlines
parseComma Parsec Text () Inlines
-> Parsec Text () Inlines -> Parsec Text () Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
Parsec Text () Inlines
parsePlusMinus Parsec Text () Inlines
-> Parsec Text () Inlines -> Parsec Text () Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
Parsec Text () Inlines
parsePM Parsec Text () Inlines
-> Parsec Text () Inlines -> Parsec Text () Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
Parsec Text () Inlines
parseI Parsec Text () Inlines
-> Parsec Text () Inlines -> Parsec Text () Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
Parsec Text () Inlines
parseExp Parsec Text () Inlines
-> Parsec Text () Inlines -> Parsec Text () Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
Parsec Text () Inlines
parseX Parsec Text () Inlines
-> Parsec Text () Inlines -> Parsec Text () Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
Parsec Text () Inlines
parseSpace
where
parseDecimalNum, parsePlusMinus, parsePM,
parseComma, parseI, parseX,
parseExp, parseSpace :: Parser Text () Inlines
parseDecimalNum :: Parsec Text () Inlines
parseDecimalNum = Parsec Text () Inlines -> Parsec Text () Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (Parsec Text () Inlines -> Parsec Text () Inlines)
-> Parsec Text () Inlines -> Parsec Text () Inlines
forall a b. (a -> b) -> a -> b
$ do
Text
pref <- Text
-> ParsecT Text () Identity Text -> ParsecT Text () Identity Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
forall a. Monoid a => a
mempty (ParsecT Text () Identity Text -> ParsecT Text () Identity Text)
-> ParsecT Text () Identity Text -> ParsecT Text () Identity Text
forall a b. (a -> b) -> a -> b
$ (Text
forall a. Monoid a => a
mempty Text
-> ParsecT Text () Identity Char -> ParsecT Text () Identity Text
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT Text () Identity Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char '+') ParsecT Text () Identity Text
-> ParsecT Text () Identity Text -> ParsecT Text () Identity Text
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Text
minus Text
-> ParsecT Text () Identity Char -> ParsecT Text () Identity Text
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT Text () Identity Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char '-')
SourceName
basenum' <- ParsecT Text () Identity Char
-> ParsecT Text () Identity SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ((Char -> Bool) -> ParsecT Text () Identity Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (\c :: Char
c -> Char -> Bool
isDigit Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '.'))
let basenum :: Text
basenum = Text
pref Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> SourceName -> Text
T.pack
(case SourceName
basenum' of
'.':_ -> '0'Char -> SourceName -> SourceName
forall a. a -> [a] -> [a]
:SourceName
basenum'
_ -> SourceName
basenum')
Text
uncertainty <- Text
-> ParsecT Text () Identity Text -> ParsecT Text () Identity Text
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
forall a. Monoid a => a
mempty (ParsecT Text () Identity Text -> ParsecT Text () Identity Text)
-> ParsecT Text () Identity Text -> ParsecT Text () Identity Text
forall a b. (a -> b) -> a -> b
$ SourceName -> Text
T.pack (SourceName -> Text)
-> ParsecT Text () Identity SourceName
-> ParsecT Text () Identity Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Text () Identity SourceName
forall u. ParsecT Text u Identity SourceName
parseParens
if Text -> Bool
T.null Text
uncertainty
then Inlines -> Parsec Text () Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> Parsec Text () Inlines)
-> Inlines -> Parsec Text () Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str Text
basenum
else Inlines -> Parsec Text () Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> Parsec Text () Inlines)
-> Inlines -> Parsec Text () Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str (Text -> Inlines) -> Text -> Inlines
forall a b. (a -> b) -> a -> b
$ Text
basenum Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "\xa0\xb1\xa0" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
let (_,ys :: Text
ys) = (Char -> Bool) -> Text -> (Text, Text)
T.break (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
=='.') Text
basenum
in case (Text -> Int
T.length Text
ys Int -> Int -> Int
forall a. Num a => a -> a -> a
- 1, Text -> Int
T.length Text
uncertainty) of
(0,_) -> Text
uncertainty
(x :: Int
x,y :: Int
y)
| Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
y -> "0." Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Int -> Text -> Text
T.replicate (Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
y) "0" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
(Char -> Bool) -> Text -> Text
T.dropWhileEnd (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
=='0') Text
uncertainty
| Bool
otherwise -> Int -> Text -> Text
T.take (Int
y Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
x) Text
uncertainty Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
case (Char -> Bool) -> Text -> Text
T.dropWhileEnd (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
=='0')
(Int -> Text -> Text
T.drop (Int
y Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
x) Text
uncertainty) of
t :: Text
t | Text -> Bool
T.null Text
t -> Text
forall a. Monoid a => a
mempty
| Bool
otherwise -> "." Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t
parseComma :: Parsec Text () Inlines
parseComma = Text -> Inlines
str "." Inlines -> ParsecT Text () Identity Char -> Parsec Text () Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT Text () Identity Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char ','
parsePlusMinus :: Parsec Text () Inlines
parsePlusMinus = Text -> Inlines
str "\xa0\xb1\xa0" Inlines
-> ParsecT Text () Identity SourceName -> Parsec Text () Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text () Identity SourceName
-> ParsecT Text () Identity SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (SourceName -> ParsecT Text () Identity SourceName
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string "+-")
parsePM :: Parsec Text () Inlines
parsePM = Text -> Inlines
str "\xa0\xb1\xa0" Inlines
-> ParsecT Text () Identity SourceName -> Parsec Text () Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text () Identity SourceName
-> ParsecT Text () Identity SourceName
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (SourceName -> ParsecT Text () Identity SourceName
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
SourceName -> ParsecT s u m SourceName
string "\\pm")
parseParens :: ParsecT Text u Identity SourceName
parseParens =
Char -> ParsecT Text u Identity Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char '(' ParsecT Text u Identity Char
-> ParsecT Text u Identity SourceName
-> ParsecT Text u Identity SourceName
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Text u Identity Char -> ParsecT Text u Identity SourceName
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 ((Char -> Bool) -> ParsecT Text u Identity Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (\c :: Char
c -> Char -> Bool
isDigit Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== '.')) ParsecT Text u Identity SourceName
-> ParsecT Text u Identity Char
-> ParsecT Text u Identity SourceName
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> ParsecT Text u Identity Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char ')'
parseI :: Parsec Text () Inlines
parseI = Text -> Inlines
str "i" Inlines -> ParsecT Text () Identity Char -> Parsec Text () Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT Text () Identity Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char 'i'
parseX :: Parsec Text () Inlines
parseX = Text -> Inlines
str "\xa0\xd7\xa0" Inlines -> ParsecT Text () Identity Char -> Parsec Text () Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Char -> ParsecT Text () Identity Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char 'x'
parseExp :: Parsec Text () Inlines
parseExp = (\n :: Inlines
n -> Text -> Inlines
str ("\xa0\xd7\xa0" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "10") Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines -> Inlines
superscript Inlines
n)
(Inlines -> Inlines)
-> Parsec Text () Inlines -> Parsec Text () Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> ParsecT Text () Identity Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char 'e' ParsecT Text () Identity Char
-> Parsec Text () Inlines -> Parsec Text () Inlines
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parsec Text () Inlines
parseDecimalNum)
parseSpace :: Parsec Text () Inlines
parseSpace = Inlines
forall a. Monoid a => a
mempty Inlines -> ParsecT Text () Identity () -> Parsec Text () Inlines
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ ParsecT Text () Identity Char -> ParsecT Text () Identity ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 (Char -> ParsecT Text () Identity Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char ' ')
doSIang :: PandocMonad m => LP m Inlines
doSIang :: LP m Inlines
doSIang = do
LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
[Text]
ps <- Text -> Text -> [Text]
T.splitOn ";" (Text -> [Text]) -> ([Tok] -> Text) -> [Tok] -> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Tok] -> Text
untokenize ([Tok] -> [Text])
-> ParsecT [Tok] LaTeXState m [Tok]
-> ParsecT [Tok] LaTeXState m [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT [Tok] LaTeXState m [Tok]
forall (m :: * -> *). PandocMonad m => LP m [Tok]
braced
let dropPlus :: Text -> Text
dropPlus t :: Text
t = case Text -> Maybe (Char, Text)
T.uncons Text
t of
Just ('+',t' :: Text
t') -> Text
t'
_ -> Text
t
case [Text]
ps [Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ Text -> [Text]
forall a. a -> [a]
repeat "" of
(d :: Text
d:m :: Text
m:s :: Text
s:_) -> Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$
(if Text -> Bool
T.null Text
d then Inlines
forall a. Monoid a => a
mempty else Text -> Inlines
str (Text -> Text
dropPlus Text
d) Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
str "\xb0") Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<>
(if Text -> Bool
T.null Text
m then Inlines
forall a. Monoid a => a
mempty else Text -> Inlines
str (Text -> Text
dropPlus Text
m) Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
str "\x2032") Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<>
(if Text -> Bool
T.null Text
s then Inlines
forall a. Monoid a => a
mempty else Text -> Inlines
str (Text -> Text
dropPlus Text
s) Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
str "\x2033")
_ -> Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty
doSIrange :: PandocMonad m => Bool -> LP m Inlines -> LP m Inlines
doSIrange :: Bool -> LP m Inlines -> LP m Inlines
doSIrange includeUnits :: Bool
includeUnits tok :: LP m Inlines
tok = do
LP m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
Inlines
startvalue <- LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
doSInum
Inlines
startvalueprefix <- Inlines -> LP m Inlines -> LP m Inlines
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option "" (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ LP m Inlines -> LP m Inlines
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
bracketed LP m Inlines
tok
Inlines
stopvalue <- LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines
doSInum
Inlines
stopvalueprefix <- Inlines -> LP m Inlines -> LP m Inlines
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option "" (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ LP m Inlines -> LP m Inlines
forall (m :: * -> *) a.
(PandocMonad m, Monoid a) =>
LP m a -> LP m a
bracketed LP m Inlines
tok
Inlines
unit <- if Bool
includeUnits
then LP m Inlines -> LP m Inlines
forall (m :: * -> *). PandocMonad m => LP m Inlines -> LP m Inlines
dosi LP m Inlines
tok
else Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return Inlines
forall a. Monoid a => a
mempty
Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines)
-> ([Inlines] -> Inlines) -> [Inlines] -> LP m Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> LP m Inlines) -> [Inlines] -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ [Inlines
startvalueprefix,
Inlines -> Inlines
emptyOr160 Inlines
startvalueprefix,
Inlines
startvalue,
Inlines -> Inlines
emptyOr160 Inlines
unit,
Inlines
unit,
"\8211",
Inlines
stopvalueprefix,
Inlines -> Inlines
emptyOr160 Inlines
stopvalueprefix,
Inlines
stopvalue,
Inlines -> Inlines
emptyOr160 Inlines
unit,
Inlines
unit]
emptyOr160 :: Inlines -> Inlines
emptyOr160 :: Inlines -> Inlines
emptyOr160 x :: Inlines
x = if Inlines
x Inlines -> Inlines -> Bool
forall a. Eq a => a -> a -> Bool
== Inlines
forall a. Monoid a => a
mempty then Inlines
x else Text -> Inlines
str "\160"
siUnit :: forall m. PandocMonad m => [(Text,Text)] -> LP m Inlines -> LP m Inlines
siUnit :: [(Text, Text)] -> LP m Inlines -> LP m Inlines
siUnit options :: [(Text, Text)]
options tok :: LP m Inlines
tok = [Inlines] -> Inlines
forall a. Monoid a => [a] -> a
mconcat ([Inlines] -> Inlines)
-> ([Inlines] -> [Inlines]) -> [Inlines] -> Inlines
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Inlines -> [Inlines] -> [Inlines]
forall a. a -> [a] -> [a]
intersperse (Text -> Inlines
str "\xa0") ([Inlines] -> Inlines)
-> ParsecT [Tok] LaTeXState m [Inlines] -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines -> ParsecT [Tok] LaTeXState m [Inlines]
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 LP m Inlines
siUnitPart
where
siUnitPart :: LP m Inlines
siUnitPart :: LP m Inlines
siUnitPart = LP m Inlines -> LP m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ do
ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany (ParsecT [Tok] LaTeXState m Tok -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '.') ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT [Tok] LaTeXState m Tok -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '~') ParsecT [Tok] LaTeXState m ()
-> ParsecT [Tok] LaTeXState m () -> ParsecT [Tok] LaTeXState m ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
spaces1)
Inlines
x <- ((LP m (Inlines -> Inlines)
siPrefix LP m (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> LP m Inlines
siBase)
LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (do Inlines
u <- LP m Inlines
siBase LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> LP m Inlines
tok
Inlines -> LP m Inlines -> LP m Inlines
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Inlines
u (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ LP m (Inlines -> Inlines)
siSuffix LP m (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Inlines -> LP m Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure Inlines
u))
Inlines -> LP m Inlines -> LP m Inlines
forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Inlines
x (Inlines -> LP m Inlines
siInfix Inlines
x)
siInfix :: Inlines -> LP m Inlines
siInfix :: Inlines -> LP m Inlines
siInfix u1 :: Inlines
u1 = LP m Inlines -> LP m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (LP m Inlines -> LP m Inlines) -> LP m Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$
(do Tok
_ <- Text -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "per"
Inlines
u2 <- LP m Inlines
siUnitPart
let useSlash :: Bool
useSlash = Text -> [(Text, Text)] -> Maybe Text
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup "per-mode" [(Text, Text)]
options Maybe Text -> Maybe Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Maybe Text
forall a. a -> Maybe a
Just "symbol"
if Bool
useSlash
then Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines
u1 Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
str "/" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
u2)
else Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines
u1 Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
str "\xa0" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines -> Inlines
negateExponent Inlines
u2))
LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (do Tok
_ <- Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '/'
Inlines
u2 <- LP m Inlines
siUnitPart
Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines
u1 Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Text -> Inlines
str "/" Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines
u2))
siPrefix :: LP m (Inlines -> Inlines)
siPrefix :: LP m (Inlines -> Inlines)
siPrefix =
(do Tok
_ <- Text -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "square"
ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
(Inlines -> Inlines) -> LP m (Inlines -> Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines -> Inlines
superscript "2"))
LP m (Inlines -> Inlines)
-> LP m (Inlines -> Inlines) -> LP m (Inlines -> Inlines)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (do Tok
_ <- Text -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "cubic"
ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
(Inlines -> Inlines) -> LP m (Inlines -> Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines -> Inlines
superscript "3"))
LP m (Inlines -> Inlines)
-> LP m (Inlines -> Inlines) -> LP m (Inlines -> Inlines)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (do Tok
_ <- Text -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "raisetothe"
ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
Inlines
n <- (Inline -> Inline) -> Inlines -> Inlines
forall a b. Walkable a b => (a -> a) -> b -> b
walk Inline -> Inline
hyphenToMinus (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
tok
(Inlines -> Inlines) -> LP m (Inlines -> Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines -> Inlines
superscript Inlines
n))
siSuffix :: LP m (Inlines -> Inlines)
siSuffix :: LP m (Inlines -> Inlines)
siSuffix =
(do Tok
_ <- Text -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "squared"
ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
(Inlines -> Inlines) -> LP m (Inlines -> Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines -> Inlines
superscript "2"))
LP m (Inlines -> Inlines)
-> LP m (Inlines -> Inlines) -> LP m (Inlines -> Inlines)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (do Tok
_ <- Text -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "cubed"
ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
(Inlines -> Inlines) -> LP m (Inlines -> Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines -> Inlines
superscript "3"))
LP m (Inlines -> Inlines)
-> LP m (Inlines -> Inlines) -> LP m (Inlines -> Inlines)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (do Tok
_ <- Text -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Text -> LP m Tok
controlSeq "tothe"
ParsecT [Tok] LaTeXState m ()
forall (m :: * -> *). PandocMonad m => LP m ()
skipopts
Inlines
n <- (Inline -> Inline) -> Inlines -> Inlines
forall a b. Walkable a b => (a -> a) -> b -> b
walk Inline -> Inline
hyphenToMinus (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
tok
(Inlines -> Inlines) -> LP m (Inlines -> Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines -> Inlines
superscript Inlines
n))
LP m (Inlines -> Inlines)
-> LP m (Inlines -> Inlines) -> LP m (Inlines -> Inlines)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '^' ParsecT [Tok] LaTeXState m Tok
-> LP m (Inlines -> Inlines) -> LP m (Inlines -> Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (do Inlines
n <- (Inline -> Inline) -> Inlines -> Inlines
forall a b. Walkable a b => (a -> a) -> b -> b
walk Inline -> Inline
hyphenToMinus (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
tok
(Inlines -> Inlines) -> LP m (Inlines -> Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines -> Inlines
superscript Inlines
n)))
LP m (Inlines -> Inlines)
-> LP m (Inlines -> Inlines) -> LP m (Inlines -> Inlines)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Char -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => Char -> LP m Tok
symbol '_' ParsecT [Tok] LaTeXState m Tok
-> LP m (Inlines -> Inlines) -> LP m (Inlines -> Inlines)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (do Inlines
n <- (Inline -> Inline) -> Inlines -> Inlines
forall a b. Walkable a b => (a -> a) -> b -> b
walk Inline -> Inline
hyphenToMinus (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
tok
(Inlines -> Inlines) -> LP m (Inlines -> Inlines)
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines -> Inlines
subscript Inlines
n)))
negateExponent :: Inlines -> Inlines
negateExponent :: Inlines -> Inlines
negateExponent ils :: Inlines
ils =
case Seq Inline -> ViewR Inline
forall a. Seq a -> ViewR a
Seq.viewr (Inlines -> Seq Inline
forall a. Many a -> Seq a
unMany Inlines
ils) of
xs :: Seq Inline
xs Seq.:> Superscript ss :: [Inline]
ss -> (Seq Inline -> Inlines
forall a. Seq a -> Many a
Many Seq Inline
xs) Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<>
Inlines -> Inlines
superscript (Text -> Inlines
str Text
minus Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> [Inline] -> Inlines
forall a. [a] -> Many a
fromList [Inline]
ss)
_ -> Inlines
ils Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines -> Inlines
superscript (Text -> Inlines
str (Text
minus Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "1"))
siBase :: LP m Inlines
siBase :: LP m Inlines
siBase =
((LP m Inlines -> LP m Inlines
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try
(do Tok _ (CtrlSeq name :: Text
name) _ <- ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => LP m Tok
anyControlSeq
case Text -> Map Text Inlines -> Maybe Inlines
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
name Map Text Inlines
siUnitModifierMap of
Just il :: Inlines
il -> (Inlines
il Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<>) (Inlines -> Inlines) -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> LP m Inlines
siBase
Nothing ->
case Text -> Map Text Inlines -> Maybe Inlines
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
name Map Text Inlines
siUnitMap of
Just il :: Inlines
il -> Inlines -> LP m Inlines
forall (f :: * -> *) a. Applicative f => a -> f a
pure Inlines
il
Nothing -> SourceName -> LP m Inlines
forall (m :: * -> *) a. MonadFail m => SourceName -> m a
fail "not a unit command"))
LP m Inlines -> LP m Inlines -> LP m Inlines
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (do Tok _ Word t :: Text
t <- (Tok -> Bool) -> ParsecT [Tok] LaTeXState m Tok
forall (m :: * -> *). PandocMonad m => (Tok -> Bool) -> LP m Tok
satisfyTok Tok -> Bool
isWordTok
Inlines -> LP m Inlines
forall (m :: * -> *) a. Monad m => a -> m a
return (Inlines -> LP m Inlines) -> Inlines -> LP m Inlines
forall a b. (a -> b) -> a -> b
$ Text -> Inlines
str Text
t)
)
siUnitModifierMap :: M.Map Text Inlines
siUnitModifierMap :: Map Text Inlines
siUnitModifierMap = [(Text, Inlines)] -> Map Text Inlines
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
[ ("atto", Text -> Inlines
str "a")
, ("centi", Text -> Inlines
str "c")
, ("deca", Text -> Inlines
str "d")
, ("deci", Text -> Inlines
str "d")
, ("deka", Text -> Inlines
str "d")
, ("exa", Text -> Inlines
str "E")
, ("femto", Text -> Inlines
str "f")
, ("giga", Text -> Inlines
str "G")
, ("hecto", Text -> Inlines
str "h")
, ("kilo", Text -> Inlines
str "k")
, ("mega", Text -> Inlines
str "M")
, ("micro", Text -> Inlines
str "μ")
, ("milli", Text -> Inlines
str "m")
, ("nano", Text -> Inlines
str "n")
, ("peta", Text -> Inlines
str "P")
, ("pico", Text -> Inlines
str "p")
, ("tera", Text -> Inlines
str "T")
, ("yocto", Text -> Inlines
str "y")
, ("yotta", Text -> Inlines
str "Y")
, ("zepto", Text -> Inlines
str "z")
, ("zetta", Text -> Inlines
str "Z")
]
siUnitMap :: M.Map Text Inlines
siUnitMap :: Map Text Inlines
siUnitMap = [(Text, Inlines)] -> Map Text Inlines
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
[ ("fg", Text -> Inlines
str "fg")
, ("pg", Text -> Inlines
str "pg")
, ("ng", Text -> Inlines
str "ng")
, ("ug", Text -> Inlines
str "μg")
, ("mg", Text -> Inlines
str "mg")
, ("g", Text -> Inlines
str "g")
, ("kg", Text -> Inlines
str "kg")
, ("amu", Text -> Inlines
str "u")
, ("pm", Text -> Inlines
str "pm")
, ("nm", Text -> Inlines
str "nm")
, ("um", Text -> Inlines
str "μm")
, ("mm", Text -> Inlines
str "mm")
, ("cm", Text -> Inlines
str "cm")
, ("dm", Text -> Inlines
str "dm")
, ("m", Text -> Inlines
str "m")
, ("km", Text -> Inlines
str "km")
, ("as", Text -> Inlines
str "as")
, ("fs", Text -> Inlines
str "fs")
, ("ps", Text -> Inlines
str "ps")
, ("ns", Text -> Inlines
str "ns")
, ("us", Text -> Inlines
str "μs")
, ("ms", Text -> Inlines
str "ms")
, ("s", Text -> Inlines
str "s")
, ("fmol", Text -> Inlines
str "fmol")
, ("pmol", Text -> Inlines
str "pmol")
, ("nmol", Text -> Inlines
str "nmol")
, ("umol", Text -> Inlines
str "μmol")
, ("mmol", Text -> Inlines
str "mmol")
, ("mol", Text -> Inlines
str "mol")
, ("kmol", Text -> Inlines
str "kmol")
, ("pA", Text -> Inlines
str "pA")
, ("nA", Text -> Inlines
str "nA")
, ("uA", Text -> Inlines
str "μA")
, ("mA", Text -> Inlines
str "mA")
, ("A", Text -> Inlines
str "A")
, ("kA", Text -> Inlines
str "kA")
, ("ul", Text -> Inlines
str "μl")
, ("ml", Text -> Inlines
str "ml")
, ("l", Text -> Inlines
str "l")
, ("hl", Text -> Inlines
str "hl")
, ("uL", Text -> Inlines
str "μL")
, ("mL", Text -> Inlines
str "mL")
, ("L", Text -> Inlines
str "L")
, ("hL", Text -> Inlines
str "hL")
, ("mHz", Text -> Inlines
str "mHz")
, ("Hz", Text -> Inlines
str "Hz")
, ("kHz", Text -> Inlines
str "kHz")
, ("MHz", Text -> Inlines
str "MHz")
, ("GHz", Text -> Inlines
str "GHz")
, ("THz", Text -> Inlines
str "THz")
, ("mN", Text -> Inlines
str "mN")
, ("N", Text -> Inlines
str "N")
, ("kN", Text -> Inlines
str "kN")
, ("MN", Text -> Inlines
str "MN")
, ("Pa", Text -> Inlines
str "Pa")
, ("kPa", Text -> Inlines
str "kPa")
, ("MPa", Text -> Inlines
str "MPa")
, ("GPa", Text -> Inlines
str "GPa")
, ("mohm", Text -> Inlines
str "mΩ")
, ("kohm", Text -> Inlines
str "kΩ")
, ("Mohm", Text -> Inlines
str "MΩ")
, ("pV", Text -> Inlines
str "pV")
, ("nV", Text -> Inlines
str "nV")
, ("uV", Text -> Inlines
str "μV")
, ("mV", Text -> Inlines
str "mV")
, ("V", Text -> Inlines
str "V")
, ("kV", Text -> Inlines
str "kV")
, ("W", Text -> Inlines
str "W")
, ("uW", Text -> Inlines
str "μW")
, ("mW", Text -> Inlines
str "mW")
, ("kW", Text -> Inlines
str "kW")
, ("MW", Text -> Inlines
str "MW")
, ("GW", Text -> Inlines
str "GW")
, ("J", Text -> Inlines
str "J")
, ("uJ", Text -> Inlines
str "μJ")
, ("mJ", Text -> Inlines
str "mJ")
, ("kJ", Text -> Inlines
str "kJ")
, ("eV", Text -> Inlines
str "eV")
, ("meV", Text -> Inlines
str "meV")
, ("keV", Text -> Inlines
str "keV")
, ("MeV", Text -> Inlines
str "MeV")
, ("GeV", Text -> Inlines
str "GeV")
, ("TeV", Text -> Inlines
str "TeV")
, ("kWh", Text -> Inlines
str "kWh")
, ("F", Text -> Inlines
str "F")
, ("fF", Text -> Inlines
str "fF")
, ("pF", Text -> Inlines
str "pF")
, ("K", Text -> Inlines
str "K")
, ("dB", Text -> Inlines
str "dB")
, ("ampere", Text -> Inlines
str "A")
, ("angstrom", Text -> Inlines
str "Å")
, ("arcmin", Text -> Inlines
str "′")
, ("arcminute", Text -> Inlines
str "′")
, ("arcsecond", Text -> Inlines
str "″")
, ("astronomicalunit", Text -> Inlines
str "ua")
, ("atomicmassunit", Text -> Inlines
str "u")
, ("bar", Text -> Inlines
str "bar")
, ("barn", Text -> Inlines
str "b")
, ("becquerel", Text -> Inlines
str "Bq")
, ("bel", Text -> Inlines
str "B")
, ("bohr", Inlines -> Inlines
emph (Text -> Inlines
str "a") Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines -> Inlines
subscript (Text -> Inlines
str "0"))
, ("candela", Text -> Inlines
str "cd")
, ("celsius", Text -> Inlines
str "°C")
, ("clight", Inlines -> Inlines
emph (Text -> Inlines
str "c") Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines -> Inlines
subscript (Text -> Inlines
str "0"))
, ("coulomb", Text -> Inlines
str "C")
, ("dalton", Text -> Inlines
str "Da")
, ("day", Text -> Inlines
str "d")
, ("decibel", Text -> Inlines
str "db")
, ("degreeCelsius",Text -> Inlines
str "°C")
, ("degree", Text -> Inlines
str "°")
, ("electronmass", Inlines -> Inlines
emph (Text -> Inlines
str "m") Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines -> Inlines
subscript (Text -> Inlines
str "e"))
, ("electronvolt", Text -> Inlines
str "eV")
, ("elementarycharge", Inlines -> Inlines
emph (Text -> Inlines
str "e"))
, ("farad", Text -> Inlines
str "F")
, ("gram", Text -> Inlines
str "g")
, ("gray", Text -> Inlines
str "Gy")
, ("hartree", Inlines -> Inlines
emph (Text -> Inlines
str "E") Inlines -> Inlines -> Inlines
forall a. Semigroup a => a -> a -> a
<> Inlines -> Inlines
subscript (Text -> Inlines
str "h"))
, ("hectare", Text -> Inlines
str "ha")
, ("henry", Text -> Inlines
str "H")
, ("hertz", Text -> Inlines
str "Hz")
, ("hour", Text -> Inlines
str "h")
, ("joule", Text -> Inlines
str "J")
, ("katal", Text -> Inlines
str "kat")
, ("kelvin", Text -> Inlines
str "K")
, ("kilogram", Text -> Inlines
str "kg")
, ("knot", Text -> Inlines
str "kn")
, ("liter", Text -> Inlines
str "L")
, ("litre", Text -> Inlines
str "l")
, ("lumen", Text -> Inlines
str "lm")
, ("lux", Text -> Inlines
str "lx")
, ("meter", Text -> Inlines
str "m")
, ("metre", Text -> Inlines
str "m")
, ("minute", Text -> Inlines
str "min")
, ("mmHg", Text -> Inlines
str "mmHg")
, ("mole", Text -> Inlines
str "mol")
, ("nauticalmile", Text -> Inlines
str "M")
, ("neper", Text -> Inlines
str "Np")
, ("newton", Text -> Inlines
str "N")
, ("ohm", Text -> Inlines
str "Ω")
, ("Pa", Text -> Inlines
str "Pa")
, ("pascal", Text -> Inlines
str "Pa")
, ("percent", Text -> Inlines
str "%")
, ("planckbar", Inlines -> Inlines
emph (Text -> Inlines
str "\x210f"))
, ("radian", Text -> Inlines
str "rad")
, ("second", Text -> Inlines
str "s")
, ("siemens", Text -> Inlines
str "S")
, ("sievert", Text -> Inlines
str "Sv")
, ("steradian", Text -> Inlines
str "sr")
, ("tesla", Text -> Inlines
str "T")
, ("tonne", Text -> Inlines
str "t")
, ("volt", Text -> Inlines
str "V")
, ("watt", Text -> Inlines
str "W")
, ("weber", Text -> Inlines
str "Wb")
]