# Representation of complex number with exponents with siunitx (workaround)?

It looks like siunitx (by @Joseph Wright) has a limitation regarding complex numbers with exponents:

\documentclass[]{article}
\usepackage[]{siunitx}
\begin{document}
\num{1 + 2 i}\\ %ok, complex number
\num{2e6}\\ %ok, number with exponent
\num{1 + 2e6 i}\\ %not ok, ! siunitx error: "invalid-token-in-exponent"
\end{document}


Is there a workaround for this?

The only way I found is

\num[parse-numbers=false]{1 + (\num[parse-numbers=true]{2e6}) i + 1}


which defeats the purpose.

(I am using siunitx version 2.5c.)

Note that siunitx can handle exponents in complex number, but in the case that the exponent is the same for both parts, for example \num{1+2i e10}, which is a different case.

-
I would have written that number as \num{1 + 2ie6} but that gives, surprisingly to me, (1 + 2i) × 10⁶. –  Qrrbrbirlbel Nov 21 '12 at 4:41
@Qrrbrbirlbel, yes, and even \num{1 + i2e6} gives (1+2i)×10^6, that is fine, that is why I moved the i to the end, in the hope that it won't be ambiguous (for the siunitx parser) –  alfC Nov 21 '12 at 4:43
This is a pretty-much deliberate limitation. Parsing complex numbers is hard enough, and it's there to support places in science where you do get for example complex frequencies. I'd need to see an example where a number with real and complex parts with an exponent only for one part comes up in the 'real world' of the scientific literature before addressing this. –  Joseph Wright Nov 21 '12 at 6:46
@JosephWright, good that you mention it. It is true, this is not a "literature" situation, however I am just processing output and displaying with a LaTeX output for reporting purposes. Your package came as a blessing because I don't have to worry in converting the C output (e.g. 1.2344234234e-23 to something readable $1.23\times 10^{-23}$), I just let num process the string and even truncate (e.g. uniformly across the document) that for me. For complex numbers I have to do a little more work to separate the real and imag part, and that is where I hit the problem. –  alfC Nov 21 '12 at 8:20
@alfC I'm more than happy to consider a feature request. The tricky part is dealing with things like 1e2 + 3e4i: logically allowable if you permit separate exponents, but much harder for me to process :-) Also, you have to then worry about the interpretation of 1+2ie3: is the exponent only for the second part or the whole number? –  Joseph Wright Nov 21 '12 at 8:23

The number parser in siunitx is intended to support the primary purpose of the package: typesetting physical quantities (numbers with units). These rarely have a complex part, and when they do (such as in some parts of electronics) the magnitude of the real and complex parts is normally similar. Thus the package understands

1 + 2i e3


as

$(1 + 2\mathrm{i}) \times 10^{3}$


as this is by far the most common requirement.

In principal the parser can be extended to cope with a wider range of inputs, but this also requires changes in how the output is generated. There is then a balance both in terms of complexity of code and of performance, as the 'common case' does not need any of this.

Feature requests are always welcome: please feel free to log one in the tracker, along with links to whatever input syntax(es) would be useful!

-
Thank you very much, I opened a feature request, regarding more general numeric types from computer languages: bitbucket.org/josephwright/siunitx/issue/208/… (sorry it went Anonymous) –  alfC Nov 21 '12 at 9:34
I'll accept this answer as an statement of the current limitation and scope of the package. –  alfC Nov 28 '12 at 21:58
@alfC Fine with me! There is an open feature request for a choice of number parsers: probably on the cards for v3 of the package, some time next year. –  Joseph Wright Nov 28 '12 at 21:59