12

I am currently working on something which requires me to have a single letter in math mode followed by a hyphen, e.g. $p$-center. For the most letters, it looks fine. However, if I use $p$ or $\rho$, the space in front of the hyphen is too small. I can fix it manually: $p\mkern1mu$-center, but it is annoying to do this everywhere.

math mode p with hyphen

Trying a little more things, I noticed that the problem is the hyphen. I changed the kerning using microtype: \SetExtraKerning[unit=space]{encoding=*}{-={135,0}} This works great, at least for hyphens. Unfortunately, it destroys all en-dashes. Whenever I write -- it is not replaced by an en-dash any more. I could replace each -- with \textendash which, again, would be annoying.

Is there a way to change the kerning of hyphens without destroying the en-dashes?

  • 3
    I would use \newcommand\pvar{$p\mkern1mu$} and then \pvar-center (the actual naming should perhaps reflect the meaning of the var). A general kerning (if it would work) will only lead to wrong spacing in other places. – Ulrike Fischer Mar 5 '17 at 10:58
7

The "p" and the rest are different fonts and the first one is an italic font. Thus, in principle the italic correction is missing. This can be added by \/ in text mode, but math mode is different.

As workaround, \textit can be used that also automatically adds the italic correction at the end. The workaround can work here, because the glyph "p" of the italic text font look the same as the glyph, that is used in math. But that depends on the font settings and it is not true in general.

\documentclass{article}
\begin{document}

  $p$-center

  \textit{p}-center

\end{document}

Result

|improve this answer|||||
  • 2
    the computer modern math "p" and the text italic "p" are not quite the same. (look closely; the counter of the math "p" is just a bit more open.) but they're probably close enough. – barbara beeton Mar 5 '17 at 15:16
3

If you're free to use LuaLaTeX, it's straightforward to set up a Lua function that automatically inserts a certain amount of kerning (e.g., 1mu) ahead of the dash symbol.

The following code captures all instances of o, p and \rho immediately followed by a dash character and one or more alphabetic characters.

enter image description here

% !TeX program = lualatex
\documentclass{article}

\usepackage{luacode}
\begin{luacode}
function kerndash ( s )
  return ( string.gsub ( s , "([op])%$%-(%a*)" , "%1\\mkern1mu$-%2" ) )
end
\end{luacode}
\AtBeginDocument{\directlua{luatexbase.add_to_callback 
  ( "process_input_buffer" , kerndash, "kerndash" )}}

\begin{document}
$p$-center

$\rho$-centric

$o$-adic
\end{document}
|improve this answer|||||
  • Mico, would not this function also add unwanted kern into an expression $-p-c$? – Boris Mar 5 '17 at 16:56
  • @Boris - It depends crucially on what, if anything, precedes the first $ symbol. The search criterion, ([op])%$%-(%a*), may be expressed in words as "(o or p) followed by exactly 1 instance of $ followed by exactly 1 instance of - followed by 1 or more alphabetical characters". If your example string were augmented to (say) $\rho$-p-c$\sigma$ (don't ask me what this might mean...), the string would satisfy the search criterion, and the Lua function would indeed insert kern between\rho and -p. However, that would presumably be alright by the OP's stated objective, right? – Mico Mar 5 '17 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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