4

My preamble contains the following definition

\newcommand*  {\pdiffat}[3] {\left(\frac{\partial{#1}}{\partial{#2}}\right)_{#3}}

which is meant to be used in math mode only. However, overleaf complains that \left must only be used in math mode and hence colors this line and all subsequent lines in pink/red.

Is there a (ideally simple) way to avoid this? I.e. such that the macro with the same functionality still works, but overleaf is happy?

  • 1
    I do not use overlead, but is wrapping the definition in \ensuremath{...} acceptable? – Steven B. Segletes Feb 11 at 14:21
  • 3
    Remove the spaces between the * and the command name, then overleaf will behave again. – Ulrike Fischer Feb 11 at 14:28
  • 3
    The only way is to ask Overleaf to avoid that silly behavior for macro definitions in the document preamble. – egreg Feb 11 at 14:41
  • 1
    Hi, Tom from Overleaf support speaking. The solution by @UlrikeFischer should work. Still, I'll raise this with our engineers to see whether we can teach this to the parser. – yo' Feb 11 at 15:26
  • 1
    @StevenB.Segletes If you make your suggestion into an answer, I'll accept that. – Walter Feb 11 at 15:58
6

Remove the spaces between the \newcommand* and the command name, they seem to confuse the overleaf parser. This here works fine for me:

 \newcommand*{\pdiffat}[3]{\left(\frac{\partial{#1}}{\partial{#2}}\right)_{#3}}
|improve this answer|||||
2

Despite the many reasons not to do it this way, and Alan's comment provides a link about not using \ensuremath, I nonetheless suggested placing an \ensuremath around the code, as in

\newcommand*{\pdiffat}[3]{\ensuremath{\left(\frac{\partial{#1}}{\partial{#2}}\right)_{#3}}}

In this manner, the command will function when invoked in either text or math modes.

I did not suggest this as a general approach to macro making, but only as a possible remedy for the particular overleaf problem the OP was experiencing. (I have no knowledge of overleaf, myself)

\documentclass{article}
\begin{document}
\newcommand*{\pdiffat}[3]{\ensuremath{\left(\frac{\partial{#1}}{\partial{#2}}\right)_{#3}}}

\pdiffat{a}{b}{c} vs. $\pdiffat{a}{b}{c}$
\end{document}
|improve this answer|||||
  • 1
    I find the statements about \ensuremath a bit over the top. For pretty much anything you can construct scenarios where this something does not give the optimal result. – Schrödinger's cat Feb 11 at 16:56

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.