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.

I'm trying to use the siunitx package to format a number which is a vector (using \hat{x} to represent a vector in the x direction). Using \hat{x} leads to complaints about invalid tokens.

After seeing this question, I tried including

\sisetup{input-symbols=\hatx\haty}

\protected\def\hatx{\ensuremath{\hat{x}}}
\protected\def\haty{\ensuremath{\hat{y}}}

to my preamble. Then, I get siunitx error: "misplaced-sign-token" Misplaced sign token '+'.

For completeness, here's what I am trying now:

\documentclass{article}
\usepackage{siunitx}

\sisetup{input-symbols=\hatx\haty}

\protected\def\hatx{\ensuremath{\hat{x}}}
\protected\def\haty{\ensuremath{\hat{y}}}

\begin{document}

\begin{equation}
\vec{F} = \SI{-3.24e-20\hatx + 4.56e-18\haty}{\newton}
\end{equation}

\end{document}

Any ideas how I can get this kind of thing to work properly?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

One way to do this is to simply use:

\vec{F} = (\num{-3.24e-20}\hatx + \num{4.56e-18}\haty) \,\si{\newton}

enter image description here

Code:

\documentclass{article}
\usepackage{siunitx}

\protected\def\hatx{\ensuremath{\hat{x}}}
\protected\def\haty{\ensuremath{\hat{y}}}

\begin{document}
\SI{1234}{\newton}

\num{1234}\,\si{\newton}

\begin{equation}
    \vec{F} = (\num{-3.24e-20}\hatx + \num{4.56e-18}\haty) \,\si{\newton}
\end{equation}
\end{document}
share|improve this answer
    
I'd add the parentheses around the vector, or the expression is mathematically different from what it should mean. –  egreg Jan 12 '13 at 21:45
    
@egreg: Yep. I had it originally but was experimenting to see how it looked without the parenthesis and copied the wrong one here. Thanks for noticing. –  Peter Grill Jan 12 '13 at 21:51
    
Thanks, I hadn't thought of that. But this eliminates the spacing that is normally provided by siunitx, I think? –  Tyler Jan 12 '13 at 21:54
    
@Tyler: Can you elaborate on which spacing you are referring to. AFAIK, The \SI macro is just a short form for of using \num for the number and \si for the units, both of which are part of the siunitx pacakge. –  Peter Grill Jan 12 '13 at 21:57
1  
Take a look at this. The first is with \SI{1234}{\newton}. The second is with \num{1234}\si{\newton}. –  Tyler Jan 12 '13 at 22:06

May I suggest you try the mandi package? It is designed to handle this very thing. Furthermore, it is designed so that the user need never worry about a physical quantity's units because they are all baked into the package. For example, you can say \force{5} and get

force magnitude

You can also say \force{\mivector{2,4,-5}} and get the expected result

force vector

although it won't be formatted as in your example above. mandi was begun before siunitx came into existence and thus relies on the SIunits package for defining unit names, but in the next major release mandi will be independent of both SIunits and siunitx while, hopefully, not preventing use of the latter.

Disclaimer: I am the author of mandi.

share|improve this answer
    
Thanks, I was not aware of this package, but reading through the documentation, it looks very interesting. For now, I would prefer to keep using the vector notation from above, but your package does allow for a more readable source file. –  Tyler Jan 15 '13 at 2:16

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.