5

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.

8
  • 4
    get rid of the $ signs in the \ovF definition (then it will work exclusively in math mode). If you, instead, want it to work in both math and non math modes, replace the $...$ instead with \ensuremath{...}. Oct 13, 2016 at 16:00
  • Wow, that was easy.. thank you :) However it doesn't work for \ovF{\varphi}. How can I handle this issue?
    – Peter Wita
    Oct 13, 2016 at 16:02
  • @PeterWita: One would assume you're only using this in math mode, and therefore should use $#1$ rather than #1.
    – Werner
    Oct 13, 2016 at 16:05
  • @Werner: Thank you for your answer. This worked well for me! :)
    – Peter Wita
    Oct 13, 2016 at 16:06
  • That is because the \varphi (corresponding to #1, shows up inside a \raisebox, the contents of which are isolated from the surrounding environment by the box. Thus, as it stands, #1 is always set in text mode. Oct 13, 2016 at 16:07

1 Answer 1

7

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

1
  • Thank you for this detailed answer. I understand all of it :)
    – Peter Wita
    Oct 13, 2016 at 16:22

You must log in to answer this question.

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