Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

siunitx commands not working inside math, align and tabular modes #185

Open
BishopWolf opened this issue Jan 7, 2022 · 13 comments
Open

Comments

@BishopWolf
Copy link

inside math or align mode mode:

$T_{1/2}=\qty{8.0197}{days}$ gives the error

[WARNING] Could not convert TeX math T_{1/2}=\qty{8.0197}{days}, rendering as TeX:
  T_{1/2}=\qty{8.0197}{days}
              ^
  unexpected control sequence \qty
  expecting "%", "\\label", "\\tag", "\\nonumber" or whitespace

inside tabular mode the table is not even rendered.

The problem is the same for all siunitx commands \num ; \qty ; \unit

@jgm
Copy link
Owner

jgm commented Jan 7, 2022

That's right. We have pretty good support for siunitx in pandoc in text mode:
https://github.com/jgm/pandoc/blob/master/src/Text/Pandoc/Readers/LaTeX/SIunitx.hs

But in math mode, everything is sent to this library.
We'd have to reproduce the work done in pandoc here.
Ideally, a lot of this could be factored out into a subsidiary library that both pandoc and texmath could import, or perhaps an additional exported module in texmath.

@jgm
Copy link
Owner

jgm commented Jan 8, 2022

Note that we do have some support for siunitx in texmath. Just not complete, e.g. not \qty.

jgm added a commit that referenced this issue Jan 8, 2022
@jgm
Copy link
Owner

jgm commented Jan 8, 2022

I've pushed support for \qty, \unit, and \qtyrange.

@jiucenglou
Copy link

I've pushed support for \qty, \unit, and \qtyrange.

Could you suggest where to find the list of the supported siunitx commands ? Could one use \DeclareSIUnit to define new units in the *.yaml header for markdown input ?

@jgm
Copy link
Owner

jgm commented Jan 6, 2023

Sorry, \DeclareSIUnit is not supported.
For current siunitx support in texmath, see https://github.com/jgm/texmath/blob/master/src/Text/TeXMath/Readers/TeX.hs#L1133

@jiucenglou
Copy link

Sorry, \DeclareSIUnit is not supported. For current siunitx support in texmath, see https://github.com/jgm/texmath/blob/master/src/Text/TeXMath/Readers/TeX.hs#L1133

Would it be possible to support \DeclareSIUnit in pandoc ? There are a number of units that are popular in the relevant field but not SI.

@jgm
Copy link
Owner

jgm commented Jan 7, 2023

Are you talking about converting from LaTeX or from markdown with LaTeX math?

@jiucenglou
Copy link

Are you talking about converting from LaTeX or from markdown with LaTeX math?

I am talking about converting from markdown with LaTeX math. (Is it correct to assume the markdown format is the best format supported by Pandoc ?)

@jgm
Copy link
Owner

jgm commented Jan 8, 2023

Complex siunitex stuff will probably work better if you're converting from LaTeX, because then pandoc uses its own fairly complex LaTeX parser. For math in markdown, it goes through the texmath library, which has more limited siunitex support (jgm/texmath).

Support for \DeclareSIUnit could, in principle, be added to the LaTeX reader, but I don't know how feasible it would be to add it to texmath.

@jiucenglou
Copy link

jiucenglou commented Jan 8, 2023

Complex siunitex stuff will probably work better if you're converting from LaTeX, because then pandoc uses its own fairly complex LaTeX parser. For math in markdown, it goes through the texmath library, which has more limited siunitex support (jgm/texmath).

Support for \DeclareSIUnit could, in principle, be added to the LaTeX reader, but I don't know how feasible it would be to add it to texmath.

Many thanks for your efforts and comments !
Could you suggest whether LaTeX format is a better source format than markdown format when both Word and PDF are target formats ?

@jgm
Copy link
Owner

jgm commented Jan 8, 2023

The LaTeX reader of course can only handle a subset of LaTeX. If you can stay within that subset it might work well for you.

@jiucenglou
Copy link

The LaTeX reader of course can only handle a subset of LaTeX. If you can stay within that subset it might work well for you.

If markdown format is a better source format when both Word and PDF are target formats, I would think that support for \DeclareSIUnit in texmath would be very helpful since non-SI units that are popular in specific fields could be used.

but I don't know how feasible it would be to add it to texmath.

Could you help to comment more on the feasibility that concerns you ?

@jgm
Copy link
Owner

jgm commented Jan 9, 2023

Here's an example I found of the use of \DeclareSIUnit:

\DeclareSIUnit[per-mode=symbol,per-symbol=p]{\Bps}{\byte\per\second}

It seems to me that you could achieve most of what this gives you in current pandoc using

\newcommand{\Bps}{\byte\per\second}

Have you tried that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants