From 1b8f1611983706f81cc33db4c4fe0ce379973c65 Mon Sep 17 00:00:00 2001 From: Emerson Harkin Date: Thu, 23 Jul 2020 19:47:32 -0400 Subject: Minimal support for SIRange in LaTeX reader (#6418) Add support for `\SIRange{firstnumber}{secondnumber}{unit}` provided by siunitx. An en-dash is used instead of localized "to". --- src/Text/Pandoc/Readers/LaTeX.hs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 1c6954279..af00813b6 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -259,6 +259,29 @@ dosiunitx = do emptyOr160 unit, unit] +-- converts e.g. \SIRange{100}{200}{\ms} to "100 ms--200 ms" +doSIRange :: PandocMonad m => LP m Inlines +doSIRange = do + skipopts + startvalue <- tok + startvalueprefix <- option "" $ bracketed tok + stopvalue <- tok + stopvalueprefix <- option "" $ bracketed tok + unit <- grouped (mconcat <$> many1 siUnit) <|> siUnit <|> tok + let emptyOr160 "" = "" + emptyOr160 _ = "\160" + return . mconcat $ [startvalueprefix, + emptyOr160 startvalueprefix, + startvalue, + emptyOr160 unit, + unit, + "\8211", -- An en-dash + stopvalueprefix, + emptyOr160 stopvalueprefix, + stopvalue, + emptyOr160 unit, + unit] + siUnit :: PandocMonad m => LP m Inlines siUnit = do Tok _ (CtrlSeq name) _ <- anyControlSeq @@ -1075,6 +1098,7 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList , ("acsp", doAcronymPlural "abbrv") -- siuntix , ("SI", dosiunitx) + , ("SIRange", doSIRange) -- hyphenat , ("bshyp", lit "\\\173") , ("fshyp", lit "/\173") -- cgit v1.2.3