Formatting of \partial and \dd

If I type a space between "d" and "u" and compare it to Esc dd Esc u and "du" with no space it appears to my eye that Mathematica adds about a half a space.

Mathematica graphics

If you are willing to use strings (only for printing) you can group the Esc dd Esc and "y" together using StringExpression and they will display closer.

Below are the results of these expressions:

Style["\[DifferentialD]" ~~ "u", 16]/Style["\[DifferentialD]" ~~ "t", 16];
Style[\[DifferentialD]u, 16]/Style[\[DifferentialD]t, 16];

Mathematica graphics

If you look carefully you will see that using StringExpression (i.e., ~~) makes it appear slightly closer.

You can define functions to make your life easier

ddC[x_, size_: 14] := Style["\[DifferentialD]" ~~ ToString[x], size]
pdC[x_, size_: 14] := Style["\[PartialD]" ~~ ToString[x], size]

and then

ddC[u, 16]/ddC[t, 16]
pdC[u],pdC[t]

gives you image with

Mathematica graphics


If you want to alter the typography AND create functionality than I think you'll need the Notation Package. However, if you just want to alter the typography, you can do that using Boxes. I like to use the InputAutoReplacements option in the Inspector to create my shortcuts. It's less keystrokes to use them... so I'm more productive.

You can create whatever construct you want including font types, placeholders, nudging, using boxes. Below is an example of some code you can try. Open a new notebook and execute the code below.

SetOptions[$FrontEndSession,
 InputAutoReplacements -> {
   "dx" -> 
    Cell[BoxData[
      FormBox[StyleBox["\[DifferentialD]\[NegativeMediumSpace]x"], 
       TraditionalForm]], FormatType -> "TraditionalForm"]}] 

This has created a temporary shortcut which will continue to work until you close your current session in Mathematica. Create a text cell and then type dx and then press the space bar. You will get the following typeset notation with the correct spacing you are looking for.

dx

You can alter the spacing between the d and x using something other than \[NegativeMediumSpace]. You can find other spacings here. You can also change the font if you like something a little different or make it italic or bold or change other characteristics of the font. There's many ways to make it look different ... but your question was specifically about spacing so that's what I addressed.

You can add inputautoreplacements using the option inspector but it's a real pain to do. Executing the code is far more efficient. Also if you change $FrontEndSession to $FrontEnd in the code above, the shortcut created will become permanent so that when you close and reopen Mathematica it still works.

You can list your current inputautoreplacements by executing the following code in a notebook.

Options[EvaluationNotebook[], InputAutoReplacements]

Copy and paste this code into a separate notebook and save it so you have a backup.

Tags:

Formatting