1

I've defined the command:

\newcommand{\dif}[1][]{\mathrm{d} {#1}\,}

since I use the notation:

\int \dif{x} f(x)

so that there's a space after every differential. However, it doesn't work as intended, since the space "\," is after the argument in the output, i.e. it works as if:

\newcommand{\dif}[1][]{\mathrm{d} \,{#1}}

Why is that? Is there any way to fix it? Thanks for any help.

  • 3
    Welcome to TeX.SX! Are you really using the dreaded notation with the differential before the function? Oh, no! ;-) Anyway, just remove the [] in the definition: you don't want an optional argument, but a mandatory one. – egreg May 18 at 11:43
  • It worked perfectly! Thank you, so much! Unfortunately, the course I'm taking uses this notation so I've been using it too so as not to cause any confusions with my notes. – Roberto Gargiulo May 18 at 11:57
1

With

\newcommand{\dif}[1][]{\mathrm{d} {#1}\,}

LaTeX expects a call such as

\dif[x]

rather than \dif{x}, because of the second optional argument to \newcommand. However, you want a mandatory argument, so you should do

\newcommand{\dif}[1]{\mathrm{d}{#1}\,}

I suggest to define an auxiliary command, so you can define other commands in terms of it and get a uniform appearance.

\documentclass{article}
\usepackage{amsmath}

\newcommand{\differentiald}{\mathrm{d}} % or just d
\newcommand{\dif}[1]{\differentiald #1\,}
\newcommand{\tder}[2]{\frac{\differentiald #1}{\differentiald #2}}

\begin{document}

\[
\int\dif{x} f(x) \qquad \int \dif{x}\dif{y} g(x,y) \qquad \tder{f}{x}
\]

\end{document}

By changing the definition of \differentiald to \newcommand{\differentiald}{d}, you'd change all of your integrals and total derivatives to have an italic “d”.

enter image description here

  • Thank you for your answer! Your solution is even more complete than what I was initially looking for, since I can now use it even for differentials of functions by having auxiliary commands. – Roberto Gargiulo May 18 at 18:19

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.