65

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?

My LaTeX code:

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).

Context: floating point numbers and numerical programming

For context, when I originally asked this question I was writing a tutorial about the mathematics of stochastic simulation, with the goal of teaching people how to implement their own simulations in Python. This particular notation (<significand>e[<sign>]<exponent>) is relevant since it's how you write a floating point literal (ie a symbol that the Python interpreter understands as representing a particular floating point number). The <signficand>*<base>^<exponent> notation and its prettier variants are less appropriate, since Python (and many other languages) don't recognize it.

3
  • 20
    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. Commented Sep 27, 2015 at 23:09
  • @PaulGessler +1 but don't forget sometimes you need to represent text-mode output exactly as well.
    – Chris H
    Commented Sep 28, 2015 at 12:42
  • 1
    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
    Commented Sep 28, 2015 at 12:46

7 Answers 7

73

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.

10
  • 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
    Commented Sep 27, 2015 at 22:43
  • 11
    @Au101 It's a minus sign; the hyphen is definitely wrong.
    – egreg
    Commented Sep 27, 2015 at 22:44
  • Is it? Fair enough, I'd never have thought it :)
    – Au101
    Commented Sep 27, 2015 at 22:49
  • 7
    @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
    Commented Sep 27, 2015 at 23:00
  • 3
    @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
    Commented Sep 28, 2015 at 8:16
44

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

10
  • 9
    By adding \sisetup{output-exponent-marker=\ensuremath{\mathrm{e}}} to the preamble, one gets 1e-10 in the required way.
    – egreg
    Commented Sep 27, 2015 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
    Commented Sep 27, 2015 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
    Commented Sep 27, 2015 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}. Commented Nov 15, 2018 at 20:10
  • Man this looks so beautiful. I love LaTeX, even after being out of uni for years. :)
    – henry
    Commented Mar 15, 2020 at 11:35
12

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.

4

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

4
  • 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 :). Commented Feb 25, 2017 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
    Commented Feb 25, 2017 at 12:58
  • Unfortunately, too much space around the minus. It's not being subtracted from "6.626e". Commented Mar 15, 2020 at 0:35
  • @barbarabeeton: That's right. I wonder why I inserted a thin space… 'Tis fixed. Thank you for pointing it!
    – Bernard
    Commented Mar 15, 2020 at 11:34
3

I use $5.67\times 10^{-8}$, and I don't have to import anything.

enter image description here

1
  • 2
    The idea behind siunitx is that with the same input \num{1.501e-8} you can get a variety of outputs. If you have a few of such numeric specifications, it's not a big deal. But if the copy editors of the journal you're submitting a paper to tell you that “we want 1.501e-8”, you'll thank yourself of having used \num: just change an option in the preamble, et voilà, the copy editor's request has been accomplished.
    – egreg
    Commented May 2, 2023 at 15:29
2

I think the simplest answer (which I'm surprised hasn't been mentioned yet), is to just insert \! (the "negative thin space" command) in between the characters that you don't want to be spaced apart:

It's as easy as

$1.5e\!-\!10$

This will render as:

enter image description here

Instead of:

enter image description here

1
  • Easy and simple, if not quite as correct as some of the more sophisticated answers. Nice!
    – tel
    Commented Aug 13 at 2:23
1

If you don't mind process .Rnw files (.Rtex files in Overleaf) with R and knitr, instead of pure LaTeX files (.tex), to produce the correct scientific notation is as simple as declare that 1.5e-10 is a S expression (i.e., a notation for nested list, well, i.e., an object that R language can manage).

\documentclass{article}
\begin{document}
\Sexpr{1.5e-10}
\end{document}

mwe


N.B.: See How to build Knitr document from the command line if you do not want use Overleaf on-line or RStudio off-line (recommended) to compile this.

2
  • You missed the whole point of the question. I want to know specifically how to format "1.5e-10" nicely as-is, not how to auto-convert it to a different notation
    – tel
    Commented Mar 18, 2020 at 5:45
  • Sorry, I thinked that the whole point was not the kerning of the minus sign, but a scientific notation, that as pointed in the comments, is not this "calculator notation", but if you want one more solution in this sense, $1\mbox{e$-$}10$ or $1\mbox{e\ensuremath-}10$ will produce exactly the same output that solutions using \mathrm or siunitxpackage.
    – Fran
    Commented Mar 18, 2020 at 7:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .