I am using the DejaVu math font and noticed that the zero in f_0 is very far away from the f.

% !TeX program = lualatex





MWE output

My understanding is that the font author sets a value for (the equivalent of) italic correction that is applied in math mode when a symbol is followed by a subscript. Can I change this value for my document? f_{\!0} (or even f_{\!\!0}) looks better but I don't want to type that every time.

  • 2
    There's no italic correction applied.
    – egreg
    Mar 21, 2023 at 17:48
  • @egreg Ah, so the fact that the glyphs overlap a bit with Latin Modern just means that the f glyph always sticks out of its bounding box? So does this mean that there is no way to do this adjustment for the whole document?
    – schtandard
    Mar 21, 2023 at 18:35
  • @schtandard - Please see the answer I just posted.
    – Mico
    Mar 21, 2023 at 18:48

2 Answers 2


Since you're using LuaLaTeX, you could (a) define a Lua function that does the subscript kerning correction and (b) assign it to LuaTeX's process_input_buffer callback, so that it can act as a pre-processor on the input stream, before TeX does its usual processing.

enter image description here

% !TeX program = lualatex


function subscriptcorr ( s )
-- Two lines per letter (here: "f" "g" "x"), for both single-char
-- subscripts and subscripts contained in pairs of curly braces
  s = s:gsub ( "f%s-_%s-(%b{})" , "f_{\\mkern-6mu %1}" )
  s = s:gsub ( "f%s-_%s-(%w)"   , "f_{\\mkern-6mu %1}" )
  s = s:gsub ( "g%s-_%s-(%b{})" , "g_{\\mkern-2mu %1}" )
  s = s:gsub ( "g%s-_%s-(%w)"   , "g_{\\mkern-2mu %1}" )
  s = s:gsub ( "x%s-_%s-(%b{})" , "x_{\\mkern-2mu %1}" )  
  s = s:gsub ( "x%s-_%s-(%w)"   , "x_{\\mkern-2mu %1}" )  
  return s

%% 2 utility LaTeX macros
  \directlua{luatexbase.add_to_callback (
  "process_input_buffer" , subscriptcorr , "subscriptcorr" )}}
  \directlua{luatexbase.remove_from_callback (
  "process_input_buffer" , "subscriptcorr" )}}


$f_0 f_1 f_m \ x_ i x _ j x _k \ g _{mn} g _ {uv}$

\SubscriptCorrOn  % activate the Lua function
$f_0 f_1 f_m \ x_ i x _ j x _k \ g _{mn} g _ {uv}$

\SubscriptCorrOff % de-activate the Lua function
$f_0 f_1 f_m \ x_ i x _ j x _k \ g _{mn} g _ {uv}$

  • Hmm, this looks promising, but there is a problem. This preprocessing seems to be applied before expansion, so this leads to wrong output: \def\testf{a}\def\testa{f}\[a_0 \testf_0 f_0 \testa_0\]
    – schtandard
    Mar 22, 2023 at 11:00
  • Also, could we make this (or a fixed version) a loop to make it easy to add more characters? I tried something like for k, v in pairs({["f"] = -4, ["g"] = -2, ["x"] = -2}) do s = s:gsub(k .. "%s-_%s-(%w)", k .. "_{\\mkern" .. v .. "mu %1}") end but this seems to add -2mu kerning to all subscripts. (One of these days I really should look into the Lua part of LuaLaTeX..)
    – schtandard
    Mar 22, 2023 at 11:02
  • @schtandard - indeed, the Lua function acts on the input stream before any expansion takes place. How serious a problem is this in practice, though? Does your document really feature macros such as those you listed in your comments? My view is that if it does, you might as teach those macros how to perform the desired amount of kerning…
    – Mico
    Mar 22, 2023 at 14:04
  • @schtandard - Please post a new query to ask how to generalize the answer shown above to sets of characters.
    – Mico
    Mar 22, 2023 at 14:06
  • Well yes, I'd say it is a serious problem. There are loads of macros typesetting symbols in my equations, e.g. I may want to write \max_{x \in A} and not have to worry about a preprocessor mistaking that for an x with an index. I could of course teach every macro I use to be careful about that, but then it's probably safer and no more bothersome to just manually insert the kerning every time I write f_0 or the like, which is what I wanted to avoid.
    – schtandard
    Mar 28, 2023 at 10:45

This is not an answer, but too long for a comment. The problem you see is the following (as has been told, but with the boxes shown):


The f in the Dejavu Math font has a rather wide side bearing. The zero, also having some side bearing. Together it adds up and does not look optimal, indeed. Let us dig a bit deeper into related issues.

Let us compare that with TeXGyre Bonum that goes to the other extreme:


The Bonum f has some italic correction, otherwise superscripts would not be placed well (blue number indicate an italic correction):


The Bonum f has another problem, though: It is sticking out at the left end from its bounding box, and that can make it clash with for example a parenthesis:


Let me describe how this is handled in ConTeXt. Maybe some initiated LaTeX person can implement something similar or at least get some inspiration.

Let us start with Bonum (this applies to all fonts). Instead of having the f sticking out of its box, we

  • add the width to the left so that it does not stick out, and
  • add the italic correction to the width and introduce an equally large negative right bottom kern.

This fixes the example with the parenthesis:


And the example with the sub- and superscripts also come out right (red number indicate bottom right corner kern):




Since the developers of Dejavu Math did not add an italic correction to the italic f, we cannot rely on the same solution (but we also do not have the problems with (f) or f^0). We can still, and that is done, add a negative corner kern at the bottom right. This is in ConTeXt done in a goodie file (a lua file with settings/tweaks), and if one looks at the one for Dejavu, one will find a tweak:

    tweak = "kerns",
    list  = {
        [0x1D453] = { bottomright = -.2 },

The amount -.2 was by trial and error, and the outcome is


Let me just comment, since there might be observant readers: In the tweaked version, the zero is also sitting a bit higher. This is due to some change in the fontparameter SubscriptShiftDown, from 277 in the font to 177 (by trial and error). If one has lower case letters as subscripts, we thought they were too low:


With the changed parameter, we get


A better comparison with some "normal" size:

Without change:


With the fixes:


This was in both cases entered as

Let $f_0(x) = \sin x$ and define 

so nothing has changed for the user. I hope this was not completely useless for you, even though it did not really answer your question.

You must log in to answer this question.

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