5

I use the Cochineal font for both text and math, using the cochineal and newtxmath packages. I only found one flaw about this font: the \bar, \tilde and \hat produce very small accents, whereas the \widebar, \widetilde and \widehat produce very big accents (using the \widebar command from Hendrik Vogt's answer here).

To have better looking accents, I tried to define stretched versions of them using the \hstretch command from the scalerel package. I defined

\newcommand{\stretchedbar}[1]{\hstretch{1.67}{\bar{\hstretch{0.6}{#1}}}}

and similar \stretchedtilde and \stretchedhat commands.

Here's a small comparaison of the three versions of bars, tildes and hats: Now the \stretched... commands give a good result for the size of the accents. However, these commands do not shift properly the accents on italic characters, they are too much on the left.

I found this answer, which introduce a \shifthat command. This command allows to manually shift the \hat on a specific character, so I guess I could adapt this code to manually shift all three accents on every character on which it is not placed properly. However, of course, this process would be very long, and I'm not even sure it would work for \tilde and \bar since I don't understand everything in the definition of this \shifthat command.

Is there any way I could define a stretched version of these accents, while adapting the shifting of the accents on italic characters? Or to redefine the accents' commands in another way to get a similar result?

  • Seems like investigating the "accents.sty" code could provide some useful ideas. The complete code is only a couple hundred lines, but I don't understand it well at all... – Hood Chatham Jan 23 at 2:18
  • 1
    Then let me know if the answer you got corresponds to that request, so I'll give to Sandy G the bounty if it is only one answer. – Sebastiano Jan 24 at 21:35
  • It seems to be a good solution, but I think I'd wait to see if someone gets another idea. And thanks a lot for the bounty, by the way! – Vincent Jan 25 at 16:56
7
+50

Here is a solution using the accents package.

enter image description here

First, define the accent marks from scratch:

\newcommand{\newbar}{\scalebox{.9}[.85]{\trimbox{0pt .55ex}{\textminus}}}
\newcommand{\newtilde}{\scalebox{.9}[1]{\trimbox{0pt .6ex}{\textasciitilde}}}
\newcommand{\newhat}{\scalebox{1.5}[.75]{\trimbox{0pt 1.1ex}{\textasciicircum}}}

The arguments in \scalebox control the width and thickness respectively. For example, if you want the bar to be thicker, increase the [.85] in the \newbar command. To make the bar less wide, decrease the {.9}. The \trimbox command comes from the trimclip package. It is needed to accommodate whitespace (vertically) around the accent marks. The nonzero argument controls the height of the accent mark above the symbol. To raise the accents, trim less. For example, to raise the bar, decrease the .55ex.

Once the accents are defined, they are called using the commands

\newcommand{\stretchedbar}[1]{\accentset{\newbar}{#1}}
\newcommand{\stretchedtilde}[1]{\accentset{\newtilde}{#1}}
\newcommand{\stretchedhat}[1]{\accentset{\newhat}{#1}}

Here is the complete code:

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[p,osf]{cochineal}
\usepackage[varqu,varl,var0]{inconsolata}
\usepackage[scale=.95,type1]{cabin}
\usepackage[cochineal,vvarbb]{newtxmath}
\usepackage[cal=boondoxo]{mathalfa}

\usepackage{accents}
\usepackage{trimclip}

\newcommand{\newbar}{\scalebox{.9}[.85]{\trimbox{0pt .55ex}{\textminus}}}
\newcommand{\newtilde}{\scalebox{.9}[1]{\trimbox{0pt .6ex}{\textasciitilde}}}
\newcommand{\newhat}{\scalebox{1.5}[.75]{\trimbox{0pt 1.1ex}{\textasciicircum}}}

\newcommand{\stretchedbar}[1]{\accentset{\newbar}{#1}}
\newcommand{\stretchedtilde}[1]{\accentset{\newtilde}{#1}}
\newcommand{\stretchedhat}[1]{\accentset{\newhat}{#1}}

\begin{document}
$\bar{e},\hat{e},\tilde{e}\quad\bar{y},\hat{y},\tilde{y}\quad\bar{A},\hat{A},\tilde{A}\quad\bar{\Omega},\hat{\Omega},\tilde{\Omega}\quad$

$\stretchedbar{e},\stretchedhat{e},\stretchedtilde{e}\quad\stretchedbar{y},\stretchedhat{y},\stretchedtilde{y}\quad\stretchedbar{A},\stretchedhat{A},\stretchedtilde{A}\quad\stretchedbar{\Omega},\stretchedhat{\Omega},\stretchedtilde{\Omega}\quad$

\end{document}

If you will need the symbols in sub/superscripts you will need to use \mathchoice. Combine the macros as follows:

\newcommand{\stretchedhat}[1]{\mathchoice
{\accentset{\scalebox{1.5}[.75]{\trimbox{0pt 1.1ex}{\textasciicircum}}}{#1}}
{\accentset{\scalebox{1.5}[.75]{\trimbox{0pt 1.1ex}{\textasciicircum}}}{#1}}
{\accentset{\scalebox{1}[.5]{\trimbox{0pt 1.2ex}{\textasciicircum}}}{#1}}
{\accentset{\scalebox{.8}[.4]{\trimbox{0pt 1.3ex}{\textasciicircum}}}{#1}}
}
\newcommand{\stretchedtilde}[1]{\mathchoice
{\accentset{\scalebox{.9}[1]{\trimbox{0pt .6ex}{\textasciitilde}}}{#1}}
{\accentset{\scalebox{.9}[1]{\trimbox{0pt .6ex}{\textasciitilde}}}{#1}}
{\accentset{\scalebox{.7}[.8]{\trimbox{0pt .7ex}{\textasciitilde}}}{#1}}
{\accentset{\scalebox{.5}[.6]{\trimbox{0pt .8ex}{\textasciitilde}}}{#1}}
}
\newcommand{\stretchedbar}[1]{\mathchoice
{\accentset{\scalebox{.9}[.85]{\trimbox{0pt .55ex}{\textminus}}}{#1}}
{\accentset{\scalebox{.9}[.85]{\trimbox{0pt .55ex}{\textminus}}}{#1}}
{\accentset{\scalebox{.7}[.7]{\trimbox{0pt .65ex}{\textminus}}}{#1}}
{\accentset{\scalebox{.5}[.6]{\trimbox{0pt .75ex}{\textminus}}}{#1}}
}

You can adjust the spacing and sizing to your liking.

$\stretchedhat{e}_{\stretchedhat{e}_{\stretchedhat{e}}}$
$\stretchedbar{e}_{\stretchedbar{e}_{\stretchedbar{e}}}$
$\stretchedtilde{e}_{\stretchedtilde{e}_{\stretchedtilde{e}}}$

enter image description here

Note that you must \protect these if you want to use them in \section, \paragraph, etc. There is a workaround for using hyperref with \texorpdfstring in the comments.

| improve this answer | |
  • 1
    I thank you very much for your attention to this question. +1. – Sebastiano Jan 24 at 18:16
  • 1
    @Schrödinger'scat I have not the question but...actually this is an only answer. – Sebastiano Jan 25 at 13:41
  • 1
    It seems to be a good solution! It would be good if the accents could adapt to sub/superscript though, but I guess correcting that with \mathchoice would not be hard? However, the issue mentioned by @Schrödinger'scat is indeed more problematic. – Vincent Jan 25 at 16:09
  • 1
    @Schrödinger'scat Of course you're right. Combining these seems to work ok. Is \section{\texorpdfstring{$\protect\stretchedhat{e}$}{$e$}} enough of a workaround? – Sandy G Jan 25 at 23:55
  • That's very good! Removed my comments. – user194703 Jan 25 at 23:57

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.