7

I've been reading almost two hours through various posts that seem to have the same problem but none of the solutions worked for me.
I want to define new units (in my case it's \thermal and \electrical).
Is it possible that scrartcl has something to do with it?
Or does a package interfere with it?
Here is my preamble:

\documentclass{scrartcl}  
\usepackage[utf8]{inputenc}  

\usepackage{amsmath}  
\usepackage{amssymb}  
\usepackage[german]{babel}  
\usepackage{graphicx}  
\usepackage{floatrow}  
\usepackage{subfigure}  
%\pagestyle{empty}  
\linespread{1.5}  
\usepackage[margin=3.5cm]{geometry}  
\usepackage{color}  

\usepackage{siunitx}  
    \sisetup{inter-unit-product =$\cdot$}  

\usepackage{cancel}  
\usepackage{float}  
\usepackage{enumitem}  
\usepackage{caption}  
\usepackage{booktabs}  
\usepackage{cleveref}  
\usepackage{colortbl}  
\usepackage{csquotes}  
\usepackage{helvet}  
\usepackage{mathpazo}  
\usepackage{listings}  
\usepackage{pgfplots}  
\usepackage{xcolor}  
\usepackage{hyperref}  

\usepackage{multirow}  

\renewcommand{\labelitemii}{$\circ$}  
\renewcommand{\labelitemiii}{$\diamond$}  
\renewcommand{\labelitemiv}{$\ast$}  

\allowdisplaybreaks  

\numberwithin{equation}{subsection} %Gleichungen bekommen die     SubKapitelnummer  

\DeclareSIUnit{\thermal}{t}  
\DeclareSIUnit{\electrical}{e}  

I get the following error:

! Missing } inserted.  
<inserted text>  
                }  
l.72 ...-1000 betrug \SI{3200}{\mega\watt\thermal}  

?  

I already tried the following:
\DeclareSIUnit{\thermal}{t}
\DeclareSIUnit\thermal{t}

and so on; spaces, no spaces, braces,... \newunit\thermal{t} isn't even recognized.
If you need additional information I'll post it. Thanks for reading this.

EDIT: Full minimal example

\documentclass{scrartcl}
\usepackage[utf8]{inputenc}  
\usepackage{siunitx}  
    \sisetup{inter-unit-product =$\cdot$}
\usepackage{amsmath}  
\usepackage{booktabs}  
\usepackage{cancel}  
\usepackage{caption}  
\usepackage{cleveref}  
\usepackage{colortbl}  
\usepackage{csquotes}  
\usepackage{helvet}  
\usepackage{mathpazo}  
\usepackage{multirow}  
\usepackage{listings}  
\usepackage{pgfplots}  
\usepackage{xcolor}  

\DeclareSIUnit{\thermal}{t}  
\DeclareSIUnit{\electrical}{e}  
\begin{document}  
\SI{3200}{\mega\watt} \\  
\SI{3200}{\mega\watt\thermal}  
\end{document}  

Error message:

! Missing } inserted.  
<inserted text>   
                }  
l.23 \SI{3200}{\mega\watt\thermal}  

?   

Update: I get an error if I include
\sisetup{inter-unit-product =$\cdot$}
I also deleted it from my original preamble and it works now.

Thank you all for helping, here is the line that I'm using now (for those who might encounter the same problem as me):
\sisetup{inter-unit-product=\ensuremath{{}\cdot{}}}

Cancara
  • 93
  • 1
  • 7
  • Do you mind making a full minimal example so we have something that we can copy and test immediately – daleif Feb 09 '16 at 21:02
  • @Cancara: Your updated MWE doesn't produce an error, but has the space. Has your problem changed now? – Werner Feb 09 '16 at 21:20
  • @Werner Thanks for your comment. Sorry, didn't make it clear in the post: The error does not occur at the MWE but at my original preamble. Now, I don't know what it is in my preamble that causes the mentioned error. – Cancara Feb 09 '16 at 21:25
  • The thin space between MW and t when using \mega\watt\thermal is placed there by design, since it is a multiplication of units. – sodd Feb 09 '16 at 21:29
  • That is why it is called a minimal example, it should of course show the problem. Creating the mwe is also a valuable debugging tool, where one often ends up finding the error. – daleif Feb 09 '16 at 21:29
  • To solve the problem, replace \sisetup{inter-unit-product=$\cdot$} with \sisetup{inter-unit-product=\ensuremath{{}\cdot{}}}. See section 5.12 of the siunitx manual. – sodd Feb 09 '16 at 21:33
  • @daleif Thanks, I'm new to this, sorry for my mistake! Also, I couldn't know that it'll work if I don't use the other packages and stuff... Anyway, I'll try to produce the error. – Cancara Feb 09 '16 at 21:34
  • @hooy thanks for your suggestion! I'll try that :-) – Cancara Feb 09 '16 at 21:35
  • I believe the reason why \sisetup{inter-unit-product=$\cdot$} does not work, is that the units are typeset in math mode, leading to the first $ in $\cdot$ to leave math mode, where \cdot is not defined, leading to the error. – sodd Feb 09 '16 at 21:44
  • @Cancara the basic idea in debugging this sort if stuff, is to save the file under a new name then start outcomment stuff and recompiling. If the error remains, then chances are that the outcommented stuff were not important – daleif Feb 09 '16 at 21:46
  • @hooy it definitely makes sense, the strange thing is that I've seen this as a solution to another question (how to minimize the space between \cdot and units) where the commenter said that it worked for her/him. I'll try to find the link.

    Found the link

    – Cancara Feb 09 '16 at 21:48
  • @daleif Thanks, next time I'll try to find the error that way! – Cancara Feb 09 '16 at 21:51

1 Answers1

9

siunitx prints the units inside \ensuremath (like the other components). This allows one to typeset the output inside math or text mode where math mode would be automatically enabled if necessary. However, forcing math mode inside \ensuremath causes a problem, as is replicated by this simple minimal example:

\documentclass{article}
\begin{document}
$x \cdot y$

\ensuremath{x \cdot y}

%\ensuremath{x $\cdot$ y}% <---- this is a problem
\end{document}

With this in mind, define your SI unit without switching to math mode:

\sisetup{inter-unit-product=\cdot}

If you wish to reduce the space between the operands of the product, then use

\sisetup{inter-unit-product=\mathord{\cdot}}

Here's a minimal example showing the different output:

enter image description here

\documentclass{article}
\usepackage{siunitx}

\DeclareSIUnit{\thermal}{t}

\begin{document}

\sisetup{inter-unit-product=\cdot}

\SI{3200}{\mega\watt\thermal}

\sisetup{inter-unit-product=\mathord{\cdot}}

\SI{3200}{\mega\watt\thermal}

\end{document}

As reference for the spacing around \cdot and the application of \mathord, see How to change default for spacing around binary relations?

Werner
  • 603,163