2

When attempting to typeset unit vectors with the physics package shorthand \vu the following problems occur when using kpfonts which do not occur when using computer modern.

  1. \vu{i} and \vu{j} do not use dotless versions of i and j.
  2. When explicitly stating \vu{\imath} and \vu{\jmath}, the produced output is not in boldface, like every other character.
  3. When working around the issue using \hat{\textbf{\j}}, the output (just for j) still has a dot.

2 Answers 2

4

If I try

\documentclass{article}
%\usepackage{kpfonts}
\usepackage{physics}

\begin{document}

$\vu{i}+\vu{j}$

\end{document}

(note that kpfonts is commented out), I get

enter image description here

The dots are there and it's not surprising, because the package does

% Unit vector [star for Greek and italic Roman]
\DeclareDocumentCommand\vectorunit{ s m }{%
  \IfBooleanTF{#1}
    {\boldsymbol{\hat{#2}}}
    {\mathbf{\hat{#2}}}%
}
% Shorthand for \vectorunit
\DeclareDocumentCommand\vu{}{\vectorunit}

(reformatted for clarity).

Here's a way out (not only for kpfonts):

\documentclass{article}
\usepackage{kpfonts}
\usepackage{physics}

\makeatletter
\ifkp@sfmath
  \DeclareSymbolFont{boldletters}{OT1}{jkpss\kp@fligm\kp@stylem}{b}{n}
  \SetSymbolFont{boldletters}{bold}{OT1}{jkpss\kp@fligm\kp@stylem}{b}{n}
\else
  \DeclareSymbolFont{boldletters}{OT1}{jkp\kp@famillem\kp@fligm\kp@stylem}{b}{n}
  \SetSymbolFont{boldletters}{bold}{OT1}{jkp\kp@famillem\kp@fligm\kp@stylem}{b}{n}
\fi
\SetSymbolFont{boldletters}{rm}{OT1}{jkp\kp@famillem\kp@fligm\kp@stylem}{b}{n}
\SetSymbolFont{boldletters}{boldrm}{OT1}{jkp\kp@famillem\kp@fligm\kp@stylem}{b}{n}
\SetSymbolFont{boldletters}{sf}{OT1}{jkpss\kp@fligm\kp@stylem}{b}{n}
\SetSymbolFont{boldletters}{boldsf}{OT1}{jkpss\kp@fligm\kp@stylem}{b}{n}
\DeclareSymbolFontAlphabet{\mathbf}{boldletters}
\makeatother
\DeclareMathSymbol{\bi}{\mathord}{boldletters}{"10}
\DeclareMathSymbol{\bj}{\mathord}{boldletters}{"11}

\begin{document}

$\vu{\bi}+\vu{\bj}$

\textbf{i j \^{\i} \^{\j}}

i j

\end{document}

enter image description here

A “self-fixing" approach, so you can input \vu{i} and \vu{j}.

\documentclass{article}
\usepackage{kpfonts}
\usepackage{physics}

\makeatletter
\ifkp@sfmath
  \DeclareSymbolFont{boldletters}{OT1}{jkpss\kp@fligm\kp@stylem}{b}{n}
  \SetSymbolFont{boldletters}{bold}{OT1}{jkpss\kp@fligm\kp@stylem}{b}{n}
\else
  \DeclareSymbolFont{boldletters}{OT1}{jkp\kp@famillem\kp@fligm\kp@stylem}{b}{n}
  \SetSymbolFont{boldletters}{bold}{OT1}{jkp\kp@famillem\kp@fligm\kp@stylem}{b}{n}
\fi
\SetSymbolFont{boldletters}{rm}{OT1}{jkp\kp@famillem\kp@fligm\kp@stylem}{b}{n}
\SetSymbolFont{boldletters}{boldrm}{OT1}{jkp\kp@famillem\kp@fligm\kp@stylem}{b}{n}
\SetSymbolFont{boldletters}{sf}{OT1}{jkpss\kp@fligm\kp@stylem}{b}{n}
\SetSymbolFont{boldletters}{boldsf}{OT1}{jkpss\kp@fligm\kp@stylem}{b}{n}
\DeclareSymbolFontAlphabet{\mathbf}{boldletters}
\makeatother
\DeclareMathSymbol{\bi}{\mathord}{boldletters}{"10}
\DeclareMathSymbol{\bj}{\mathord}{boldletters}{"11}

\ExplSyntaxOn
\RenewDocumentCommand\vectorunit{ s m }
 {
  \IfBooleanTF{#1}
    {\boldsymbol{\hat{#2}}}
    {\mathbf{\hat{\fixphysics_replace:n{#2}}}}
 }
\cs_new:Nn \fixphysics_replace:n
 {
  \str_case:nnF { #1 }
   {
    { i } { \bi }
    { j } { \bj }
   }
   { #1 }
 }
\ExplSyntaxOff

\begin{document}

$\vu{i}+\vu{j}$

\textbf{i j \^{\i} \^{\j}}

i j

\end{document}
4
  • Strangely enough, whatever combination of fonts and packages I was using before I moved to kpfonts had no dots on the is and js with \vu{i}. I will definitely use this though. Thanks! Commented Sep 4, 2021 at 20:23
  • 1
    @OmnipotentEntity I added a “self-fixing” approach.
    – egreg
    Commented Sep 4, 2021 at 20:23
  • Thanks for the self-fixing approach. I have found it good practice to just add shortcut commands for things like this so that I can change them all by editing only one place. In this case, I'm using \ihat, \jhat, and \khat, so it's not a big deal for me. However, the technique I'm sure will be useful for other things :D Commented Sep 4, 2021 at 20:27
  • @OmnipotentEntity Oh, and don't use physics.
    – egreg
    Commented Sep 4, 2021 at 20:29
0

While \j does have a dot, is it outside of the character boundary, so all one must do is explicitly clip to the font bounding box.

\usepackage{kpfonts}
\usepackage{amsthm, amsmath, amssymb}
\usepackage{mathrsfs}
\usepackage{trimclip}
\usepackage{physics}

% HACK: \imath and \jmath don't go bold in the \vu environment, so use text mode instead
\newcommand{\ihat}{\, \hat{\textbf{\i}}}
% HACK: \j still has a dot, but it's defined outside of the bounding box for the character. Explicitly clip so it doesn't display.
\newcommand{\jhat}{\, \hat{\textbf{\clipbox{0pt 0pt 0pt 0pt}{\j}}}} 

You must log in to answer this question.

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