[Tex/LaTex] esdiff package for easily writing derivatives cannot handle subscripts properly

errorsmath-modesubscripts

Here's a MnWE:

\documentclass[12pt,letterpaper]{article}

\usepackage{lmodern}
\usepackage[T1]{fontenc}

\usepackage{amsmath}
\usepackage{esdiff}

\begin{document}
    $\diffp{V}{c_i}$
\end{document}

The error being returned:

line 14: Missing { inserted. $\diffp{V}{c_i}

From the log:

! Missing { inserted.
<to be read again> 
                   }
l.14     $\diffp{V}{c_i}
                        $
A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.

The following causes the same error:

\documentclass[12pt,letterpaper]{article}

\usepackage{lmodern}
\usepackage[T1]{fontenc}

\usepackage{amsmath}
\usepackage{esdiff}

\begin{document}
    $\diffp{V}{c_{i}}$
\end{document}

How can I get esdiff to properly work with subscripts?

Best Answer

Use an extra pair of braces for the argument with scripts:

    $\diffp{V}{{c_{i}}}$

A complete example:

\documentclass[12pt,letterpaper]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage{esdiff}

\begin{document}
    $\diffp{V}{{c_{i}}}$
\end{document}

enter image description here

The extra pair of braces forms a group thus c_{i} is seen as a "unit"; without it, TeX sees c as a first token, internally \partial c is built, and then ot takes _ as the next token to form \partial _, which triggers the error.