139

I would like to make a partial differential equation by using the following notation:

dQ/dt

(without / but with a real numerator and denomenator). Earlier today I got help from this page on how to u_t, but now I also have to write it like dQ/dt. I understand how it can be done by using dollarsigns and fractions, but is it possible to do it using

\begin{equation}
....
\end{equation}

so that it can be on separate lines and using math-style?

1
  • 1
    See also cool: "The pack­age (COn­tent Ori­ented LaTeX) gives LaTeX the power to re­tain mathemat­i­cal mean­ing of its ex­pres­sions in ad­di­tion to the typsetting in­struc­tions; es­sen­tially sep­a­rat­ing style from the con­tent of the math." Jan 29, 2015 at 14:20

6 Answers 6

211

You said partial differential equation:

\documentclass{article}
\begin{document}
\begin{equation}
\frac{\partial Q}{\partial t} = \frac{\partial s}{\partial t}
\end{equation}
\end{document}

enter image description here

now using physics package, extra goodies (bonus):

\documentclass{article}
\usepackage{physics}
\begin{document}
\[
\dv{Q}{t} = \dv{s}{t}  \quad
\dv[n]{Q}{t} = \dv[n]{s}{t}  \quad
\pdv{Q}{t} = \pdv{s}{t}  \quad
\pdv[n]{Q}{t} = \pdv[n]{s}{t}  \quad
\pdv{Q}{x}{t} = \pdv{s}{x}{t}  \quad
\]
\[
\fdv{F}{g}
\]
\end{document}

enter image description here

6
  • 4
    Thank you very much for both answers! Both of them worked perfect.
    – David
    Jan 29, 2015 at 13:24
  • I also tried the second option you gave, but when I had written \usepackage{physics} at the top of the document, I got this as an output: ! LaTeX Error: File `physics.sty' not found. Type X to quit or <RETURN> to proceed, or enter new name. (Default extension: sty) Enter file name:
    – David
    Jan 29, 2015 at 13:43
  • What should I enter as file name?
    – David
    Jan 29, 2015 at 13:43
  • 2
    @David It means you don't have physics package installed. Please install it.
    – user11232
    Jan 29, 2015 at 13:57
  • Note that we can italicize the d's using \usepackage[italicdiff]{physics}. Apr 9, 2017 at 5:23
18

Another possibility to write classic derivates or partial derivates I suggest (IMHO), actually, to use derivative package. For my humble opinion it is very good and last release is **2024/02/08, v1.4 **. Here there are some examples take, some, from the guide:

enter image description here

\documentclass[12pt]{article}
\usepackage{derivative}
\begin{document}
\[
\pdv{f}{x}, \quad \odv{Q}{t}=\odv{s}{t}, \quad \pdv{f}{x,y}, \quad 
\derivset{\odv}[switch-*=false] \odv{y}{x}, \quad \odv[n]{y}{x}, \quad
\derivset{\odv}[misc-add-delims=fun] \odv*{\odv{y}{x}}{x}, \quad 
\derivset{\pdv}[sort-method={sign,symbol,abs}] \pdv[c+kn,-b+2a]{f}{x,y}
\]
\end{document}
4
  • 1
    Just fully agree IMHO with your HO: this package is very good. It is easy to use and has powerful options. +1 Jul 30, 2021 at 10:13
  • @loved.by.Jesus I am help that you have appreciated my answer. + 1 also for you and other.
    – Sebastiano
    Jul 30, 2021 at 10:28
  • What is the mnemonic for odv and pdv? I would guess "Ordinary Derivative..." and "Partial Derivative..." but what is the v standing for?
    – lucidbrot
    Mar 8, 2022 at 10:41
  • 1
    @lucidbrot I got the naming scheme from another package, I think it was physics, but at least in my package dv stands for "DeriVative" or for short "DeriV". The latter is also the prefix for the internal package commands.
    – Simon
    Jun 28, 2022 at 13:23
7

I now recommend using the cool package:

\documentclass{article}
\usepackage{cool}
\begin{document}
Text:
\[
    \pderiv{u}{t}=\pderiv[2]{u}{x}
\]
More text.
\end{document}

I used to recommend defining a command to make a short form:

\documentclass{article}
% Partial derivative
\newcommand*{\pd}[3][]{\ensuremath{\frac{\partial^{#1} #2}{\partial #3}}}
\begin{document}
Text:
\[
    \pd{u}{t}=\pd[2]{u}{x^2}
\]
More text.
\end{document}

what it looks like

3
  • 1
    There is rarely a good use of \ensuremath. While there's nothing really wrong with it, it removes semantic meaning without adding much of anything else. See When not to use \ensuremath for math macro? Jan 29, 2015 at 13:33
  • You do not have to make that square in denominator by hand... you can formulate it in this way: \newcommand{\pdv}[3][]{\frac{\partial^{#1}#2}{\partial {#3}^{#1}}} Feb 19, 2016 at 18:27
  • 1
    @JozefJanočko Note that \partial^{}u (the default in your solution) will give more spacing compared to \partial u.
    – sodd
    Feb 19, 2016 at 21:18
2

Try this

\frac{\partial^2 u}{\partial x^2}
1
  • 7
    This doesn't add anything more than isn't already covered in the other answer(s).
    – Werner
    Feb 1, 2019 at 19:51
2

All good answers. I would just like to mention that if your are somewhat new to LaTeX, you should get used to using \newcommand and \renewcommand. For example:

% __________ Differentials __________

% Single

  \newcommand{\diff}{d}           % If you want an upright `d', change it here
  \newcommand{\p}[1]{\partial#1}
  \newcommand{\q}[1]{\delta#1}    % Kronecker Delta/Variation Symbol

% Nth Differentials:

  \newcommand{\dN}[2]{\diff^{#1}{#2}}   % Numerator type
  \newcommand{\pN}[2]{\partial^{#1}{#2}}
  \newcommand{\qN}[2]{\delta^{#1}{#2}}

% Nth Powers of Differentials

  \newcommand{\dD}[2]{\diff{#2}^{#1}}   % Denominator type
  \newcommand{\pD}[2]{\p{#2}^{#1}}
  \newcommand{\qD}[2]{\delta{#2}^{#1}}
  \newcommand{\pd}[1]{\dfrac{\partial}{\partial{#1}}}
  \newcommand{\pdd}[2]{\dfrac{\partial{#1}}{\partial{#2}}}

% __________ Derivatives __________

% 1st derivative:

\newcommand{\dod}[2]{\dfrac{\diff{#1}}{\diff{#2}}}  % 'differential over differential'
\newcommand{\pop}[2]{\dfrac{\p#1}{\p#2}}            % 'partial over partial'
\newcommand{\lpop}[2]{\p#1/\p#2}            % A 'layed down' version
\newcommand{\qoq}[2]{\dfrac{\q#1}{\q#2}}

% Nth derivative:

\newcommand{\dodN}[3]{\dfrac{\dN{#1}{#2}}{\dD{#1}{#3}}}
\newcommand{\popN}[3]{\dfrac{\pN{#1}{#2}}{\pD{#1}{#3}}}
\newcommand{\lpopN}[3]{\pN{#1}{#2}/\pD{#1}{#3}}  % Layed version of \pop
\newcommand{\qoqN}[3]{\dfrac{\qN{#1}{#2}}{\qD{#1}{#3}}}

% Mixed

\newcommand{\dodMixed}[3]{\dfrac{\dN{2}{#1}}{\diff{#2}\diff{#3}}}
\newcommand{\popMixed}[3]{\dfrac{\pN{2}{#1}}{\p{#2}\p{#3}}}
\newcommand{\lpopMixed}[3]{\pN{2}{#1}/\p{#2}\p{#3}}
\newcommand{\qoqMixed}[3]{\dfrac{\qN{2}{#1}}{\q{#2}\q{#3}}}
1

Another option is to use hep-math package (2023/07/01). Here a little tex.code compilable.

enter image description here

\documentclass[12pt]{article}
\usepackage{hep-math}
\renewcommand{\diffsymbol}{\mathrm d} % optional upright d
\begin{document}

\[\dv[f]x,\quad, \dv*[f]x^n,\quad, \dv[f]x*^n,\quad, \dv*[f]x*^n\]
\[\dv xf,\quad, \dv*xf,\quad, \dv x*f,\quad, \dv*x*f\]
\[\pdv[f]h,\quad, \pdv[f]y[x],\quad, \pdv[f]x^5,\quad, \pdv[f]x^3[y^2]\]
\[\pdv[f]x^2[y]^3, \pdv[f]x[y]^3, \pdv x[y]f\]
\end{document}
1
  • 1
    +1 for bringing up a package I didn't know but I wouldn't recommend it...
    – campa
    Feb 9 at 14:17

You must log in to answer this question.

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