3

Is there some way to get \widebar, \widehat, and \widetilde to work with the libertinus package, such as to get nice spacing?

Here's a MWE (which uses Vogt's \widebar command):

\documentclass{article}
\usepackage{libertinus}
\makeatletter
\let\save@mathaccent\mathaccent
\newcommand*\if@single[3]{%
  \setbox0\hbox{${\mathaccent"0362{#1}}^H$}%
  \setbox2\hbox{${\mathaccent"0362{\kern0pt#1}}^H$}%
  \ifdim\ht0=\ht2 #3\else #2\fi
  }
%The bar will be moved to the right by a half of \macc@kerna, which is computed by amsmath:
\newcommand*\rel@kern[1]{\kern#1\dimexpr\macc@kerna}
%If there's a superscript following the bar, then no negative kern may follow the bar;
%an additional {} makes sure that the superscript is high enough in this case:
\newcommand*\widebar[1]{\@ifnextchar^{{\wide@bar{#1}{0}}}{\wide@bar{#1}{1}}}
%Use a separate algorithm for single symbols:
\newcommand*\wide@bar[2]{\if@single{#1}{\wide@bar@{#1}{#2}{1}}{\wide@bar@{#1}{#2}{2}}}
\newcommand*\wide@bar@[3]{%
  \begingroup
  \def\mathaccent##1##2{%
%Enable nesting of accents:
    \let\mathaccent\save@mathaccent
%If there's more than a single symbol, use the first character instead (see below):
    \if#32 \let\macc@nucleus\first@char \fi
%Determine the italic correction:
    \setbox\z@\hbox{$\macc@style{\macc@nucleus}_{}$}%
    \setbox\tw@\hbox{$\macc@style{\macc@nucleus}{}_{}$}%
    \dimen@\wd\tw@
    \advance\dimen@-\wd\z@
%Now \dimen@ is the italic correction of the symbol.
    \divide\dimen@ 3
    \@tempdima\wd\tw@
    \advance\@tempdima-\scriptspace
%Now \@tempdima is the width of the symbol.
    \divide\@tempdima 10
    \advance\dimen@-\@tempdima
%Now \dimen@ = (italic correction / 3) - (Breite / 10)
    \ifdim\dimen@>\z@ \dimen@0pt\fi
%The bar will be shortened in the case \dimen@<0 !
    \rel@kern{0.6}\kern-\dimen@
    \if#31
      \overline{\rel@kern{-0.6}\kern\dimen@\macc@nucleus\rel@kern{0.4}\kern\dimen@}%
      \advance\dimen@0.4\dimexpr\macc@kerna
%Place the combined final kern (-\dimen@) if it is >0 or if a superscript follows:
      \let\final@kern#2%
      \ifdim\dimen@<\z@ \let\final@kern1\fi
      \if\final@kern1 \kern-\dimen@\fi
    \else
      \overline{\rel@kern{-0.6}\kern\dimen@#1}%
    \fi
  }%
  \macc@depth\@ne
  \let\math@bgroup\@empty \let\math@egroup\macc@set@skewchar
  \mathsurround\z@ \frozen@everymath{\mathgroup\macc@group\relax}%
  \macc@set@skewchar\relax
  \let\mathaccentV\macc@nested@a
%The following initialises \macc@kerna and calls \mathaccent:
  \if#31
    \macc@nested@a\relax111{#1}%
  \else
%If the argument consists of more than one symbol, and if the first token is
%a letter, use that letter for the computations:
    \def\gobble@till@marker##1\endmarker{}%
    \futurelet\first@char\gobble@till@marker#1\endmarker
    \ifcat\noexpand\first@char A\else
      \def\first@char{}%
    \fi
    \macc@nested@a\relax111{\first@char}%
  \fi
  \endgroup
}
\makeatother
\begin{document}
\[\widebar{a}\hspace{1pt}\widebar{b}\hspace{1pt}\widebar{c}\hspace{1pt}\widebar{d}\hspace{1pt}\widebar{e}\hspace{1pt}\widebar{f}\hspace{1pt}\widebar{g}\hspace{1pt}\widebar{h}\hspace{1pt}\widebar{i}\hspace{1pt}\widebar{j}\hspace{1pt}\widebar{k}\hspace{1pt}\widebar{l}\hspace{1pt}\widebar{m}\hspace{1pt}\widebar{n}\hspace{1pt}\widebar{o}\hspace{1pt}\widebar{p}\hspace{1pt}\widebar{q}\hspace{1pt}\widebar{r}\hspace{1pt}\widebar{s}\hspace{1pt}\widebar{t}\hspace{1pt}\widebar{u}\hspace{1pt}\widebar{v}\hspace{1pt}\widebar{w}\hspace{1pt}\widebar{x}\hspace{1pt}\widebar{y}\hspace{1pt}\widebar{z}\]
\[\widebar{A}\hspace{1pt}\widebar{B}\hspace{1pt}\widebar{C}\hspace{1pt}\widebar{D}\hspace{1pt}\widebar{E}\hspace{1pt}\widebar{F}\hspace{1pt}\widebar{G}\hspace{1pt}\widebar{H}\hspace{1pt}\widebar{I}\hspace{1pt}\widebar{J}\hspace{1pt}\widebar{K}\hspace{1pt}\widebar{L}\hspace{1pt}\widebar{M}\hspace{1pt}\widebar{N}\hspace{1pt}\widebar{O}\hspace{1pt}\widebar{P}\hspace{1pt}\widebar{Q}\hspace{1pt}\widebar{R}\hspace{1pt}\widebar{S}\hspace{1pt}\widebar{T}\hspace{1pt}\widebar{U}\hspace{1pt}\widebar{V}\hspace{1pt}\widebar{W}\hspace{1pt}\widebar{X}\hspace{1pt}\widebar{Y}\hspace{1pt}\widebar{Z}\]
\[\widetilde{a}\hspace{1pt}\widetilde{b}\hspace{1pt}\widetilde{c}\hspace{1pt}\widetilde{d}\hspace{1pt}\widetilde{e}\hspace{1pt}\widetilde{f}\hspace{1pt}\widetilde{g}\hspace{1pt}\widetilde{h}\hspace{1pt}\widetilde{i}\hspace{1pt}\widetilde{j}\hspace{1pt}\widetilde{k}\hspace{1pt}\widetilde{l}\hspace{1pt}\widetilde{m}\hspace{1pt}\widetilde{n}\hspace{1pt}\widetilde{o}\hspace{1pt}\widetilde{p}\hspace{1pt}\widetilde{q}\hspace{1pt}\widetilde{r}\hspace{1pt}\widetilde{s}\hspace{1pt}\widetilde{t}\hspace{1pt}\widetilde{u}\hspace{1pt}\widetilde{v}\hspace{1pt}\widetilde{w}\hspace{1pt}\widetilde{x}\hspace{1pt}\widetilde{y}\hspace{1pt}\widetilde{z}\]
\[\widetilde{A}\hspace{1pt}\widetilde{B}\hspace{1pt}\widetilde{C}\hspace{1pt}\widetilde{D}\hspace{1pt}\widetilde{E}\hspace{1pt}\widetilde{F}\hspace{1pt}\widetilde{G}\hspace{1pt}\widetilde{H}\hspace{1pt}\widetilde{I}\hspace{1pt}\widetilde{J}\hspace{1pt}\widetilde{K}\hspace{1pt}\widetilde{L}\hspace{1pt}\widetilde{M}\hspace{1pt}\widetilde{N}\hspace{1pt}\widetilde{O}\hspace{1pt}\widetilde{P}\hspace{1pt}\widetilde{Q}\hspace{1pt}\widetilde{R}\hspace{1pt}\widetilde{S}\hspace{1pt}\widetilde{T}\hspace{1pt}\widetilde{U}\hspace{1pt}\widetilde{V}\hspace{1pt}\widetilde{W}\hspace{1pt}\widetilde{X}\hspace{1pt}\widetilde{Y}\hspace{1pt}\widetilde{Z}\]
\[\widehat{a}\hspace{1pt}\widehat{b}\hspace{1pt}\widehat{c}\hspace{1pt}\widehat{d}\hspace{1pt}\widehat{e}\hspace{1pt}\widehat{f}\hspace{1pt}\widehat{g}\hspace{1pt}\widehat{h}\hspace{1pt}\widehat{i}\hspace{1pt}\widehat{j}\hspace{1pt}\widehat{k}\hspace{1pt}\widehat{l}\hspace{1pt}\widehat{m}\hspace{1pt}\widehat{n}\hspace{1pt}\widehat{o}\hspace{1pt}\widehat{p}\hspace{1pt}\widehat{q}\hspace{1pt}\widehat{r}\hspace{1pt}\widehat{s}\hspace{1pt}\widehat{t}\hspace{1pt}\widehat{u}\hspace{1pt}\widehat{v}\hspace{1pt}\widehat{w}\hspace{1pt}\widehat{x}\hspace{1pt}\widehat{y}\hspace{1pt}\widehat{z}\]
\[\widehat{A}\hspace{1pt}\widehat{B}\hspace{1pt}\widehat{C}\hspace{1pt}\widehat{D}\hspace{1pt}\widehat{E}\hspace{1pt}\widehat{F}\hspace{1pt}\widehat{G}\hspace{1pt}\widehat{H}\hspace{1pt}\widehat{I}\hspace{1pt}\widehat{J}\hspace{1pt}\widehat{K}\hspace{1pt}\widehat{L}\hspace{1pt}\widehat{M}\hspace{1pt}\widehat{N}\hspace{1pt}\widehat{O}\hspace{1pt}\widehat{P}\hspace{1pt}\widehat{Q}\hspace{1pt}\widehat{R}\hspace{1pt}\widehat{S}\hspace{1pt}\widehat{T}\hspace{1pt}\widehat{U}\hspace{1pt}\widehat{V}\hspace{1pt}\widehat{W}\hspace{1pt}\widehat{X}\hspace{1pt}\widehat{Y}\hspace{1pt}\widehat{Z}\]
\end{document}

which gives As displayed, some characters end up with quite bad spacing, e.g.:

enter image description here

So, how can one get nice spacing for \wide*** with unicode-math?

Dan
  • 31
  • 2
    The clever code by Hendrik Vogt was not maintained for quite some time. The algorithm used there to position the “wide bar” was designed for legacy TeX engines (pdfTeX, for example). When you use unicode-math with OpenType Math fonts, the algorithms in XeTeX and LuaTeX are very different. So, very likely, Vogt’s code is no longer suitable. – Ruixi Zhang Oct 18 '19 at 03:01
  • @RuixiZhang I see. Do you suggest some other algorithm for \widebar? What about \widehat and \widetilde? – Dan Oct 18 '19 at 11:30

0 Answers0