5

I am using pandoc to convert a .tex document into a .docx. The tex document uses the siunitx package.

As pandoc can not interpret the macros in the package, I have to write dummies for the macros I use, which will then be used by pandoc. As the docx is simply for review by my co-authors, this is not a problem and the final formatting will be done by LaTeX.

I have implemented some macros

\newcommand{\percent}{percent}
\newcommand{\per}{/}

\newcommand{\num}[1]{#1}
\newcommand{\numrange}[2]{#1 to #2}
\newcommand{\numlist}[1]{#1}

\newcommand{\si}[1]{#1}

but I am struggling with \SI, particularly the preunit part

\SI{number}[preunit]{unit}

as the second argument [preunit] is the optional argument. I have found that I can specify the first argument as optional argument as follow:

\newcommand{\SI}[3][test]{#1#2#3}

But how can I do this with the square brackets and as the second argument?


ADDITIONAL INFO

Pandoc version: pandoc 1.15.2.1

3
  • \NewDocumentCommand{\si}{mO{test}m} using the xparse package, but I am not sure this will work with pandoc
    – user31729
    Commented Dec 1, 2015 at 10:15
  • Shouldn't it read \SI{number}[preunit]{unit}?
    – user31729
    Commented Dec 1, 2015 at 10:16
  • Perhaps a Generic Preprocessor could help here. However, I always thought GPP would be better for the markdown-to-*TeX workflow....
    – jon
    Commented Dec 1, 2015 at 17:54

1 Answer 1

1

Would something like this work?

\documentclass{article}

\newcommand{\percent}{percent}
\newcommand{\per}{/}
\newcommand{\kilogram}{kg}
\newcommand{\coulomb}{C}
\newcommand{\mole}{mol}

\newcommand{\num}[1]{#1}
\newcommand{\numrange}[2]{#1 to #2}
\newcommand{\numlist}[1]{#1}

\newcommand\svnum{}
\newcommand\SI[2][]{\renewcommand\svnum{#2}\SIhelp}
\newcommand\SIhelp[2][]{\(#1\)\svnum\,#2}
\begin{document}
\SI{23}{m}

\SI{23}[\$]{}

\SI[per-mode=symbol]{1.99}[\$]{\per\kilogram} 

\SI[per-mode=fraction]{1.345}[1000\times]{\coulomb\per\mole}
\end{document}

enter image description here

11
  • Unfortunately, does not work with pandoc.
    – Rainer
    Commented Dec 1, 2015 at 11:42
  • @Rainer You realize I am showing it with and without siunitx. To make it work in your setting, you need to remove the siunitx portion. Better still, let me restate it without the siunitx present. Commented Dec 1, 2015 at 11:45
  • @Rainer How about with this clarification? Commented Dec 1, 2015 at 11:47
  • Sure - in the pandoc version I have only the Not using siunitx section with ``renewcommand``` replaced with newcommand.
    – Rainer
    Commented Dec 1, 2015 at 11:47
  • @Rainer I am not a pandoc user, so I can't really say anything more. But I thought doing it with no packages would suffice. There is nothing unique in my coding. Commented Dec 1, 2015 at 11:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .