TeX - LaTeX Asked by chsk on April 26, 2021
I’m using the code from Tianren Liu’s answer to How do I robustly typeset a double-hat? to typeset double-hat accents in math mode, but sometimes the horizontal alignment is off. To wit:
documentclass{article}
usepackage{statmath}
makeatletter
newcommand{doublehat}[1]{%
begingroup%
letmacc@kernaz@%
letmacc@kernbz@%
letmacc@nucleus@empty%
hat{raisebox{.35ex}{vphantom{ensuremath{#1}}}smash{hat{#1}}}%
endgroup%
}
makeatother
begin{document}
$$hatbfbeta quad hatbfu$$
$$doublehatbfbeta quad doublehatbfu$$
end{document}
This yields:
The double hat on the u is fine, but that on the beta is much further to the left than it should be, and doesn’t look good. I lack the TeX skills to fix this, but would much appreciate the help of any wizard. Thanks!
You can measure the result of math-accent hat
(which is positioned by kern of nucleus with skewchar
). The skewchar
is not important in the following macro, we do only measuring the result by un-boxing boxes:
defmeasurehat#1{%
setbox0=vbox{$hat{#1}hfilbreak$nullpar
setbox0=lastboxunskipunpenaltyglobalsetbox1=lastbox}%
setbox0=hbox{unhbox1 unskipunpenaltyunskip globalsetbox2=lastbox}%
setbox0=vbox{unvbox2 setbox0=lastbox}%
}
defdoublehat#1{%
measurehat{#1}dimen0=wd0 measurehat{kern0pt#1}%
raise.35exrlap{kerndimexprdimen0-wd0$hat{phantom{#1}}$}{hat#1}%
}
% try this:
$$hatbfbeta quad hatbfu$$
$$doublehatbfbeta quad doublehatbfu$$
Correct answer by wipet on April 26, 2021
This is not really a satisfying answer, because it requires the user to do two things: indicate whether the glyph to be hatted is rm
or it
in shape, and also to specify the tangent of the font's italic slant angle in the macro tanslant
.
With that, I introduce hatsrm[<n>]{<token>}
and hatsit[<n>]{<token>}
to place n
hats (default 2) over the roman or italic token, respectively.
This is only set up currently for text or display style. If it is needed in the smaller math styles, let me know...perhaps something could be done.
documentclass{article}
usepackage{stackengine}
deftanslant{.25}
newcommandhatsrm[2][2]{ensurestackMath{%
ifnum#1>1%
stackengine{-4pt}{hatsrm[numexpr#1-1relax]{#2}}{%
scriptstylechar'136}{O}{c}{F}{T}{S}%
else%
stackengine{-3pt}{#2}{scriptstylechar'136}{O}{c}{F}{T}{S}%
fi%
}}
newcommandhatsit[2][2]{ensurestackMath{%
sbox0{$#2$}%
ifnum#1>1%
stackengine{-4pt}{hatsit[numexpr#1-1relax]{#2}}{%
kerntanslantht0scriptstylechar'136}{O}{c}{F}{T}{S}%
else%
stackengine{-3pt}{#2}{kerntanslantht0scriptstylechar'136}%
{O}{c}{F}{T}{S}%
fi%
}}
begin{document}
[
hatsit[1]{z}neqhatsrm{Lambda}neqhatsrm[3]{Delta}neqhatsit[4]{beta}
]
end{document}
Answered by Steven B. Segletes on April 26, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP