4

Suppose I have an operation on a set X which I want to denote with something like $X^\prime$, $X^\bullet$, or $X^\circ$, except with a different symbol. I found out that some of the diacritics available in math mode (see here) make a decent candidate when used “standalone”, for instance as $X \: \tilde{}$ or $X \: \hat{}$. This might not be the intended use for these characters, but the result looks very nice IMHO (certainly much nicer than, say, $X^\sim$ or $X^\wedge$).

However, in doing so, I will inevitably run into problems. One of these is easy to solve: a bit of extra space should be inserted before the standalone diacritic to make it look nice (a small space like \: seems to do the trick). However, if the diacritic is preceded by a subscript, I would like it to behave like a superscript, so it starts above the subscript, not after it. This is illustrated by the following MWE:

\documentclass[margin=2mm]{standalone}
\usepackage{amsmath}

\newcommand{\myhat}{\ensuremath{\:\hat{}}}
\newcommand{\mytilde}{\ensuremath{\:\tilde{}}}
\newcommand{\mybreve}{\ensuremath{\:\breve{}}}
\newcommand{\mycheck}{\ensuremath{\:\check{}}}

\begin{document}
\renewcommand{\arraystretch}{1.3}
\begin{tabular}{|c|c|c|c|}
    \hline
    command & no subscript & short subscript &  long subscript \\
    \hline
    hat     & $X\myhat$    & $X_1\myhat$     &  $X_{\omega(k)}\myhat$   \\
    tilde   & $X\mytilde$  & $X_1\mytilde$   &  $X_{\omega(k)}\mytilde$ \\
    breve   & $X\mybreve$  & $X_1\mybreve$   &  $X_{\omega(k)}\mybreve$ \\
    check   & $X\mycheck$  & $X_1\mycheck$   &  $X_{\omega(k)}\mycheck$ \\
    \hline
\end{tabular}
\end{document}

math accents as standalone symbols

My question is this: how can I make these “standalone” diacritics behave more like superscripts, without having to resort to adding negative horizontal space manually for each occurrence? Alternatively, can identical symbols also be generated in a different way, so that they may be used simply as $X^\standalonetilde$, $X^\standalonehat$, $X^\standalonebreve$, and $X^\standalonecheck$?

1
  • As a side node, the converse (i.e. taking a general symbol and turning it into an accent) is covered by this question.
    – Josse
    Sep 12, 2018 at 22:23

1 Answer 1

6

Not very efficient, but it seems to work.

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand\makesymbolaccent[2]{%
  \expandafter\expandafter\expandafter\let
  \expandafter\expandafter\expandafter\@tempa\expandafter\@secondoftwo#2%
  \edef#1{{\mkern-1mu\noexpand\symbolaccent{\mathchar"\expandafter\@gobblethree\@tempa}}}%
}
\newcommand{\symbolaccent}[1]{\mathpalette\symbol@accent{#1}}
\newcommand{\symbol@accent}[2]{%
  \sbox\z@{$\m@th\demote@style{#1}#2$}%
  \sbox\tw@{$\m@th\demote@style{#1}{}^{\demote@style{#1}#2}$}%
  \raisebox{\dimexpr\ht\z@-\ht\tw@}[\height][0pt]{\copy\z@}%
}
\newcommand\demote@style[1]{%
  \ifx#1\scriptstyle\textstyle\else\scriptstyle\fi
}
\makeatother

\makesymbolaccent{\ehat}{\hat}
\makesymbolaccent{\etilde}{\tilde}
\makesymbolaccent{\ebreve}{\breve}
\makesymbolaccent{\echeck}{\check}

\begin{document}

\begin{tabular}{|c|c|c|c|}
    \hline
    command & no subscript & short subscript &  long subscript \\
    \hline
    hat     & $X^\ehat$    & $X_1^\ehat$     &  $X_{\omega(k)}^\ehat$   \\
    tilde   & $X^\etilde$  & $X_1^\etilde$   &  $X_{\omega(k)}^\etilde$ \\
    breve   & $X^\ebreve$  & $X_1^\ebreve$   &  $X_{\omega(k)}^\ebreve$ \\
    check   & $X^\echeck$  & $X_1^\echeck$   &  $X_{\omega(k)}^\echeck$ \\
    \hline
\end{tabular}

\end{document}

enter image description here

4
  • Thank you for your solution, and sorry for the late response. I am hesitant to accept this, on the one hand because I don't quite understand what's going on, and on the other hand because I'm not too happy with how this looks in other font sizes (e.g. \[ \bigcup_{x \in X^\ehat} S_x \]) (though it's not too bad). I'll look at this more closely some time in the (near) future.
    – Josse
    Apr 18, 2019 at 14:38
  • it seems that this code no longer works in newer versions of (La)TeX, but I don't understand what the problem is. (It's giving me a bunch of errors and not displaying the diacritics. Did the meaning of \@gobblethree change?) Would you be able to get it working again?
    – Josse
    Mar 29 at 14:59
  • 1
    @Josse In the meantime those commands have been made robust. Fixed.
    – egreg
    Mar 29 at 15:47
  • Great, thanks a lot for the fix and the explanation of what happened! I guess I still have some plain TeX to learn... 😅
    – Josse
    Apr 4 at 18:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .