diff options
author | John MacFarlane <jgm@berkeley.edu> | 2018-08-17 15:22:47 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2018-08-17 15:22:47 -0700 |
commit | 1b668657632c58964e8d7df42ea88e5ea6abfb1e (patch) | |
tree | 15321183db834685650bc881686a8edf4919182e /src/Text/Pandoc/Readers | |
parent | 723b60b42ed875011a73975ac1d4b9e7d780ea8f (diff) | |
download | pandoc-1b668657632c58964e8d7df42ea88e5ea6abfb1e.tar.gz |
LaTeX reader: fix siunitx unit commands...
...they should only be recognized in siunitx contexts.
For example, `\l` outside of an siunitx context should be l-slash,
not l (for liter)!
Closes #4842.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 356 |
1 files changed, 182 insertions, 174 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index afd0f34b9..ebcb9fecf 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -735,7 +735,7 @@ dosiunitx = do skipopts value <- tok valueprefix <- option "" $ bracketed tok - unit <- inlineCommand' <|> tok + unit <- grouped (mconcat <$> many1 siUnit) <|> siUnit <|> tok let emptyOr160 "" = "" emptyOr160 _ = "\160" return . mconcat $ [valueprefix, @@ -744,11 +744,187 @@ dosiunitx = do emptyOr160 unit, unit] --- siunitx's \square command -dosquare :: PandocMonad m => LP m Inlines -dosquare = do - unit <- inlineCommand' <|> tok - return . mconcat $ [unit, "\178"] +siUnit :: PandocMonad m => LP m Inlines +siUnit = do + Tok _ (CtrlSeq name) cmd <- anyControlSeq + if name == "square" + then do + unit <- grouped (mconcat <$> many1 siUnit) <|> siUnit <|> tok + return . mconcat $ [unit, "\178"] + else + case M.lookup name siUnitMap of + Just il -> return il + Nothing -> mzero + +siUnitMap :: M.Map Text Inlines +siUnitMap = M.fromList + [ ("fg", str "fg") + , ("pg", str "pg") + , ("ng", str "ng") + , ("ug", str "μg") + , ("mg", str "mg") + , ("g", str "g") + , ("kg", str "kg") + , ("amu", str "u") + , ("pm", str "pm") + , ("nm", str "nm") + , ("um", str "μm") + , ("mm", str "mm") + , ("cm", str "cm") + , ("dm", str "dm") + , ("m", str "m") + , ("km", str "km") + , ("as", str "as") + , ("fs", str "fs") + , ("ps", str "ps") + , ("ns", str "ns") + , ("us", str "μs") + , ("ms", str "ms") + , ("s", str "s") + , ("fmol", str "fmol") + , ("pmol", str "pmol") + , ("nmol", str "nmol") + , ("umol", str "μmol") + , ("mmol", str "mmol") + , ("mol", str "mol") + , ("kmol", str "kmol") + , ("pA", str "pA") + , ("nA", str "nA") + , ("uA", str "μA") + , ("mA", str "mA") + , ("A", str "A") + , ("kA", str "kA") + , ("ul", str "μl") + , ("ml", str "ml") + , ("l", str "l") + , ("hl", str "hl") + , ("uL", str "μL") + , ("mL", str "mL") + , ("L", str "L") + , ("hL", str "hL") + , ("mHz", str "mHz") + , ("Hz", str "Hz") + , ("kHz", str "kHz") + , ("MHz", str "MHz") + , ("GHz", str "GHz") + , ("THz", str "THz") + , ("mN", str "mN") + , ("N", str "N") + , ("kN", str "kN") + , ("MN", str "MN") + , ("Pa", str "Pa") + , ("kPa", str "kPa") + , ("MPa", str "MPa") + , ("GPa", str "GPa") + , ("mohm", str "mΩ") + , ("kohm", str "kΩ") + , ("Mohm", str "MΩ") + , ("pV", str "pV") + , ("nV", str "nV") + , ("uV", str "μV") + , ("mV", str "mV") + , ("V", str "V") + , ("kV", str "kV") + , ("W", str "W") + , ("uW", str "μW") + , ("mW", str "mW") + , ("kW", str "kW") + , ("MW", str "MW") + , ("GW", str "GW") + , ("J", str "J") + , ("uJ", str "μJ") + , ("mJ", str "mJ") + , ("kJ", str "kJ") + , ("eV", str "eV") + , ("meV", str "meV") + , ("keV", str "keV") + , ("MeV", str "MeV") + , ("GeV", str "GeV") + , ("TeV", str "TeV") + , ("kWh", str "kWh") + , ("F", str "F") + , ("fF", str "fF") + , ("pF", str "pF") + , ("K", str "K") + , ("dB", str "dB") + , ("angstrom", str "Å") + , ("arcmin", str "′") + , ("arcminute", str "′") + , ("arcsecond", str "″") + , ("astronomicalunit", str "ua") + , ("atomicmassunit", str "u") + , ("atto", str "a") + , ("bar", str "bar") + , ("barn", str "b") + , ("becquerel", str "Bq") + , ("bel", str "B") + , ("candela", str "cd") + , ("celsius", str "°C") + , ("centi", str "c") + , ("coulomb", str "C") + , ("dalton", str "Da") + , ("day", str "d") + , ("deca", str "d") + , ("deci", str "d") + , ("decibel", str "db") + , ("degreeCelsius",str "°C") + , ("degree", str "°") + , ("deka", str "d") + , ("electronvolt", str "eV") + , ("exa", str "E") + , ("farad", str "F") + , ("femto", str "f") + , ("giga", str "G") + , ("gram", str "g") + , ("hectare", str "ha") + , ("hecto", str "h") + , ("henry", str "H") + , ("hertz", str "Hz") + , ("hour", str "h") + , ("joule", str "J") + , ("katal", str "kat") + , ("kelvin", str "K") + , ("kilo", str "k") + , ("kilogram", str "kg") + , ("knot", str "kn") + , ("liter", str "L") + , ("litre", str "l") + , ("lumen", str "lm") + , ("lux", str "lx") + , ("mega", str "M") + , ("meter", str "m") + , ("metre", str "m") + , ("milli", str "m") + , ("minute", str "min") + , ("mmHg", str "mmHg") + , ("mole", str "mol") + , ("nano", str "n") + , ("nauticalmile", str "M") + , ("neper", str "Np") + , ("newton", str "N") + , ("ohm", str "Ω") + , ("Pa", str "Pa") + , ("pascal", str "Pa") + , ("percent", str "%") + , ("per", str "/") + , ("peta", str "P") + , ("pico", str "p") + , ("radian", str "rad") + , ("second", str "s") + , ("siemens", str "S") + , ("sievert", str "Sv") + , ("steradian", str "sr") + , ("tera", str "T") + , ("tesla", str "T") + , ("tonne", str "t") + , ("volt", str "V") + , ("watt", str "W") + , ("weber", str "Wb") + , ("yocto", str "y") + , ("yotta", str "Y") + , ("zepto", str "z") + , ("zetta", str "Z") + ] lit :: String -> LP m Inlines lit = pure . str @@ -1594,174 +1770,6 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList , ("acsp", doAcronymPlural "abbrv") -- siuntix , ("SI", dosiunitx) - -- units of siuntix - , ("fg", lit "fg") - , ("pg", lit "pg") - , ("ng", lit "ng") - , ("ug", lit "μg") - , ("mg", lit "mg") - , ("g", lit "g") - , ("kg", lit "kg") - , ("amu", lit "u") - , ("pm", lit "pm") - , ("nm", lit "nm") - , ("um", lit "μm") - , ("mm", lit "mm") - , ("cm", lit "cm") - , ("dm", lit "dm") - , ("m", lit "m") - , ("km", lit "km") - , ("as", lit "as") - , ("fs", lit "fs") - , ("ps", lit "ps") - , ("ns", lit "ns") - , ("us", lit "μs") - , ("ms", lit "ms") - , ("s", lit "s") - , ("fmol", lit "fmol") - , ("pmol", lit "pmol") - , ("nmol", lit "nmol") - , ("umol", lit "μmol") - , ("mmol", lit "mmol") - , ("mol", lit "mol") - , ("kmol", lit "kmol") - , ("pA", lit "pA") - , ("nA", lit "nA") - , ("uA", lit "μA") - , ("mA", lit "mA") - , ("A", lit "A") - , ("kA", lit "kA") - , ("ul", lit "μl") - , ("ml", lit "ml") - , ("l", lit "l") - , ("hl", lit "hl") - , ("uL", lit "μL") - , ("mL", lit "mL") - , ("L", lit "L") - , ("hL", lit "hL") - , ("mHz", lit "mHz") - , ("Hz", lit "Hz") - , ("kHz", lit "kHz") - , ("MHz", lit "MHz") - , ("GHz", lit "GHz") - , ("THz", lit "THz") - , ("mN", lit "mN") - , ("N", lit "N") - , ("kN", lit "kN") - , ("MN", lit "MN") - , ("Pa", lit "Pa") - , ("kPa", lit "kPa") - , ("MPa", lit "MPa") - , ("GPa", lit "GPa") - , ("mohm", lit "mΩ") - , ("kohm", lit "kΩ") - , ("Mohm", lit "MΩ") - , ("pV", lit "pV") - , ("nV", lit "nV") - , ("uV", lit "μV") - , ("mV", lit "mV") - , ("V", lit "V") - , ("kV", lit "kV") - , ("W", lit "W") - , ("uW", lit "μW") - , ("mW", lit "mW") - , ("kW", lit "kW") - , ("MW", lit "MW") - , ("GW", lit "GW") - , ("J", lit "J") - , ("uJ", lit "μJ") - , ("mJ", lit "mJ") - , ("kJ", lit "kJ") - , ("eV", lit "eV") - , ("meV", lit "meV") - , ("keV", lit "keV") - , ("MeV", lit "MeV") - , ("GeV", lit "GeV") - , ("TeV", lit "TeV") - , ("kWh", lit "kWh") - , ("F", lit "F") - , ("fF", lit "fF") - , ("pF", lit "pF") - , ("K", lit "K") - , ("dB", lit "dB") - , ("angstrom", lit "Å") - , ("arcmin", lit "′") - , ("arcminute", lit "′") - , ("arcsecond", lit "″") - , ("astronomicalunit", lit "ua") - , ("atomicmassunit", lit "u") - , ("atto", lit "a") - , ("bar", lit "bar") - , ("barn", lit "b") - , ("becquerel", lit "Bq") - , ("bel", lit "B") - , ("candela", lit "cd") - , ("celsius", lit "°C") - , ("centi", lit "c") - , ("coulomb", lit "C") - , ("dalton", lit "Da") - , ("day", lit "d") - , ("deca", lit "d") - , ("deci", lit "d") - , ("decibel", lit "db") - , ("degreeCelsius",lit "°C") - , ("degree", lit "°") - , ("deka", lit "d") - , ("electronvolt", lit "eV") - , ("exa", lit "E") - , ("farad", lit "F") - , ("femto", lit "f") - , ("giga", lit "G") - , ("gram", lit "g") - , ("hectare", lit "ha") - , ("hecto", lit "h") - , ("henry", lit "H") - , ("hertz", lit "Hz") - , ("hour", lit "h") - , ("joule", lit "J") - , ("katal", lit "kat") - , ("kelvin", lit "K") - , ("kilo", lit "k") - , ("kilogram", lit "kg") - , ("knot", lit "kn") - , ("liter", lit "L") - , ("litre", lit "l") - , ("lumen", lit "lm") - , ("lux", lit "lx") - , ("mega", lit "M") - , ("meter", lit "m") - , ("metre", lit "m") - , ("milli", lit "m") - , ("minute", lit "min") - , ("mmHg", lit "mmHg") - , ("mole", lit "mol") - , ("nano", lit "n") - , ("nauticalmile", lit "M") - , ("neper", lit "Np") - , ("newton", lit "N") - , ("ohm", lit "Ω") - , ("Pa", lit "Pa") - , ("pascal", lit "Pa") - , ("percent", lit "%") - , ("per", lit "/") - , ("peta", lit "P") - , ("pico", lit "p") - , ("radian", lit "rad") - , ("second", lit "s") - , ("siemens", lit "S") - , ("sievert", lit "Sv") - , ("square", dosquare) - , ("steradian", lit "sr") - , ("tera", lit "T") - , ("tesla", lit "T") - , ("tonne", lit "t") - , ("volt", lit "V") - , ("watt", lit "W") - , ("weber", lit "Wb") - , ("yocto", lit "y") - , ("yotta", lit "Y") - , ("zepto", lit "z") - , ("zetta", lit "Z") -- hyphenat , ("bshyp", lit "\\\173") , ("fshyp", lit "/\173") |