% \iffalse %<*driver> \documentclass{l3doc} \usepackage{fontspec} \setmonofont{DejaVu Sans Mono}[Scale=MatchLowercase] \EnableCrossrefs \CodelineIndex \RecordChanges \begin{document} \DocInput{unicodehat.dtx} \end{document} % % \fi % % \title{The \textsf{unicodehat} package} % \author{Moritz R. Schäfer} % \date{\today} % \maketitle % % \begin{abstract} % Maps all precomposed Unicode Latin letters bearing a single circumflex % accent to the corresponding hatted letters in mathematics, while % preserving the original characters in text. Intended for directly typed % quantum-mechanical operator notation. % \end{abstract} % % \section{Usage} % Use UTF-8 input with LuaLaTeX or XeLaTeX. For text, choose a font % containing the input characters: % \begin{verbatim} % \documentclass{article} % \usepackage{fontspec} % \usepackage{unicodehat} % \begin{document} % Text: Ĥ. Mathematics: $Ĥ = Ê$. % \end{document} % \end{verbatim} % In mathematics, for example, \texttt{Ĥ} expands to \verb|\hat{H}|. % Outside mathematics the original Unicode character is retained. % The package uses \textsf{newunicodechar} and defines no package options. % % \section{Character mappings} % The following input characters map to hats over the corresponding % Latin letters, in the same order: % \begin{verbatim} % Input: Â Ê Î Ô Û Ĉ Ĝ Ĥ Ĵ Ŝ Ŵ Ŷ Ẑ % Base: A E I O U C G H J S W Y Z % Input: â ê î ô û ĉ ĝ ĥ ĵ ŝ ŵ ŷ ẑ % Base: a e i o u c g h j s w y z % \end{verbatim} % These 26 mappings cover all precomposed Unicode characters consisting of % a basic Latin letter (A--Z or a--z) with a single circumflex accent above: % 13 letters in both uppercase and lowercase. % % Only these single-code-point characters are remapped. Combining sequences, % such as \texttt{H} followed by U+0302 (COMBINING CIRCUMFLEX ACCENT), are % not supported, even though they can look identical to \texttt{Ĥ} (U+0124). % For combining sequences with LuaLaTeX, use % \href{https://ctan.org/pkg/luamathaccents}{\textsf{luamathaccents}}; % for example, it converts \texttt{x} followed by U+0302 to \verb|\hat{x}|, % without needing a precomposed Unicode character. It does not convert % precomposed characters such as \texttt{Ĥ} to math accents. % % \paragraph{Font coverage.} % The precomposed characters \texttt{Ẑ} (U+1E90) and \texttt{ẑ} (U+1E91) % are missing from some text fonts, including Latin Modern Mono. % In regular text, choose a font containing these glyphs; this documentation % uses DejaVu Sans Mono for the character mappings and code listings. % In mathematics, the package expands them to \verb|\hat{Z}| and % \verb|\hat{z}|, so these two Unicode glyphs are not needed in the font. % % \StopEventually{} % % \section{Implementation} % % \begin{macrocode} %<*package> \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{unicodehat} [2026/11/16 v1.0.0 Unicode circumflex letters in mathematics] \RequirePackage{newunicodechar} % \end{macrocode} % Declare an internal helper for the character mappings. % \begin{macrocode} \newcommand*\unicodehat@def[2] {\newunicodechar{#2}{\ifmmode\hat{#1}\else{#2}\fi}} % \end{macrocode} % Declare all 26 precomposed circumflex mappings. % \begin{macrocode} \unicodehat@def A Â \unicodehat@def E Ê \unicodehat@def I Î \unicodehat@def O Ô \unicodehat@def U Û \unicodehat@def C Ĉ \unicodehat@def G Ĝ \unicodehat@def H Ĥ \unicodehat@def J Ĵ \unicodehat@def S Ŝ \unicodehat@def W Ŵ \unicodehat@def Y Ŷ \unicodehat@def Z Ẑ \unicodehat@def a â \unicodehat@def e ê \unicodehat@def i î \unicodehat@def o ô \unicodehat@def u û \unicodehat@def c ĉ \unicodehat@def g ĝ \unicodehat@def h ĥ \unicodehat@def j ĵ \unicodehat@def s ŝ \unicodehat@def w ŵ \unicodehat@def y ŷ \unicodehat@def z ẑ \endinput % % \end{macrocode} % \Finale