0

A user on Chemistry SE mentioned a very nice shortcut to use in implementing a command for partial derivatives (see comments section of question: https://chemistry.stackexchange.com/questions/126955/proving-a-thermodynamic-relation-between-partial-h-partial-t-p-and-part):

Suppose you want to create the following partial derivative:

\left(\frac{\partial U}{\partial p}\right)_{\!T}

using this command:

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

The standard use of the command would be:

\pd {U}{p}{T}

However, since each argument is only a single character, this is sufficient:

\pd UpT

If one needs to typeset numerous partial derivatives, this is a great time-saver.

Indeed, you can even use a hybrid approach, where braces are eschewed for single-character arguments, but used for multi-character arguments. For example, to implement this:

\left(\frac{\partial U}{\partial p}\right)_{\!T, n_i}

One would write this:

\pd Up{T, n_i}

This seems to leverage what is a standard shortcut in LaTeX for single-argument commands (e.g., we drop the braces when the argument of a superscript or subscript command has only one character). But, for this usage (multi-argument user-defined commands) are there cases in which this (seemingly non-standard) approach would create a problem?

theorist
  • 143
  • 5
    it is guaranteed to work with latex you see people using \frac12 for a half for example but it is poor style and eventually makes the source harder to read. It may also fail with various latex-to-xxx convertors which may not be expecting this, – David Carlisle Jan 25 '20 at 20:11
  • Thanks @DavidCarlisle Should I delete my question because it's a duplicate, or leave it so that people who have the same question as mine, but can't find the linked question, might be able to find mine? I did search TeX SE extensively (using various search phrases including "command" and "braces") before posting and was unable to find the linked question, so posting was in fact useful because it both gave me your answer, and a link to a similar question. – theorist Jan 25 '20 at 21:08
  • No the site likes duplicates, questions with lots of duplicates are easier to find via search, so don't delete. – David Carlisle Jan 25 '20 at 21:13
  • @DavidCarlisle, understood, thanks. And as far as the practice itself goes, it seems it would be fine if I'm only the only one that will be seeing the source code (in which case the style is purely personal preference), e.g., if I'm using the command to make class handouts, where I'll only being circulating pdfs. – theorist Jan 25 '20 at 21:19
  • believe me: reading code that you wrote 30 years previously where you omitted everything omittable makes you wish you'd put them in:-) – David Carlisle Jan 25 '20 at 21:38
  • @DavidCarlisle I typically document my code, as needed, to address such eventualities. This is of course personal preference, but if I can avoid a lot of tedium in typing by using a non-standard shortcut, at the cost of some extra documentation, it's worth it to me. This would make the most sense for long pieces where I'd use the non-standard shortcut extensively. – theorist Feb 04 '20 at 03:34
  • sure, although mine wasn't exactly a theoretical example. Sometime around 1993 Frank and I spent a couple of weeks removing every non mandatory brace from the sources of latex (look in latex.ltx) as removing {} saves you 4 bytes or so of token memory. It was necessary at the time but it doesn't make the latex sources particularly pleasant to read.... – David Carlisle Feb 04 '20 at 08:00

0 Answers0