Skip to main content
Answer fixed for OpenType.
Source Link
Heiko Oberdiek
  • 277.4k
  • 25
  • 738
  • 1.1k

TeXs without OpenType

(|Lua|pdf|Xe|pdf)TeX only sees boxes. It does not know, how the glyph is shaped inside the character box. The implicit kerning does not apply between the base character and its sub- or superscript.

The kerning can manually be fixed:

\documentclass{article} \usepackage{unicode-math} \setmainfont{Latin Modern Roman} \setmathfont{Latin Modern Math} \begin{document} \[ \mathbf P(x) = \mathbf P_n + \mathbf A^n \] \[ \mathbf P(x) = \mathbf P_{\!n} + \mathbf A^{\!n} \] \end{document} 

Result

P and A could be made active in math mode. Then they could look for a sub- or superscript. But it does not help here, because P and A are hidden inside \mathbf. An easy way is to make \mathbf P a macro that can check the following token for a subscript:

\documentclass{article} \usepackage{unicode-math} \setmainfont{Latin Modern Roman} \setmathfont{Latin Modern Math} \usepackage{ltxcmds}[2011/04/14] \makeatletter \newcommand*{\bfP}{% \mathbf{P}% \ltx@ifnextchar@nospace_{\@CatchSubScriptNegKern}{}% } \newcommand*{\bfA}{% \mathbf{A}% \ltx@ifnextchar@nospace^{\@CatchSuperScriptNegKern}{}% } \def\@CatchSubScriptNegKern_#1{% _{\!#1}% } \def\@CatchSuperScriptNegKern^#1{% ^{\!#1}% } \makeatother \begin{document} \[ \bfP(x) = \bfP_n + \bfA^n \] \end{document} 

Result

LuaTeX/XeTeX

Package unicode-math seems to have a feature to replace some superscripts and subscripts to get a better placement. With xits-math.otf this works:

\documentclass{article} \usepackage{unicode-math} \setmainfont{Latin Modern Roman} %\setmathfont{Latin Modern Math} \setmathfont{xits-math.otf} \begin{document} \[ \mathbf P(x) = \mathbf P_n + \mathbf A^n \] \[ \mathbf A^n = \mathbf A^^^^207f \mathrel{;} \mathbf A^{nn} \] \[ \mathbf P_n \ne \mathbf P_^^^^2099 \mathrel{;} \mathbf P_{nn} \] \end{document} 

Result

Remarks:

  • Image generated by LuaLaTeX.

  • latinmodern-math.otf and Asana-Math.otf do not work.

  • If the sub-/superscript is not a single character, it does not work for LuaLaTeX as can be seen in the image.

  • Sub- and superscripts of n are also available as Unicode characters:

     U+2099: LATIN SUBSCRIPT SMALL LETTER N U+207F: SUPERSCRIPT LATIN SMALL LETTER N 

    Only the latter case of a superscript works in the example. The subscript case failed for latinmodern-math.otf, Asana-Math.otf and xits-math.otf.

(|Lua|pdf|Xe)TeX only sees boxes. It does not know, how the glyph is shaped inside the character box. The implicit kerning does not apply between the base character and its sub- or superscript.

The kerning can manually be fixed:

\documentclass{article} \usepackage{unicode-math} \setmainfont{Latin Modern Roman} \setmathfont{Latin Modern Math} \begin{document} \[ \mathbf P(x) = \mathbf P_n + \mathbf A^n \] \[ \mathbf P(x) = \mathbf P_{\!n} + \mathbf A^{\!n} \] \end{document} 

Result

P and A could be made active in math mode. Then they could look for a sub- or superscript. But it does not help here, because P and A are hidden inside \mathbf. An easy way is to make \mathbf P a macro that can check the following token for a subscript:

\documentclass{article} \usepackage{unicode-math} \setmainfont{Latin Modern Roman} \setmathfont{Latin Modern Math} \usepackage{ltxcmds}[2011/04/14] \makeatletter \newcommand*{\bfP}{% \mathbf{P}% \ltx@ifnextchar@nospace_{\@CatchSubScriptNegKern}{}% } \newcommand*{\bfA}{% \mathbf{A}% \ltx@ifnextchar@nospace^{\@CatchSuperScriptNegKern}{}% } \def\@CatchSubScriptNegKern_#1{% _{\!#1}% } \def\@CatchSuperScriptNegKern^#1{% ^{\!#1}% } \makeatother \begin{document} \[ \bfP(x) = \bfP_n + \bfA^n \] \end{document} 

Result

TeXs without OpenType

(|pdf)TeX only sees boxes. It does not know, how the glyph is shaped inside the character box. The implicit kerning does not apply between the base character and its sub- or superscript.

The kerning can manually be fixed:

\documentclass{article} \usepackage{unicode-math} \setmainfont{Latin Modern Roman} \setmathfont{Latin Modern Math} \begin{document} \[ \mathbf P(x) = \mathbf P_n + \mathbf A^n \] \[ \mathbf P(x) = \mathbf P_{\!n} + \mathbf A^{\!n} \] \end{document} 

Result

P and A could be made active in math mode. Then they could look for a sub- or superscript. But it does not help here, because P and A are hidden inside \mathbf. An easy way is to make \mathbf P a macro that can check the following token for a subscript:

\documentclass{article} \usepackage{unicode-math} \setmainfont{Latin Modern Roman} \setmathfont{Latin Modern Math} \usepackage{ltxcmds}[2011/04/14] \makeatletter \newcommand*{\bfP}{% \mathbf{P}% \ltx@ifnextchar@nospace_{\@CatchSubScriptNegKern}{}% } \newcommand*{\bfA}{% \mathbf{A}% \ltx@ifnextchar@nospace^{\@CatchSuperScriptNegKern}{}% } \def\@CatchSubScriptNegKern_#1{% _{\!#1}% } \def\@CatchSuperScriptNegKern^#1{% ^{\!#1}% } \makeatother \begin{document} \[ \bfP(x) = \bfP_n + \bfA^n \] \end{document} 

Result

LuaTeX/XeTeX

Package unicode-math seems to have a feature to replace some superscripts and subscripts to get a better placement. With xits-math.otf this works:

\documentclass{article} \usepackage{unicode-math} \setmainfont{Latin Modern Roman} %\setmathfont{Latin Modern Math} \setmathfont{xits-math.otf} \begin{document} \[ \mathbf P(x) = \mathbf P_n + \mathbf A^n \] \[ \mathbf A^n = \mathbf A^^^^207f \mathrel{;} \mathbf A^{nn} \] \[ \mathbf P_n \ne \mathbf P_^^^^2099 \mathrel{;} \mathbf P_{nn} \] \end{document} 

Result

Remarks:

  • Image generated by LuaLaTeX.

  • latinmodern-math.otf and Asana-Math.otf do not work.

  • If the sub-/superscript is not a single character, it does not work for LuaLaTeX as can be seen in the image.

  • Sub- and superscripts of n are also available as Unicode characters:

     U+2099: LATIN SUBSCRIPT SMALL LETTER N U+207F: SUPERSCRIPT LATIN SMALL LETTER N 

    Only the latter case of a superscript works in the example. The subscript case failed for latinmodern-math.otf, Asana-Math.otf and xits-math.otf.

Macros \bfP and \bfA added.
Source Link
Heiko Oberdiek
  • 277.4k
  • 25
  • 738
  • 1.1k

(|Lua|pdf|Xe)TeX only sees boxes. It does not know, how the glyph is shaped inside the character box. The implicit kerning does not apply between the base character and its sub- or superscript.

The kerning can manually be fixed:

\documentclass{article} \usepackage{unicode-math} \setmainfont{Latin Modern Roman} \setmathfont{Latin Modern Math} \begin{document} \[ \mathbf P(x) = \mathbf P_n + \mathbf A^n \] \[ \mathbf P(x) = \mathbf P_{\!n} + \mathbf A^{\!n} \] \end{document} 

Result

P and A could be made active in math mode. Then they could look for a sub- or superscript. But it does not help here, because P and A are hidden inside \mathbf. An easy way is to make \mathbf P a macro that can check the following token for a subscript:

\documentclass{article} \usepackage{unicode-math} \setmainfont{Latin Modern Roman} \setmathfont{Latin Modern Math} \usepackage{ltxcmds}[2011/04/14] \makeatletter \newcommand*{\bfP}{% \mathbf{P}% \ltx@ifnextchar@nospace_{\@CatchSubScriptNegKern}{}% } \newcommand*{\bfA}{% \mathbf{A}% \ltx@ifnextchar@nospace^{\@CatchSuperScriptNegKern}{}% } \def\@CatchSubScriptNegKern_#1{% _{\!#1}% } \def\@CatchSuperScriptNegKern^#1{% ^{\!#1}% } \makeatother \begin{document} \[ \bfP(x) = \bfP_n + \bfA^n \] \end{document} 

Result

(|Lua|pdf|Xe)TeX only sees boxes. It does not know, how the glyph is shaped inside the character box. The implicit kerning does not apply between the base character and its sub- or superscript.

The kerning can manually be fixed:

\documentclass{article} \usepackage{unicode-math} \setmainfont{Latin Modern Roman} \setmathfont{Latin Modern Math} \begin{document} \[ \mathbf P(x) = \mathbf P_n + \mathbf A^n \] \[ \mathbf P(x) = \mathbf P_{\!n} + \mathbf A^{\!n} \] \end{document} 

Result

(|Lua|pdf|Xe)TeX only sees boxes. It does not know, how the glyph is shaped inside the character box. The implicit kerning does not apply between the base character and its sub- or superscript.

The kerning can manually be fixed:

\documentclass{article} \usepackage{unicode-math} \setmainfont{Latin Modern Roman} \setmathfont{Latin Modern Math} \begin{document} \[ \mathbf P(x) = \mathbf P_n + \mathbf A^n \] \[ \mathbf P(x) = \mathbf P_{\!n} + \mathbf A^{\!n} \] \end{document} 

Result

P and A could be made active in math mode. Then they could look for a sub- or superscript. But it does not help here, because P and A are hidden inside \mathbf. An easy way is to make \mathbf P a macro that can check the following token for a subscript:

\documentclass{article} \usepackage{unicode-math} \setmainfont{Latin Modern Roman} \setmathfont{Latin Modern Math} \usepackage{ltxcmds}[2011/04/14] \makeatletter \newcommand*{\bfP}{% \mathbf{P}% \ltx@ifnextchar@nospace_{\@CatchSubScriptNegKern}{}% } \newcommand*{\bfA}{% \mathbf{A}% \ltx@ifnextchar@nospace^{\@CatchSuperScriptNegKern}{}% } \def\@CatchSubScriptNegKern_#1{% _{\!#1}% } \def\@CatchSuperScriptNegKern^#1{% ^{\!#1}% } \makeatother \begin{document} \[ \bfP(x) = \bfP_n + \bfA^n \] \end{document} 

Result

Source Link
Heiko Oberdiek
  • 277.4k
  • 25
  • 738
  • 1.1k

(|Lua|pdf|Xe)TeX only sees boxes. It does not know, how the glyph is shaped inside the character box. The implicit kerning does not apply between the base character and its sub- or superscript.

The kerning can manually be fixed:

\documentclass{article} \usepackage{unicode-math} \setmainfont{Latin Modern Roman} \setmathfont{Latin Modern Math} \begin{document} \[ \mathbf P(x) = \mathbf P_n + \mathbf A^n \] \[ \mathbf P(x) = \mathbf P_{\!n} + \mathbf A^{\!n} \] \end{document} 

Result