latex3 / mathtools

Mathematical tools to use with amsmath
LaTeX Project Public License v1.3c
55 stars 6 forks source link

\xLongrightarrow #51

Closed quarkQuark closed 8 months ago

quarkQuark commented 1 year ago

This package does not provide an extensible variant for \Longrightarrow. This would be very useful to have.

muzimuzhi commented 1 year ago

Compared to \xRightarrow/\xLeftarrow, what's your expected effect of \xLongrightarrow / \xLongleftarrow, longer initial arrow length or larger left- and right- padding?

quarkQuark commented 1 year ago

I would expect it to be the same as the difference between \xrightarrow and \xlongrightarrow (#12), so that for short arguments it is the same length as \Longrightarrow rather than \Rightarrow (etc for the left variant).

It looks like the code for #12 is quite short, so I hope this wouldn't be too hard to implement. But I have no personal experience with low-level TeX functions.

muzimuzhi commented 1 year ago

This seems to do the work:

\documentclass{article}
\usepackage{mathtools}
\usepackage{color}

\MHInternalSyntaxOn
% imitate https://github.com/latex3/mathtools/commit/cb0750aa3741b00421079e4ceb36bfa32088fdd4
\def\MT_Longrightarrow_fill:{%
  \arrowfill@\Relbar\Relbar\Longrightarrow}
\def\MT_Longleftarrow_fill:{%
  \arrowfill@\Longleftarrow\Relbar\Relbar}

\providecommand*\xLongrightarrow[2][]{%
  \ext@arrow 0359\MT_Longrightarrow_fill:{#1}{#2}}
\providecommand*\xLongleftarrow[2][]{%
  \ext@arrow 3095\MT_Longleftarrow_fill:{#1}{#2}}
\MHInternalSyntaxOff

% check the natural width matches with the non-extendable ones in \normalsize
\def\markerU{\smash{\llap{\textcolor{red}{%
  \rule[-.25\baselineskip]{.4pt}{.75\baselineskip}}}}}
\def\markerL{\smash{\llap{\textcolor{blue}{%
  \rule{.4pt}{.75\baselineskip}}}}}

\begin{document}
\begin{align*}
  \text{normal}     & &&
    a \leftarrow     b\markerU &&  a \longleftarrow     b\markerU &&
    a \Leftarrow     b\markerU &&  a \Longleftarrow     b\markerU \\
  \text{extendable} & &&
    a \xleftarrow{}  b\markerL &&  a \xlongleftarrow{}  b\markerL &&
    a \xLeftarrow{}  b\markerL &&  a \xLongleftarrow{}  b\markerL \\
  %
  \text{normal}     & &&
    a \rightarrow    b\markerU &&  a \longrightarrow    b\markerU &&
    a \Rightarrow    b\markerU &&  a \Longrightarrow    b\markerU \\
  \text{extendable} & &&
    a \xrightarrow{} b\markerL &&  a \xlongrightarrow{} b\markerL &&
    a \xRightarrow{} b\markerL &&  a \xLongrightarrow{} b\markerL \\
\end{align*}
\end{document}

image image