jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.87k stars 3.39k forks source link

siunitx - support international number formats #8850

Open tk-100 opened 1 year ago

tk-100 commented 1 year ago

Would it be possible to take the language of the current document into account?

Example markdown file:

---
title: siunitx test
lang: de-DE
---

Term: $m=\SI{1.5e2}{\kilo\gram}$

Used command for conversion:

pandoc -s --mathml test.md -o test.html

Output:

grafik

I would expect (for locale de-DE):

If a general implementation is too complex - would it be possible to offer options for siunitx? So the users could change the decimal separator and multiplication sign by themselves.

jgm commented 1 year ago

A bit tricky because jgm/texmath handles the math conversion, but doesn't have access to the lang metadata.

tk-100 commented 1 year ago

Oh, I see. Would it be possible to pass pandoc variables to jgm/texmath?

I would suggest something like:

siunitx-locale or siunitx-lang with default "en-US" (or similar)

This variable would then affect the following lines in SIunitx.hs:

krtko1 commented 1 year ago

Another solution might be to add support for \sisetup

fermifunktion commented 5 months ago

I would like to convert LaTeX files (using siunitx) to Word files and change the standard symbols for "times" (× to ·) and decimal sign (. to ,) , therefore downloaded the source files of pandoc and compiled locally, but I have no idea, where the default symbols are defined within the source. Could you guide me in the right direction? Many thanks in advance!

jgm commented 5 months ago

Another approach, I suppose, would be to have pandoc resolve the sinunitx macros, converting them to regular TeX math, before passing the math to texmath for conversion. In this context pandoc would have access to lang metadata.

jgm commented 5 months ago

As for \times, you can simply add a macro definition in your source \newcommand{\times}{\cdot} or whatever. Pandoc will handle that. But the decimal point can't be remapped so easily.

fermifunktion commented 5 months ago

Unfortunately, redefining \times did not work for me (and it would not help on changing the decimal sign either).

So in a next step I downloaded texmath and changed parseNumPart, ParseComma and parseExp accordingly in src/Text/TeXMath/Readers/TeX.hs. Now (after stack install) by running texmath in the command line, the substitutions work perfectly, but not when calling pandoc. Is there a way to tell pandoc to use the locally installed version of texmath? How could I link the local version of texmath to pandoc during the compilation of pandoc?

Sorry for that stupid kind of questions, but I am not used to Haskell and friends. Many thanks in advance!

jgm commented 4 months ago

Is there a way to tell pandoc to use the locally installed version of texmath?

Yes. You'd need to add something to cabal.project (assuming you're using cabal and not stack to compile).

Something like

source-repository-package
  type: git
  location: https://github.com/jgm/typst-hs
  tag: 7e0e80548aae9f3d3059f0dae333e93c8d67f290

but with the location of your texmath for location and the appropriate commit hash for tag.

jgm commented 4 months ago

For stack.yaml, if you're using stack, replace the existing texmath item in extra-deps with something like this, appropriately modified:

- git: https://github.com/jgm/typst-hs
  commit: 7e0e80548aae9f3d3059f0dae333e93c8d67f290
fermifunktion commented 4 months ago

Thanks for the quick reply. I was able to use my local install of texmath to compile a version of pandoc now using my changed locale settings. Thanks for your help!