Skip to content

Commit

Permalink
Support locale-based separator for LaTeX SIRange
Browse files Browse the repository at this point in the history
Try to get a locale-based separator SI units in doSIRange ("to" in
English) and fall back to an en-dash if one is not found.
Currently, unit tests are only available for English using "to" as
a separator.
  • Loading branch information
efharkin committed Jun 6, 2020
1 parent 116ec3f commit bdc370c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/Text/Pandoc/Readers/LaTeX.hs
Expand Up @@ -269,12 +269,18 @@ doSIRange = do
unit <- grouped (mconcat <$> many1 siUnit) <|> siUnit <|> tok
let emptyOr160 "" = ""
emptyOr160 _ = "\160"
localTo <- translateTerm Translations.To
let separator = (if localTo /= ""
then text $ T.toLower localTo
else "\8211")
return . mconcat $ [startvalueprefix,
emptyOr160 startvalueprefix,
startvalue,
emptyOr160 unit,
unit,
" \8211 ", -- An en-dash
text " ",
separator,
text " ",
stopvalueprefix,
emptyOr160 stopvalueprefix,
stopvalue,
Expand Down
14 changes: 7 additions & 7 deletions test/command/3587.md
Expand Up @@ -63,19 +63,19 @@
% pandoc -f latex -t native
\SIRange{10}{20}{\gram}
^D
[Para [Str "10\160g",Space,Str "\8211",Space,Str "20\160g"]]
[Para [Str "10\160g",Space,Str "to",Space,Str "20\160g"]]
```
```
% pandoc -f latex -t native
\SIRange{35}{9}{\milli\meter}
^D
[Para [Str "35\160mm",Space,Str "\8211",Space,Str "9\160mm"]]
[Para [Str "35\160mm",Space,Str "to",Space,Str "9\160mm"]]
```
```
% pandoc -f latex -t native
\SIRange{4}{97367265}{\celsius}
^D
[Para [Str "4\160\176C",Space,Str "\8211",Space,Str "97367265\160\176C"]]
[Para [Str "4\160\176C",Space,Str "to",Space,Str "97367265\160\176C"]]
```

## Decimal range with simple units
Expand All @@ -84,7 +84,7 @@
% pandoc -f latex -t native
\SIRange{4.5}{97367265.5}{\celsius}
^D
[Para [Str "4.5\160\176C",Space,Str "\8211",Space,Str "97367265.5\160\176C"]]
[Para [Str "4.5\160\176C",Space,Str "to",Space,Str "97367265.5\160\176C"]]
```

## Squared units
Expand All @@ -93,7 +93,7 @@
% pandoc -f latex -t native
\SIRange{10}{20}{\square\meter}
^D
[Para [Str "10\160m\178",Space,Str "\8211",Space,Str "20\160m\178"]]
[Para [Str "10\160m\178",Space,Str "to",Space,Str "20\160m\178"]]
```

## Ignore round precision
Expand All @@ -105,12 +105,12 @@
% pandoc -f latex -t native
\SIRange[round-precision=2]{10}{20}{\gram}
^D
[Para [Str "10\160g",Space,Str "\8211",Space,Str "20\160g"]]
[Para [Str "10\160g",Space,Str "to",Space,Str "20\160g"]]
```
```
% pandoc -f latex -t native
\SIRange[round-precision=2]{10.0}{20.25}{\gram}
^D
[Para [Str "10.0\160g",Space,Str "\8211",Space,Str "20.25\160g"]]
[Para [Str "10.0\160g",Space,Str "to",Space,Str "20.25\160g"]]
```

0 comments on commit bdc370c

Please sign in to comment.