7

I've been teaching myself a lot of calculus through online resources since I've been bored over summer break and will be taking AP Calculus I and AP Physics C next year. When dealing with integrals, all of my readings and formula charts put a space in between the integrand and the differential. For example, a sheet of practice problems from Clark University: Clark and the Physics C formula sheet from CollegeBoard: ap

When using LaTeX, how can I take the code $$\int ydx$$, which yields $$\int ydx$$ and edit it so that there is a space between the $y$ and $dx$?

(Sorry for the novice questions; I'm still new to this.)

  • 1
    There should be \[\int y\,dx\] – Przemysław Scherwentke Jun 13 '16 at 23:48
  • 1
    Define some handy macro for differentials, like \dd and write \int y \dd x. I prefer \d but since it's already defined, if you defined \d you would lose the original definition so you need to save it. The most common definition for those macros to get correct spacing is \mathop{}\!d. – Manuel Jun 14 '16 at 0:02
  • 2
    The physics package comes with macros for differentials. This will also take care about upright shape of the d. – samcarter_is_at_topanswers.xyz Jun 14 '16 at 0:15
11

It's a good habit to have a thin space in front of “dx”, which emphasizes the fact that the “d” is attached to the variable “x”, forming a single unit (which is, mathematically, what really happens).

So a savvy typist will input your formula as

\[
\int k\,dx = kx+C
\]

and, similarly,

\[
\iint\limits_{\mathbb{R}^2} e^{-x^2-y^2}\,dx\,dy
\]

Typing in the \, becomes automatic, when you think about the nature of the symbol. But

Yes, there's a caveat. Some people, not knowing what the “d” is about, think that it has the same mathematical nature as “sin” (which it hasn't, but here we're discussing opinions), so they want it to appear in upright font.1

In view of this it is convenient to add a macro for the “d” in the differential symbols; the simplest one is

\newcommand{\diff}{\mathop{}\!d}

so you type the formulas above as

\int k \diff x = kx+C

\iint\limits_{\mathbb{R}^2} e^{-x^2-y^2} \diff x \diff y

and, in case the journal editor, your supervisor or whoever asks you to turn the “d” into upright type, all you'll have to do is to change one line in your typescript

\newcommand{\diff}{\mathop{}\!\mathrm{d}}

Some packages offer similar functionality; I usually find they overdo. For instance the physics package defines \dd with three optional arguments, making for confusion rather than simplification. (The commath package, instead, makes such a mess that it is better ignoring it.)

In any case, resist the temptation to do

\renewcommand{\d}{<whatever>}

in order to have a handier macro name for the differential. Macros for accents should never be redefined to do something different. Accents appear (maybe masked out) in people's names and having the differential symbol popping out in the middle of a name in the bibliography is not the best thing to find out when you're very near a deadline.


1 Even worse, some people even go further and use Wolfram's convention that the “d” is double-struck: 𝕕 (they also like 𝕖 for Euler's number). Let's hope this ugliness won't spread.

| improve this answer | |
3

I use this, borrowed from an answer on this side, but I can't remember as an answer to which question:

\documentclass[12pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
 \usepackage{amsmath,amsfonts,amssymb}%

\AtBeginDocument{\renewcommand*{\d}{\mathop{\kern0pt\mathrm{d}}\!{}}}

\begin{document}

\[ \int_a^b f(t)\d t \]

\end{document} 

enter image description here

| improve this answer | |
  • 1
    I'm curious: why AtBeginDocument instead of just renewing the command in the preamble? – Ethan Bolker Jun 14 '16 at 1:47
  • Why not use e.g. \diff, instead of redefining an existing macro? – Torbjørn T. Jun 14 '16 at 6:19
  • 4
    Redefining \d is wrong. You'll regret doing it when one of your bibliography entries will not typeset. And you'll have to change all your document looking for \d. – egreg Jun 14 '16 at 7:54
  • While I agree with egreg that redefining \d is problematic you can at least restrict the redefinition to math mode. – campa Jun 14 '16 at 8:28
  • @Ethan Bolker: It's been a long time since I used it, and I don't remember exactly why. Probably because of an interaction with other packages I usually load. – Bernard Jun 14 '16 at 10:44

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.