0

I want to try to communicate what I want to achieve with the following code example. I would like to have one left- and right-command for this functionality, which compiles in reasonable time. I am happy with the aesthetics achieved by the routines below. I apologize if that question could be solved using other answers from the site. Thank you for taking a look at it!

\documentclass{amsart}
\usepackage{amsmath} 
\usepackage{stackengine}

\newcommand\constantoverleftarrow[1]{\stackengine{0pt}{$\smash{\mbox{\scriptsize\ensuremath{\overleftarrow{\normalsize\hphantom{D}\vphantom{#1}}}}}$}{$#1$}{O}{l}{F}{F}{L}}

\newcommand\constantoverrightarrow[1]{\stackengine{0pt}{$\smash{\mbox{\scriptsize\ensuremath{\overrightarrow{\normalsize\hphantom{D}\vphantom{#1}}}}}$}{$#1$}{O}{l}{F}{F}{L}}

\newcommand\constantfootoverleftarrow[1]{\stackengine{0pt}{$\smash{\mbox{\tiny\ensuremath{\overleftarrow{\footnotesize\hphantom{D}\vphantom{#1}}}}}$}{$#1$}{O}{l}{F}{F}{L}}

\newcommand\constantfootoverrightarrow[1]{\stackengine{0pt}{$\smash{\mbox{\tiny\ensuremath{\overrightarrow{\footnotesize\hphantom{D}\vphantom{#1}}}}}$}{$#1$}{O}{l}{F}{F}{L}}

\newcommand\constantunsmashedoverleftarrow[1]{\stackengine{0pt}{$\mbox{\scriptsize\ensuremath{\overleftarrow{\normalsize\hphantom{D}\vphantom{#1}}}}$}{$#1$}{O}{l}{F}{F}{L}}

\newcommand\constantunsmashedoverrightarrow[1]{\stackengine{0pt}{$\mbox{\scriptsize\ensuremath{\overrightarrow{\normalsize\hphantom{D}\vphantom{#1}}}}$}{$#1$}{O}{l}{F}{F}{L}}

\begin{document}

I write longer sentences which have inline math and wrap over several lines. It might happen that I speak about a derivative $\constantoverleftarrow{D_{x_1\cdots x_n}}$ and put it inside the text. It is important for me that the arrow of such a formula does not expand over the indices. I used the smashed version of my own arrow here because I do not want that the lines spread apart. 

Of course, it might as well happen that I speak about a derivative
\[
\constantunsmashedoverleftarrow{D_x}
\] 
which occurs in display math. Here, I use the unsmashed version of my own arrow because I want the spacing to be ordinary. This is important, in particular if I have display math with several lines or even boxes around the math from empheq package.\footnote{A derivative $\constantfootoverrightarrow{D_y}$ in a footnote needs to be smaller.} (It might also be important for deliminators. But there, I usually control the size myself and do not use the $\left(\right)$ version. This seems less important to me.)

The experts from \TeX Stackexchange might notice: Such a macro does not always work. Indeed, it will not adjust to subscripts for example, like $\int_{\constantoverrightarrow{D_z}}$. However, I do not need this. I don't have to worry about all the functionality but only about the one I really use.

I finally want to remark: My document may have around 200 to 300 arrows. And using the code above in the preamble takes a lot of time to compile.

\end{document}

Related, related, related.

  • I fixed a lot of typos in your code above. Now it compiles. – Sigur Aug 31 '19 at 15:19
  • You said that takes a lot of time to compile. Maybe because the errors I already fixed. Try again with the code above. – Sigur Aug 31 '19 at 15:21
  • Why don't use simply \int_{\overrightarrow{D}_z}? – Sigur Aug 31 '19 at 15:23
  • @Sigur The point is that the index $z$ gets shifted to the right. Concerning compiling, I thought it is maybe bad coding. – user66288 Aug 31 '19 at 15:42
  • Well, it is not clear what is the problem with z. It is subscript, so should be moved a little bit. Do you want to reduce the right spacing? – Sigur Aug 31 '19 at 15:44
0

I think this works for me by combining egreg's and Steven's solution. It compiles fast while the above in the question gets timeout. I smash it twice which I forgot in the question. It seems like things get not spread assymetrically at top and bottom now. It is probably not optimal but I can work with it.

\newcommand\constantoverrightarrow[1]{\colas#1\endcolas}
\def\colas#1#2\endcolas{\stackengine{0pt}{}{$\smash{\overrightsmallarrow{#1}}$}{O}{l}{F}{T}{L}%
  \smash{\phantom{#1}#2}}

\newcommand\constantoverleftarrow[1]{\cola#1\endcola}
\def\cola#1#2\endcola{\stackengine{0pt}{}{$\smash{\overleftsmallarrow{#1}}$}{O}{l}{F}{T}{L}%
  \smash{\phantom{#1}#2}}

\makeatletter
\newcommand{\overleftsmallarrow}{\mathpalette{\overarrowsmall@\leftarrowfill@}}
\newcommand{\overrightsmallarrow}{\mathpalette{\overarrowsmall@\rightarrowfill@}}
\newcommand{\overarrowsmall@}[3]{%
  \vbox{%
    \ialign{%
      ##\crcr
      #1{\smaller@style{#2}}\crcr
      \noalign{\nointerlineskip\vskip0.4pt}%
      $\m@th\hfil#2#3\hfil$\crcr
    }%
  }%
}
\def\smaller@style#1{%
  \ifx#1\displaystyle\scriptstyle\else
    \ifx#1\textstyle\scriptstyle\else
      \scriptscriptstyle
    \fi
  \fi
}
\makeatother

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.