21

I've noticed that e-style (for example, 1.5e-10) scientific notation does not look especially nice in Latex math mode:

enter image description here

(code used to generate the above image: $1.5e-10$)

In particular, the width and kerning of the negative sign is totally off. Is there any way to specifically fix the issues with the negative sign?

edit:

Here's the complete code, including packages, for the above image:

\documentclass[11pt,notitlepage]{article}
\usepackage{amsfonts, amsmath, amsthm, amssymb}
\begin{document}
$1.5e-10$
\end{document}

I've also run into the exact same kerning issues with MathJax (via the markdown editor in IPython Notebook. Notebook sets MathJax up automatically, so no idea what packages they use).

  • 13
    You can, of course, typeset however you like, but I have to add this note: This is not scientific notation, but "calculator-ese", as one of my former professors put it. In my mind, its only place in typeset work is in typesetting computer/calculator input codes where 1.5e-10 is the way to present this number to the computer/calculator. In which case, it would appear in a monospaced font (not math mode), where the supposed kerning problems do not appear. – Paul Gessler Sep 27 '15 at 23:09
  • @PaulGessler +1 but don't forget sometimes you need to represent text-mode output exactly as well. – Chris H Sep 28 '15 at 12:42
  • Treating it as the input/output of a computer/calculator I'd set it in a monospaced font rather than as maths (in the way many software books do). If I was doing this a lot, and making some assumptions about what else I'd be writing in the same document, I'd probably use the listings package, though it's overkill just for a single example. – Chris H Sep 28 '15 at 12:46
32

It's not ugly, but exactly what's expected. If you type

$2x-10$

then you expect that there is some space around the minus sign, because it denotes an operation. When you type $1e-10$, TeX interprets it in exactly the same way, because it can't read your mind: the two expressions are formally the same, only two symbols are different.

If you want that an expression that's normally interpreted as a polynomial should be treated in a different way, then you have to properly mark it.

One solution might be

$1\mathrm{e}{-10}$

because in this case the braces around -10 tell TeX to enter a subformula and so the minus sign is initial, so not interpreted as a binary operation, but as a unary operator.

You could make a definition, such as

\newcommand{\expnumber}[2]{{#1}\mathrm{e}{#2}}

and input the number as

$\expnumber{1}{-10}$

but there's a much better alternative, the package siunitx.

\documentclass{article}

\usepackage{siunitx}
\sisetup{output-exponent-marker=\ensuremath{\mathrm{e}}}

\begin{document}

\num{1e-10}

\end{document}

This package offers many more features than just printing numbers in the desired format; consult its documentation to find them.

enter image description here


Note that siunitx is not understood by MathJax, so with it you must stick to the “hand made” solution. You can still say, in it,

$\def\num#1{\numx#1}\def\numx#1e#2{{#1}\mathrm{e}{#2}}$ 

and a formula such as $\num{1e-10}$ will be printed in the way you want.

  • This is a really good answer, but it seems to me that you're still using the minus sign for e-10 and I think it really ought to be an intra-word dash, the minus sign is too long. To be honest, I think I probably wouldn't even use math mode, text mode seems more appropriate, especially as the notation is surely for situations in which proper mathematical typesetting cannot be achieved – Au101 Sep 27 '15 at 22:43
  • 6
    @Au101 It's a minus sign; the hyphen is definitely wrong. – egreg Sep 27 '15 at 22:44
  • Is it? Fair enough, I'd never have thought it :) – Au101 Sep 27 '15 at 22:49
  • 5
    @tel I believe you've been too much influenced by the bad typesetting obtained with word processors by uncaring authors: a hyphen can never be interpreted as a minus sign. When I see “1e-10” (with a hyphen) I get, at the least, goosebumps. – egreg Sep 27 '15 at 23:00
  • 1
    @Mark Never heard about any difference between the subtraction and negative signs. Well, I know somebody distinguishes between them, but just for didactical reasons I don't agree with. – egreg Sep 28 '15 at 8:16
19

Take a look at the siunitx package. This is helpful for typesetting units and unitless numbers (among many other things). This works in text mode as well as math mode.

\documentclass{article}
\usepackage{siunitx}
\begin{document}
Number only: \num{1e-10}

Number with units: \SI{1e-10}{\meter\per\second}
\end{document}

enter image description here

  • 2
    By adding \sisetup{output-exponent-marker=\ensuremath{\mathrm{e}}} to the preamble, one gets 1e-10 in the required way. – egreg Sep 27 '15 at 22:19
  • @erik that looks very nice, but what I really want to know is if there's a way to format the e-style notation nicely. Knowing how to do the alternative 1x10^-10 style doesn't really help me. Any ideas? – tel Sep 27 '15 at 22:29
  • @tel I see. I didn't realize you specifically wanted to keep the 'e' notation. egreg's comment (and answer) offer an alternative, but the typesetting may not be what you want. – erik Sep 27 '15 at 22:37
  • 2 x 10^3 is nice, but 1 x 10^3 is verbose compared to just 10^3. To get that, use the nonintuitive invocation \num{e3}. – Camille Goudeseune Nov 15 '18 at 20:10
2

A solution with xparse:

\documentclass{article}

\usepackage{xparse}

\NewDocumentCommand{\scnum}{ >{\SplitArgument{1}{e}}m }
 {\scnumaux#1}
\NewDocumentCommand{\scnumaux}{ m m }
 {#1\,\mathrm e\,{#2}}

\begin{document} 

$\hbar\approx\scnum{6.626e-34} $

\end{document} 

enter image description here

  • I approved the edit since according to en.wikipedia.org/wiki/Planck_constant the h-bar (h/2pi) is 1.054571800(13)×10−34 J⋅s. But that is not importing regarding the LaTeX problem :). – Dr. Manuel Kuehner Feb 25 '17 at 12:10
  • 2
    @DrManuel Kuehner: As I'm only a poor mathematician ;-), it appears I confused the Planck constant (h) and the Planck-Dirac constant (). I've fixed it. – Bernard Feb 25 '17 at 12:58
2

Here's a really simple solution, not using any extra packages and looks just fine, in my opinion:

$9.54\text{e-}7$

That is, you're writing the "e-" part in normal text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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