[Tex/LaTex] Using \newcommand in an equation/in math modes

equationsmacros

I found the following command for increasing the space between an \underline and its corresponding text:

\newcommand{\ovF}[1]{
  $\overline{\raisebox{0pt}[\dimexpr\height+1mm\relax]{#1}}$
}

This command works well e.g. in

\ovF{a}

By trying to overline a term that needs a math environment it works as well, e.g.

\ovF{\varphi}

However I want to use my command in an equation, e.g.

\begin{equation}
  \ovF{a}
  \ovF{\varphi}
\end{equation}

Neither the first nor the second line works for me but I couldn't find any reason for this yet. I got the assumption that the predefined math mode of the equation brings me some issues. Therefore I tried to understand those issues by using this command without the equation in a math mode.

$\ovF{a}$
$\ovF{\varphi}$

Also none of them worked. For all of them I get the same Error message:

! Missing $ inserted.<inserted text>$

So my question is: What should I do/change to use my command in a math environment, especially in a equation? Did I make something wrong?

I am sorry if I made any mistakes. I am new to this board and its my first question.

Best Answer

Generally, a function should be targeted for either math or text mode. However, since you seem to want something that functions in all modes, I give it a spin, with a bit of overkill. It obeys math styles, etc.

\documentclass{article}
\usepackage{scalerel}
\newcommand{\ovF}[1]{\ensuremath{%
  \ThisStyle{\overline{\raisebox{0pt}[\dimexpr\height+1mm\relax]{$\SavedStyle#1$}}}}%
}
\parskip 1em
\begin{document}
\ovF{a}

\ovF{\varphi} {\LARGE\ovF{\varphi}}

\begin{equation}
  \ovF{a}
  \ovF{\varphi}
\end{equation}

$\ovF{a}$

$\ovF{\varphi} \scriptscriptstyle \ovF{\varphi} $

\end{document}

enter image description here

Related Question