@@ -57,6 +57,7 @@ import Text.Pandoc.Readers.LaTeX.Types (ExpansionPoint (..), Macro (..),
57import Text.Pandoc.Readers.LaTeX.Parsing
57import Text.Pandoc.Readers.LaTeX.Parsing
58import Text.Pandoc.Readers.LaTeX.Lang (polyglossiaLangToBCP47,
58import Text.Pandoc.Readers.LaTeX.Lang (polyglossiaLangToBCP47,
59 babelLangToBCP47)
59 babelLangToBCP47)
60+import Text.Pandoc.Readers.LaTeX.SIunitx
60import Text.Pandoc.Shared
61import Text.Pandoc.Shared
61import qualified Text.Pandoc.Translations as Translations
62import qualified Text.Pandoc.Translations as Translations
62import Text.Pandoc.Walk
63import Text.Pandoc.Walk
@@ -244,227 +245,6 @@ doxspace =
244 startsWithLetter _ = False
245 startsWithLetter _ = False
247−-- converts e.g. \SI{1}[\$]{} to "$ 1" or \SI{1}{\euro} to "1 €"
248−dosiunitx :: PandocMonad m => LP m Inlines
252− valueprefix <- option "" $ bracketed tok
253− unit <- grouped (mconcat <$> many1 siUnit) <|> siUnit <|> tok
254− let emptyOr160 "" = ""
255− emptyOr160 _ = "\160"
256− return . mconcat $ [valueprefix,
257− emptyOr160 valueprefix,
262−-- converts e.g. \SIrange{100}{200}{\ms} to "100 ms--200 ms"
263−doSIrange :: PandocMonad m => LP m Inlines
267− startvalueprefix <- option "" $ bracketed tok
269− stopvalueprefix <- option "" $ bracketed tok
270− unit <- grouped (mconcat <$> many1 siUnit) <|> siUnit <|> tok
271− let emptyOr160 "" = ""
272− emptyOr160 _ = "\160"
273− return . mconcat $ [startvalueprefix,
274− emptyOr160 startvalueprefix,
278− "\8211", -- An en-dash
280− emptyOr160 stopvalueprefix,
285−siUnit :: PandocMonad m => LP m Inlines
287− Tok _ (CtrlSeq name) _ <- anyControlSeq
290− unit <- grouped (mconcat <$> many1 siUnit) <|> siUnit <|> tok
291− return . mconcat $ [unit, "\178"]
293− case M.lookup name siUnitMap of
294− Just il -> return il
297−siUnitMap :: M.Map Text Inlines
298−siUnitMap = M.fromList
322− , ("fmol", str "fmol")
323− , ("pmol", str "pmol")
324− , ("nmol", str "nmol")
325− , ("umol", str "μmol")
326− , ("mmol", str "mmol")
327− , ("mol", str "mol")
328− , ("kmol", str "kmol")
343− , ("mHz", str "mHz")
345− , ("kHz", str "kHz")
346− , ("MHz", str "MHz")
347− , ("GHz", str "GHz")
348− , ("THz", str "THz")
354− , ("kPa", str "kPa")
355− , ("MPa", str "MPa")
356− , ("GPa", str "GPa")
357− , ("mohm", str "mΩ")
358− , ("kohm", str "kΩ")
359− , ("Mohm", str "MΩ")
377− , ("meV", str "meV")
378− , ("keV", str "keV")
379− , ("MeV", str "MeV")
380− , ("GeV", str "GeV")
381− , ("TeV", str "TeV")
382− , ("kWh", str "kWh")
388− , ("angstrom", str "Å")
389− , ("arcmin", str "′")
390− , ("arcminute", str "′")
391− , ("arcsecond", str "″")
392− , ("astronomicalunit", str "ua")
393− , ("atomicmassunit", str "u")
395− , ("bar", str "bar")
397− , ("becquerel", str "Bq")
399− , ("candela", str "cd")
400− , ("celsius", str "°C")
401− , ("centi", str "c")
402− , ("coulomb", str "C")
403− , ("dalton", str "Da")
407− , ("decibel", str "db")
408− , ("degreeCelsius",str "°C")
409− , ("degree", str "°")
411− , ("electronvolt", str "eV")
413− , ("farad", str "F")
414− , ("femto", str "f")
417− , ("hectare", str "ha")
418− , ("hecto", str "h")
419− , ("henry", str "H")
420− , ("hertz", str "Hz")
422− , ("joule", str "J")
423− , ("katal", str "kat")
424− , ("kelvin", str "K")
426− , ("kilogram", str "kg")
427− , ("knot", str "kn")
428− , ("liter", str "L")
429− , ("litre", str "l")
430− , ("lumen", str "lm")
433− , ("meter", str "m")
434− , ("metre", str "m")
435− , ("micro", str "μ")
436− , ("milli", str "m")
437− , ("minute", str "min")
438− , ("mmHg", str "mmHg")
439− , ("mole", str "mol")
441− , ("nauticalmile", str "M")
442− , ("neper", str "Np")
443− , ("newton", str "N")
446− , ("pascal", str "Pa")
447− , ("percent", str "%")
451− , ("radian", str "rad")
452− , ("second", str "s")
453− , ("siemens", str "S")
454− , ("sievert", str "Sv")
455− , ("steradian", str "sr")
457− , ("tesla", str "T")
458− , ("tonne", str "t")
461− , ("weber", str "Wb")
462− , ("yocto", str "y")
463− , ("yotta", str "Y")
464− , ("zepto", str "z")
465− , ("zetta", str "Z")
468lit :: Text -> LP m Inlines
248lit :: Text -> LP m Inlines
469lit = pure . str
249lit = pure . str
@@ -1097,8 +877,8 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList
1097 , ("acfp", doAcronymPlural "full")
877 , ("acfp", doAcronymPlural "full")
1098 , ("acsp", doAcronymPlural "abbrv")
878 , ("acsp", doAcronymPlural "abbrv")
1099 -- siuntix
879 -- siuntix
1100− , ("SI", dosiunitx)
880+ , ("SI", dosiunitx tok)
1101− , ("SIrange", doSIrange)
881+ , ("SIrange", doSIrange tok)
1102 -- hyphenat
882 -- hyphenat
1103 , ("bshyp", lit "\\\173")
883 , ("bshyp", lit "\\\173")
1104 , ("fshyp", lit "/\173")
884 , ("fshyp", lit "/\173")