Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

If I use the siunitx package to generate an imaginary number e.g. \SI{120i}{\per\centi\meter} then it places a 0 before the 120 (probably some artifact of expecting complex notation with a real number included).

This seems like a bug. Also it puts the number in parenthesis which would make sense if it was a complex number with a real and an imaginary component, but not if it's just an imaginary component on it's own.

I have considered turning of parsing, but that can create other formatting problems e.g. I like my "i" to be italic", which can be set up with the options, but not if parsing is turned off.

share|improve this question
2  
Yup, this does happen and is of course wrong. I'll have to check the detail, but I think that the parenthesis are a side-effect of the initial bug. –  Joseph Wright May 23 '11 at 12:49
    
To clarify, Joseph is the author of siunitx and, if past siunitx questions are any indication, there'll be a new version on CTAN in the next couple of days that will solve your problem. –  Seamus May 23 '11 at 12:56
    
IMHO bug reports are better reported by email to the package author(s). Technically this post is "not a real question". –  Martin Scharrer May 23 '11 at 13:03
5  
Problem is (hopefully) solved. Version v2.2e is on its way to CTAN. –  Joseph Wright May 23 '11 at 13:10
2  
@Martin: There is always some grey in this. A lot of people like to check that they are seeing a real bug, rather than misunderstanding something. The current case is pretty clear-cut, but that is not always true for bug reports. –  Joseph Wright May 23 '11 at 13:13

1 Answer 1

up vote 4 down vote accepted

For those who cannot wait for the update to hit CTAN, the following should work

\documentclass{article}
\usepackage{siunitx}
\ExplSyntaxOn
\cs_set_protected:Npn \siunitx_number_in_complex:N #1 {
  \bool_set_false:N \l_siunitx_number_in_first_bool
  \bool_if:NTF \l_siunitx_number_in_complex_root_bool
    {
      \siunitx_number_in_parse_error:nn
        { duplicate-complex-root-token } { \token_to_str:N #1 }
    }
    {
      \cs_set_eq:NN \siunitx_number_in_check:n
        \siunitx_number_in_check_full:n
      \bool_set_true:N \l_siunitx_number_in_complex_root_bool
      \prop_put:Nnn \l_siunitx_number_in_prop { complex-root } {#1}
      \tl_if_empty:NF \l_siunitx_number_parsed_tl
        {
          \cs_set_eq:NN \siunitx_number_in_parse_loop:N
            \siunitx_number_in_parse_complex:N
        }
      \bool_if:NT \l_siunitx_number_in_decimal_bool
        {
          \bool_if:NF \l_siunitx_number_in_complex_bool
            {
              \prop_if_in:NnT \l_siunitx_number_in_prop
                { mantissa-uncertainty }
                {
                  \siunitx_number_in_complex_aux:nn
                    { mantissa-decimal } { complex-decimal }
                  \siunitx_number_in_complex_aux:nn
                    { mantissa-uncertainty } { complex-uncertainty }
                }
              \siunitx_number_in_complex_aux:nn { mantissa-integer }
                { complex-integer }
              \siunitx_number_in_complex_aux:nn
                { mantissa-decimal-marker } { complex-decimal-marker }
              \prop_del:Nn \l_siunitx_number_in_prop { mantissa }
              \prop_put:Nnn \l_siunitx_number_in_prop { complex }
                { true }
            }
        }
      \prop_if_in:NnF \l_siunitx_number_in_prop { mantissa }
        {
          \prop_if_in:NnT \l_siunitx_number_in_prop { mantissa-sign }
            {
              \siunitx_number_in_complex_aux:nn { mantissa-sign }
                { complex-sign }
            }
        }
      \bool_set_true:N \l_siunitx_number_in_complex_bool
      \bool_set_false:N \l_siunitx_number_in_first_bool
      \siunitx_number_in_init_part:n { complex }
      \prop_if_in:NnT \l_siunitx_number_in_prop
        { complex-decimal-marker }
        { \bool_set_true:N \l_siunitx_number_in_decimal_bool }
      \prop_if_in:NnTF \l_siunitx_number_in_prop
        { complex-sign }
        { \bool_set_true:N \l_siunitx_number_in_sign_bool }
        { \prop_del:Nn \l_siunitx_number_in_prop { mantissa } }
    }
}
\ExplSyntaxOff
\begin{document}
\SI{120i}{\per\centi\metre}
\end{document}

(Sorry about the length - there is only one changed line here but the function is a bit long!)

share|improve this answer
    
Gosh, I have a headache now X-|. This seems to work, though I actually put the code in my style file (with "new" instead of "set" for the header line). I tried some other solutions before you posted this. They were based upon the new version of the code that you released on your Bitbucket site. Using the help of another user who had the software needed to extract the correct files. It appears that the changes you made, may not have been implemented in the siunitx.dtx file. Perhaps some kind of mistake was made? Maybe it's nothing, just thought I'd let you know. Thanks for the solution. –  aghsmith May 23 '11 at 20:01
    
@user1269: The above is exactly the same 'fixed' version of \siunitx_number_in_complex:N as you can see on BitBucket. So I'm not sure what you mean. (Also, the only software you need to extract the .sty file from siunitx.dtx is TeX itself. Doing tex siunitx.dtx will extract the style file.) –  Joseph Wright May 23 '11 at 20:09
    
Hope I didn't cause offense there... I shall explain. It seems that some software is needed to download the siunitx.dtx file ("hg" I believe). I tried it without and it crashed out my browser. Once I received the dtx file from a guy on irc. I could not install it. tex siunitx.dtx failed as did pdflatex siunitx.dtx. I examined the dtx file though and it appeared not to incorporate the changes specified in the "changesets" section of your site. It could be that the guy on irc got the wrong file. Not that those two problems would be related. –  aghsmith May 23 '11 at 20:22
    
Further to previous message. I have spoken to some one else who also downloaded the siunitx.dtx file from the repository. He got a working file that resolves this problem. perhaps it simply took a while to update. Any how it looks like there is no problem with the repository version of the file. Sorry if I caused any panic. –  aghsmith May 23 '11 at 20:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.