This question already has an answer here:

I made some macros shown below, which outputs ordinary/partial derivative. I was checking whether they work as I expected, and found that \dif{y}{x} expands to \tfrac{\difd y}{\difd x} in align environment.
I want to use \tfrac only in sentences, not in any display math modes. How should I change the definition in order to expands \dif{y}{x} to \dfrac{\difd y}{\difd x} in align environment, gather environment and so on?

I have another question. I think higher derivatives written with my command (especially partial ones) make a little much space before f.
In terms of mathematical typography, which is proper: \frac{〈operator〉^{#1}#2}{〈operator〉#3^{#1}} or \frac{〈operator〉^{#1}\!#2}{〈operator〉#3^{#1}}?

example of higher derivatives

EDIT (June 13, 2015 at 23:28 JST):
The first question has been settled.

EDIT (June 15, 2015 at 14:21 JST):
As David Carlisle points out, my question was a duplicate of commath and \ifinner and commath package should not be used. Then, I have another question. In the linked page, there is a macro named \spx, the definition of which is in the below. Since we can see {^{#1}} in the definition, it seems to be an improved ^. What is the difference between this \spx and \^ and which should I use, "\(p)dif@nth and \@(p)dif" or "\spx without \@ifnextchar"?

My macros

% ----- differential operator -----
\makedifdit % default setting
% ----- ordinary derivative -----
% ----- partial derivative -----

Definition of \spx and its usage


marked as duplicate by egreg conditionals Jun 15 '15 at 6:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • just use \frac !! the default is to switch styles, \tfrac is to force text style and \dfrac is to force display style. Not test is needed. – David Carlisle Jun 13 '15 at 13:50
  • \ifinner is unrelated to the display/text style distinction. Are these macros based on the ones from commath which have similar tests? – David Carlisle Jun 13 '15 at 13:54
  • @DavidCarlisle Yes, I copied from commath.sty and arranged it. I suppose \frac in display math mode, in some cases, could be text style (though I cannot take an example immediately). I want to avoid that. – Merzong Jun 13 '15 at 14:03
  • I would not copy any of the macros in there, it is telling that I recognised the style just from the error you are asking about in your question. – David Carlisle Jun 13 '15 at 14:05
  • there is no case where \ifinner does anything useful here. – David Carlisle Jun 13 '15 at 14:10

The primitive \over as used by \frac automatically switches styles. The \tfrac and \dfrac macros are for special cases to force text or display style. \ifinner does not test for text/display distinction so the solution is simple, replace all




For your second question, I wouldn't use the negative spacing, certainly your image shows \! is too much, you can almost get away with it with f but other characters won't fit under the superscript so well.

  • Sorry, I missed your answer for the second quesiton. I tried \(p)dif[2]{y}{x} and realized the problem is a matter of the glyph of "f" itself rather than that of spacing. – Merzong Jun 13 '15 at 16:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.