重新审视 overleft/rightarrow 的旧问题以及我自己的方法

重新审视 overleft/rightarrow 的旧问题以及我自己的方法

我想尝试用以下代码示例来传达我想要实现的目标。我希望此功能有一个左命令和右命令,它可以在合理的时间内编译。我对以下例程所实现的美感感到满意。如果可以使用网站上的其他答案来解决该问题,我深表歉意。感谢您的关注!

\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}

有关的有关的有关的

答案1

我认为通过结合 egreg 和 Steven 的解决方案,这种方法对我来说很有效。它编译速度很快,而问题中的上述内容会超时。我把它砸了两次,我忘了在问题中。现在看起来事情在顶部和底部不再不对称地分布。这可能不是最佳选择,但我可以使用它。

\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

相关内容