3

I am trying to produce wide grave and acute accents. Following \widetilde and \widehat from The TexBook and https://texwelt.de/fragen/26664/breiter-gravis-fur-pdflatex/26908 , I went on with

\documentclass{article}
\pagestyle{empty}
\usepackage{graphicx}
\usepackage[T1]{fontenc}%%% we do wish this if we stick to pdflatex
\usepackage{newtxtext}%%% we do wish this if we stick to pdflatex
\usepackage[slantedGreek,subscriptcorrection]{newtxmath}%%% we do wish if we stick to pdflatex
\newcommand{\widegraveA}{\mathaccent"0012 }
\newcommand{\wideacuteA}{\mathaccent"0013 }
\makeatletter
\newcommand\wideacuteB[1]{%
  \mathchoice
  {\@wideaccent{\displaystyle}{#1}{\mathchar"7013}{-1.06ex}{1}{1}}
  {\@wideaccent{\textstyle}{#1}{\mathchar"7013}{-1.05ex}{1}{1}}
  {\@wideaccent{\scriptstyle}{#1}{\mathchar"7013}{-.75ex}{1}{1}}
  {\@wideaccent{\scriptscriptstyle}{#1}{\mathchar"7013}{-.54ex}{1}{1}}
}
\newcommand\widegraveB[1]{%
  \mathchoice
  {\@wideaccent{\displaystyle}{#1}{\mathchar"7012}{-1.06ex}{1}{1}}
  {\@wideaccent{\textstyle}{#1}{\mathchar"7012}{-1.05ex}{1}{1}}
  {\@wideaccent{\scriptstyle}{#1}{\mathchar"7012}{-.75ex}{1}{1}}
  {\@wideaccent{\scriptscriptstyle}{#1}{\mathchar"7012}{-.54ex}{1}{1}}
}
\newcommand{\@wideaccent}[6]{
  \setbox\@tempboxa\hbox{$\m@th#1#2$}%
  \@tempdima=\ht\@tempboxa
  \@tempdimb=\wd\@tempboxa
  \ooalign{%
    \box\@tempboxa\cr
    \hidewidth\raise\dimexpr\@tempdima#4\relax\hbox{\resizebox{#5\@tempdimb}{#6\height}{$\m@th#1#3$}}\hidewidth
  }%
}
\makeatother
\begin{document}
 \(\widegraveA{\mathit{loop}}, \widegraveA{\mathit{pool}}, \widegraveA{\mathit{buffer}}, \widegraveA{\sigma_k}, \wideacuteA{\mathit{loop}}, \wideacuteA{\mathit{pool}}, \wideacuteA{\mathit{buffer}}, \wideacuteA{\sigma_k}\)\\
 \(\widegraveB{\mathit{loop}}, \widegraveB{\mathit{pool}}, \widegraveB{\mathit{buffer}}, \widegraveB{\sigma_k}, \wideacuteB{\mathit{loop}}, \wideacuteB{\mathit{pool}}, \wideacuteB{\mathit{buffer}}, \wideacuteB{\sigma_k}\)
\end{document}

As you see, \wideacuteA and \widegraveA don't stretch the grave and acute at all, and \wideacuteB and \widegraveB produce sometimes accents uncentered, too far left, too far right, too narrow, too near to the text, or too far from the text:

pdflatex output

  1. Why?

  2. How to make \mathaccent stretch the accents?

  3. How to make \widegraveB and \wideacuteB produce non-ugly (or at least less ugly) accents?

PS. In this particular question, we do wish T1 and NewTX fonts with the given options. Moreover, the order of preference of text under the wide acute and grave is this, ordered from most to least important:

  1. \sigma_k,
  2. \mathit{buffer},
  3. \mathit{loop} and \mathit{pool},
  4. \mathit{sum},
  5. all other multiletter maths.

We handle the unicode engines in Wide acute and wide grave for TeX Gyre Termes and TeX Gyre Termes Math .

  • the font does not have wide acute and grave – David Carlisle Aug 16 '21 at 06:40
  • @DavidCarlisle Ok, thanks. Are you, perhaps, aware of Type 1 or Unicode math fonts with wide grave and acute? In fact, what matters to me is not simply “wide”, but “stretchable”. –  Aug 16 '21 at 12:46
  • I'm not aware of any font with those accents extendable (that is not to say there is no such font) you could of course stretch them with graphics operators as you show here, or draw the symbol with tikz or similar but the results are likely to be "variable" – David Carlisle Aug 16 '21 at 12:58
  • depending on your actual use do you want an accent symbol at all? hard to make that look nice extended. It may look better to have a sloping line which you can easily slope in either direction and easily extend to any width. – David Carlisle Aug 16 '21 at 13:00
  • In many of these cases it is probably better to have two syntaxes to use, like e^{x} and \exp(x), then one can be used for short/narrow input, the other for more complex input. – daleif Aug 16 '21 at 13:20
  • 1
    @DavidCarlisle Extendable sloped lines would also be fine with me, provided they look better than the extendable acute and grave above. First disadvantage: for accenting one-letter symbols on the baseline, the standard \acute and \grave are ideal, so, the sloped lines better not differ from the accents too much . Second disadvantage: the drawn sloped lines do not produce anything in the PDF text layer, whereas the above \widegraveB and \wideacuteB do produce the acutes and the graves in the text. –  Aug 16 '21 at 21:13
  • @daleif Right, multiletter commands could be an option in general, but that's not what the author wants in the concrete case. They do want extendible accents or something that looks similar (such as sloped lines). It would be even better if it gave something usable also in the PDF text layer. –  Aug 16 '21 at 21:20
  • We see this sort of thing/request from physics users from time to time. It is just not a good idea, it looks horrible and is unreadable for the end user – daleif Aug 16 '21 at 21:20
  • @daleif As for „looks horrible“: I completely agree, and that's exactly why I am asking the question. As for unreadability: What exactly is unreadable? In the concrete case, the author has some meaningful pronunciation (which is offtopic here) for the accented long variables, so I completely disagree with “unreadable for the end user”. –  Aug 16 '21 at 21:28
  • @daleif What has to be done is something (from an author's viewpoint) analogous to the already present \widetilde and \widehat from TeX; the end user and the content author do not need to know how difficult the different kinds of extensible accents are typeset internally and why. –  Aug 16 '21 at 21:30
  • @DavidCarlisle Concerning ‘but the results are likely to be "variable"’: I'd be ok with the result being at least as good as the current \wideacuteB and \widegraveB in general and strictly better only in some aspects (not necessarily in all). –  Aug 16 '21 at 21:33
  • 1
    I don't think you'll ever get an answer to all four questions. I could explain (1), but as for the rest... – campa Aug 17 '21 at 13:19
  • @campa Please feel free, though we all know that „why“ questions are tricky in many respects. Here, I don't mean „What the hell“ but „What are the reasons“. David said this already for \mathaccent; you could add to it or try to expand on the \widegraveB and \wideacuteB macros. –  Aug 18 '21 at 11:39

1 Answers1

3

Here, I adapted my answer at Really wide hat symbol, even making it work in \scriptstyle.

EDITED/overhauled to work better in the smaller scripts.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{scalerel,stackengine}
\stackMath
\newcommand\reallywideacute[1]{%
  \ThisStyle{\savestack\tmpA{$\SavedStyle#1$}%
  \savestack{\tmpbox}{%
    \def\scriptstyleScaleFactor{0.8}% LOCAL CHANGE
    \def\scriptscriptstyleScaleFactor{0.68}% LOCAL CHANGE
    $\SavedStyle\stretchto{%
    \scalerel*[\wd\tmpAcontent]%
      {\kern-2.05\LMpt\mathchar"7013\kern-1.1\LMpt}%
    {\rule{0ex}{\textheight}}%
  }{2.6\LMex}$}%
  \stackengine{-7.5\LMpt}{\SavedStyle#1}{\tmpbox}{O}{c}{F}{T}{S}}%
}
\newcommand\reallywidegrave[1]{%
  \ThisStyle{\savestack\tmpA{$\SavedStyle#1$}%
  \savestack{\tmpbox}{%
    \def\scriptstyleScaleFactor{0.8}% LOCAL CHANGE
    \def\scriptscriptstyleScaleFactor{0.68}% LOCAL CHANGE
    $\SavedStyle\stretchto{%
    \scalerel*[\wd\tmpAcontent]%
      {\kern-1.1\LMpt\mathchar"7012\kern-2.1\LMpt}%
    {\rule{0ex}{\textheight}}%
  }{2.6\LMex}$}%
  \stackengine{-7.5\LMpt}{\SavedStyle#1}{\tmpbox}{O}{c}{F}{T}{S}}%
}
\def\scriptstyleScaleFactor{0.8}% GLOBAL CHANGE, 0.7 DEFAULT
\def\scriptscriptstyleScaleFactor{0.68}% GLOBAL CHANGE, 0.5 DEFAULT
\parskip 1ex
\begin{document}

$\reallywideacute{zbcdefghijklm}\quad\reallywidegrave{zbcdefghijklm}$

$\reallywideacute{zbcdefghijk}\quad\reallywidegrave{zbcdefghijk}$

$\reallywideacute{zbcdefghi}\quad\reallywidegrave{zbcdefghi}$

$\reallywideacute{zbcdefg}\quad\reallywidegrave{zbcdefg}$

$\reallywideacute{zbcde}\quad\reallywidegrave{zbcde}$

$\reallywideacute{zbc}\quad\reallywidegrave{zbc}$

$\reallywideacute{zb}\quad\reallywidegrave{zb}$

$\scriptstyle \reallywideacute{zbcdefghijklm}\quad\reallywidegrave{zbcdefghijklm}$

$\scriptstyle \reallywideacute{zbcdefghijk}\quad\reallywidegrave{zbcdefghijk}$

$\scriptstyle \reallywideacute{zbcdefghi}\quad\reallywidegrave{zbcdefghi}$

$\scriptstyle \reallywideacute{zbcdefg}\quad\reallywidegrave{zbcdefg}$

$\scriptstyle \reallywideacute{zbcde}\quad\reallywidegrave{zbcde}$

$\scriptstyle \reallywideacute{zbc}\quad\reallywidegrave{zbc}$

$\scriptstyle \reallywideacute{zb}\quad\reallywidegrave{zb}$

\end{document}

enter image description here

In \scriptscriptstyle, it is still passable:

enter image description here


SUPPLEMENT

To use newtxmath, the kerns need to be adjusted:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{newtxtext, newtxmath}
\usepackage{scalerel,stackengine}
\stackMath
\newcommand\reallywideacute[1]{%
  \ThisStyle{\savestack\tmpA{$\SavedStyle#1$}%
  \savestack{\tmpbox}{$\SavedStyle\stretchto{%
    \scalerel*[\wd\tmpAcontent]%
      {\kern-.95\LMpt\mathchar"7013\kern-.12\LMpt}%
    {\rule{0ex}{\textheight}}%
  }{2.6\LMex}$}%
  \stackengine{-7.5\LMpt}{\SavedStyle#1}{\tmpbox}{O}{c}{F}{T}{S}}%
}
\newcommand\reallywidegrave[1]{%
  \ThisStyle{\savestack\tmpA{$\SavedStyle#1$}%
  \savestack{\tmpbox}{$\SavedStyle\stretchto{%
    \scalerel*[\wd\tmpAcontent]%
      {\kern-.12\LMpt\mathchar"7012\kern-.95\LMpt}%
    {\rule{0ex}{\textheight}}%
  }{2.6\LMex}$}%
  \stackengine{-7.5\LMpt}{\SavedStyle#1}{\tmpbox}{O}{c}{F}{T}{S}}%
}
\parskip 1ex
\begin{document}

$\reallywideacute{zbcdefghijklm}\quad\reallywidegrave{zbcdefghijklm}$

$\reallywideacute{zbcdefghijk}\quad\reallywidegrave{zbcdefghijk}$

$\reallywideacute{zbcdefghi}\quad\reallywidegrave{zbcdefghi}$

$\reallywideacute{zbcdefg}\quad\reallywidegrave{zbcdefg}$

$\reallywideacute{zbcde}\quad\reallywidegrave{zbcde}$

$\reallywideacute{zbc}\quad\reallywidegrave{zbc}$

$\reallywideacute{zb}\quad\reallywidegrave{zb}$

$\scriptstyle \reallywideacute{zbcdefghijklm}\quad\reallywidegrave{zbcdefghijklm}$

$\scriptstyle \reallywideacute{zbcdefghijk}\quad\reallywidegrave{zbcdefghijk}$

$\scriptstyle \reallywideacute{zbcdefghi}\quad\reallywidegrave{zbcdefghi}$

$\scriptstyle \reallywideacute{zbcdefg}\quad\reallywidegrave{zbcdefg}$

$\scriptstyle \reallywideacute{zbcde}\quad\reallywidegrave{zbcde}$

$\scriptstyle \reallywideacute{zbc}\quad\reallywidegrave{zbc}$

$\scriptstyle \reallywideacute{zb}\quad\reallywidegrave{zb}$

\end{document}

enter image description here

  • Splendid and fine result. – Sebastiano Aug 17 '21 at 14:13
  • 2
    Erm, I won't go as far as Sebastiano and call this "splendid" but +1 for the effort ;-) – campa Aug 17 '21 at 14:32
  • 1
    @campa I always marvel at Sebastiano's exuberance. Thanks for the upvote. – Steven B. Segletes Aug 17 '21 at 14:34
  • 1
    Thanks! +1, I really appreciate this. Maybe, I should have said that in the particular questions I do care about the given packages and the given examples for pdflatex (for unicode, we'd have a different story, I'll make yet another question out of it). I made this now clear in the questuion. With \usepackage{newtxtext} \usepackage[slantedGreek,subscriptcorrection]{newtxmath} added to you example, I get ! Arithmetic overflow. <recently read> \dimen@ii. –  Aug 18 '21 at 11:52
  • 1
    @GeekestGeek Please see my supplement, addressing the accents of the newtxmath fonts. – Steven B. Segletes Aug 18 '21 at 12:04
  • Works like a charm so far. Thank you again!!! I'll do some more testing later today and report/tick here. In the meantime: how can I put all the accents all a bit lower (perhaps, even so more over \reallywidegrave{\mathit{loop}} and \reallywideacute{\mathit{pool}}) and make the all accents slightly thinner? Further: is it possible to make the accents slightly shorter or move them a bit such that they do not extend over the top row of the letters (e.g., in \reallywideacute{\mathit{loop}}, \reallywideacute{\mathit{pool}}, \reallywideacute{\mathit{buffer}})? –  Aug 18 '21 at 12:14
  • 1
    @GeekestGeek The -7pt after \stackengine affects only the vertical placement, whereas the 2.6ex before the \stackengine affects both the thickness as well as the vertical placement. Playing around, you might change the -7pt to -6pt and the 2.6ex to 2ex. Suggestion: get the thickness to the desired level, and then work on the vertical adjustment. – Steven B. Segletes Aug 18 '21 at 12:26
  • I've just seen it; thanks! –  Aug 18 '21 at 12:31
  • 1
    @GeekestGeek That is why my "Suggestion" is to lock in the thickness first. – Steven B. Segletes Aug 18 '21 at 12:33
  • Got it, thanks! If you want to make the accents shorter such that they don't go over the left bound of \mathit-content, do you say .9\wd\tmpAcontent instead of \wd\tmpAcontent, or is there a cleaner way? –  Aug 18 '21 at 12:34
  • @GeekestGeek Better would be to slightly change the \kern before the \mathchar in the more positive direction. Another point: extra calculation is done to discern and capture the current math style (normal vs script, etc.). If you only ever wanted to use this at normal non-script sizes, then issuing in the preamble \ignoremathstyle will save you some calculation time. – Steven B. Segletes Aug 18 '21 at 12:38
  • Following your suggestion, I now have \kern-.82pt\mathchar"7013 in \reallywideacute and no kern before \mathchar "7012 in \reallywidegrave. As for script and scriptscript sizes, it is unknown whether I'd use them, so, better be prepared for them, too. –  Aug 19 '21 at 17:14
  • I noticed that in script and scriptscript the accent is too thick in comparison to the main text. Any idea on how to make the accents thinner in script and scriptscript? –  Aug 19 '21 at 17:16
  • @GeekestGeek Done. Significant overhaul. Note that \scriptstyleScaleFactor and \scriptscriptstyleScaleFactor are font-dependent. – Steven B. Segletes Aug 19 '21 at 18:29
  • @StevenB.Segletes Thanks again; ticked! (1) Could I potentially simply change \hidewidth to something cleverer in my original \wideacuteB and \widegraveB to get the same output without invoking the full stackengine and scalerel? (2) Any idea or suggestion or improvement for http://tex.stackexchange.com/questions/611151, where the draft is based on your solution? –  Aug 19 '21 at 20:41