1

My goal is to write a \unitvector command which produces bold upright symbols with a bold circumflex accent. Here's my MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Bonum}
\setmathfont{texgyrebonum-math.otf}

\newcommand\unitvectorA[1]{\symbfup{\hat{#1}}}
\newcommand\unitvectorB[1]{\text{\textbf{\^{#1}}}}

\begin{document}
% Text versions for reference.
\textbf{\^{x}}
\textbf{\^{ρ}}

% First attempt: circumflex accent is not bold.
$\unitvectorA{x}$
$\unitvectorA{\rho}$

% Second attempt: missing \rho.
$\unitvectorB{x}$
$\unitvectorB{\rho}$
\end{document}

Here's the output:

enter image description here

There are other questions here which are similar to this one, but as far as I can tell, they either do not use unicode-math, or they do not provide a bold circumflex accent. (If I'm wrong about that, I'd love to know.)

I believe I understand why \symbfup doesn't do the "right" thing: Unicode does not define a "mathematical bold circumflex accent" (which seems like an oversight to me). I also do not have the luxury of using a math font which has a corresponding bold math font (such as XITS Math), which I believe would also provide a solution. Hence the attempted workaround using \text which, unfortunately, is not a workaround at all as it does not work.

I attempted to use the range feature of unicode-math to switch out fonts in some clever way, but I failed to find an incantation which worked.

Update:

I modified Marcel Krüger's answer by replacing XITS Math Bold with TeX Gyre Bonum Bold and obtained this:

enter image description here

It seems that there should be a way to nudge the accents over, but I don't understand yet how \Umathaccent works.

2 Answers 2

4

You can just skip unicode-math and load XITS Math Bold as a LaTeX Symbol font:

\documentclass{article}
\usepackage{amsmath}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Bonum}
\setmathfont{texgyrebonum-math.otf}

% We could use fontspec to load these but I am not a big fontspec fan:
\DeclareFontFamily{TU}{xitsmath}{}
\DeclareFontShape{TU}{xitsmath}{bx}{n}
  {<-> \UnicodeFontName{XITS Math Bold}{mode=base;script=math;language=DFLT}}{}

% Declare \symboldaccent:
\DeclareSymbolFont{boldaccents}{TU}{xitsmath}{bx}{n}
% Now we just need a nice name for the accent: (If you prefer a `\widehat`, just omit `fixed`)
\newcommand\boldhat{\Umathaccent fixed 7\symboldaccents"0302\relax}

\newcommand\unitvector[1]{\symbfup{\boldhat{#1}}}

% If we are using LuaTeX, we can also modify our text font to include the placement information for math accents:
\directlua{
  fonts.constructors.features.otf.register{
    name = 'mathcircumflex',
    description = 'Add math accent treatment to circumflex',
    manipulators = {
      base = function(tfm, v)
        tfm.nomath = false
        tfm.characters[0x2C6].top_accent = tfm.characters[0x2C6].width/2
      end
    }
  }
}
\DeclareFontFamily{TU}{bonumsemimath}{}
\DeclareFontShape{TU}{bonumsemimath}{bx}{n}
{<-> \UnicodeFontName{TeX Gyre Bonum Bold}{mode=base;+mathcircumflex;script=DFLT;language=DFLT}}{}
\DeclareSymbolFont{boldtextaccents}{TU}{bonumsemimath}{bx}{n}
\newcommand\boldtexthat{\Umathaccent fixed 7\symboldtextaccents"02C6\relax}

\newcommand\unitvectorB[1]{\symbfup{\boldtexthat{#1}}}

\begin{document}
% Text versions for reference.
\textbf{\^{x}}
\textbf{\^{ρ}}

$\unitvector{x}$
$\unitvector{\rho}$

$\unitvectorB{x}$
$\unitvectorB{\rho}$
\end{document}

enter image description here

3
  • That's a nice answer, but unfortunately the circumflex doesn't necessarily match the font. Is there a way to do this by grabbing the circumflex from TeX Gyre Bonum Bold instead of XITS Math Bold?
    – Derek
    Commented Aug 21, 2018 at 21:46
  • @Derek I added some LuaTeX code for this. For XeTeX you would have to add manual spacing in \unitvector. Commented Aug 22, 2018 at 8:59
  • This works perfectly in xelatex – I don't need to use the LuaTeX bit at all. Thanks!
    – Derek
    Commented Aug 22, 2018 at 22:04
0

Works only with lualatex. For xelatex you can use the FakeBold option.

\documentclass{article}
\usepackage{amsmath}
\usepackage{unicode-math}
\setmainfont{TeX Gyre Bonum}
\setmathfont{texgyrebonum-math.otf}
\usepackage[bold=0.8]{xfakebold}
\newcommand\unitvectorA[1]{\setBold\ensuremath{\hat{#1}}\unsetBold}
\begin{document}
    \unitvectorA{x} $\hat{x}$
    \unitvectorA{\rho}$\hat{\rho}$      
\end{document}

enter image description here

You must log in to answer this question.

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