So I notice that the spacing between \nabla and f in math mode when using mtpro2 is really wide (for me, at least). Here is the result of typing \nabla f with mtpro2.

gradient of f

I wonder if there is a way we can adjust the symbol \nabla based on the next non-space letter, say:

  1. If the next non-space letter is f, then execute \kern -0.2 em f,
  2. else, stay at usual.

I have been looking around, but could not find a satisfying solution. Any help is highly appreciated.

  • Can I ask a question please?
    – Sebastiano
    Sep 9, 2018 at 8:21

1 Answer 1


Here's a LuaLaTeX-based solution. It sets up a Lua function called nabla_f that does most of the work, and it assigns this function to the process_input_buffer callback, making it operate on all inputs before TeX starts is usual processing.

enter image description here

% !TEX TS-program = lualatex
\usepackage{times,mtpro2} % text and math fonts
function nabla_f ( s )
   return ( s:gsub ( "\\nabla%s*f" , "\\nabla\\mkern-4mu f" ) )
\directlua{luatexbase.add_to_callback("process_input_buffer", nabla_f , "nablaf" )}

$\nabla{}f$ $\nabla f$ $\nabla h$ $\nabla k$

Addendum: If you also want to change the amount of whitespace between \partial and f, while keeping the instruction to change the distance between \nabla and f, I suggest you replace

   return ( s:gsub ( "\\nabla%s*f" , "\\nabla\\mkern-4mu f" ) )


   s = s:gsub ( "\\nabla%s*f" ,  "\\nabla\\mkern-4mu f" ) 
   s = s:gsub ( "\\partial%s*f", "\\partial\\mkern-4mu f" )
   return s

Of course, you can (and should) change the new instance of -4mu to whatever the optimal adjustment amount may be.

  • 1
    so I guess this works for other things like \partial f by replacing nabla with partial? I am excited about this :)
    – weirdo
    Sep 8, 2018 at 23:51
  • 1
    @weirdo - Indeed, the code can be modified to allow further types of adjustments. I posted an addendum to show how this might be done for the case of \partial and f.
    – Mico
    Sep 9, 2018 at 4:52
  • 2
    works like a charm for me :)
    – weirdo
    Sep 9, 2018 at 16:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .