2

How can I get a left arrow as a math accent to go over single symbols and groups of symbols, in such a way that:

  • the left arrows over a single character and multiple characters have the same heaviness; and
  • the left arrow over a single character is not overly long?

Here is what I've tried so far:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{newtxtext,newtxmath}
\usepackage{accents}
\usepackage{extarrows}

\linespread{1.1} % just to display output here more clearly

\newcommand{\reverse}[1]{\accentset{\leftarrow}{#1}}
\newcommand{\xreverse}[1]{\accentset{\xlongleftarrow{}}{#1}}
\newcommand{\longreverse}[1]{\overleftarrow{#1}}

\begin{document}

Accent single character with left arrow:

\smallskip

$\reverse{\sigma}$ \quad Arrow too short, too light, too small?

$\longreverse{\sigma}$ \quad Arrow too long and heavy!

\medskip

Accent multiple characters with left arrow:

\smallskip

$\xreverse{\sigma \ast \tau}$ \quad Use \verb!\xreverse!: arrow definitely too short. 

$\longreverse{\sigma \ast \tau}$ \quad Use \verb!\longreverse!: arrow long enough, but perhaps too heavy?

\bigskip

Want to use  better arrows in the alternative to \dots
\[(\sigma \ast \tau)^{\leftarrow} \simeq \reverse{\tau} \ast \reverse{\sigma}
\]
\dots that instead puts the long left arrow over the whole group of 3 symbols:

\begin{itemize}

\item $\longreverse{\sigma \ast \tau} \simeq \reverse{\tau} \ast \reverse{\sigma}$ \quad Use \verb!\longreverse! on left, \verb!\reverse! on right.

\item $\longreverse{\sigma \ast \tau} \simeq \longreverse{\tau} \ast \longreverse{\sigma}$ \quad Use \verb!\longreverse! for all.

\end{itemize}

\end{document}

leftarrow accents

I'd strongly prefer a method that avoids using TikZ or other drawing methods. And I need a method that will be relatively robust when a different font family (e.g., lucidabr, mathtimepro2) is used insstead of newtx. also when unicode-math is used along with a math font requiring xelatex.

I am aware of Configurable and Extensible Accents (Arrows, Dots, Vectors) and the item Dashed left arrow over symbol that is referenced by the accepted answer to it.

Addendum: using halloween command \overscriptleftarrow

Following the comment by @GuM, I tried the \overscriptleftarrow command from the halloween package. This does seem to work with all the font families I've tried, no matter whether I'm using pdflatex or, together with unicode-math, xelatex. For example:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{fontspec}
%\setmainfont[Ligatures=TeX]{TeX Gyre Termes}
%\setmainfont[Ligatures=TeX,SmallCapsFont={Latin Modern Roman Caps}]{Latin Modern Roman}
\usepackage{unicode-math}
\setmathfont[Ligatures=TeX]{TeX Gyre Termes Math}
%\setmathfont[Ligatures=TeX]{Latin Modern Math}

\usepackage{halloweenmath}
\newcommand{\reverse}[1]{\overscriptleftarrow{#1}}

\begin{document}

$\reverse{\sigma \ast \tau} \eqsim \reverse{\tau} \ast \reverse{\sigma}$

\end{document}

Output:

\overscriptleftarrow from halloween.sty and unicode-math

murray
  • 7,944
  • This question seem to solicit primarily opinion-based answers... – Werner Sep 11 '19 at 22:11
  • @Werner: I've rephrased the question. The main point is to use same thickness left arrow accents when over multiple characters as over a single character, but without an overly long accent when over a single character. – murray Sep 11 '19 at 22:20
  • Have you tried \overscriptleftarrow from the halloweenmath package? – GuM Sep 11 '19 at 22:57
  • @GuM: Will halloweenmath coexist happily with unicode-math and such math fonts as TeX Gyre Termes Math and Latin Modern Math? – murray Sep 12 '19 at 01:07
  • halloweenmath does seem to work with every document text & math font I trow at it. I do hate to load in another package with so many definitions -- for "scary" symbols (witches, ghosts, broomsticks, etc.) drawn with pict2e -- irrelevant to ordinary math usage. – murray Sep 12 '19 at 14:11
  • Indeed, the halloweenmath package doesn’t help here, if you use unicode-math. Sorry, I overlooked the last lines of your question. Please note, however, that I posted just a comment, not an answer! (:-) As for the problem of loading a package with hundreds of definitions, but using only a couple of them… well, it’s something that one often does when using LaTeX! (;-) However, had the \overscriptleftarrow worked, it would have been easy to extract only the necessary definitions. – GuM Sep 12 '19 at 18:28
  • @GuM: halloween is working for me under XeLaTeX if I use, say, TeX Gyre Termes or Latin Modern. (See addendum to my original question.) – murray Sep 15 '19 at 14:17

1 Answers1

3

Here is a solution using the calc and adjustbox packages. You can adjust the thickness of the arrow as well as its height as described below.

enter image description here

First we define the arrow:

\newcommand{\newarrow}{\scalebox{.7}{$\leftarrow$}}

Adjusting the .7 will make the arrow lighter or heavier. Using 1 will give you the original weight of \leftarrow, and will increase the size of the arrowhead.

Next we clip off the body of the arrow using the \clipbox command from the adjustbox package. (Actually it's from the trimclip package which is part of adjustbox.) What remains is .3em of the arrow: mostly just the arrowhead.

After that we scale the arrow body so that the head and body together make up the width of the symbols beneath the arrow. (Actually we clip .1em from the right end because there's some white space there.)

After that we place the reassembled arrow over the symbols using raise and rlap keys from the adjustbox package. If you want to adjust the height of the arrow, you can replace raise=\myheight with raise=1.2\myheight, or any scaling factor.

Here is the macro for \newreverse:

\newcommand{\newreverse}[1]{\settoheight{\myheight}{\ensuremath{#1}}%
\adjustbox{raise=\myheight,rlap}{%
\clipbox*{0 0 {.3em} {1.5\height}}{$\newarrow$}%
\resizebox{\widthof{\ensuremath{#1}}-.3em}{\height}{\clipbox*{{.3em} 0 {\width-.1em} {1.1\height}}{$\newarrow$}}%
}%
#1}

Note that you must define \myheight using \newlength{\myheight}. For some reason, the \adjustbox command doesn't accept raise=\heightof{#1}.

Here is the full code:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{newtxtext,newtxmath}
\usepackage{calc} % for subtracting lengths
\usepackage{adjustbox} % \adjustbox, \clipbox, \scalebox

\newcommand{\newarrow}{\scalebox{.7}{$\leftarrow$}}
\newcommand{\newreverse}[1]{\settoheight{\myheight}{\ensuremath{#1}}%
   \adjustbox{raise=\myheight,rlap}{%
   \clipbox*{0 0 {.3em} {1.5\height}}{$\newarrow$}%
   \resizebox{\widthof{\ensuremath{#1}}-.3em}{\height}{\clipbox*{{.3em} 0 {\width-.1em} {1.1\height}}{$\newarrow$}}%
   }#1}

\newlength{\myheight}

\begin{document}

\begin{itemize}
\item $\newreverse{\sigma \ast \tau} \simeq \newreverse{\tau} \ast \newreverse{\sigma}$
\item $\newreverse{\mathit{abcdefghijklmnop}}$
\end{itemize}

\end{document}
Sandy G
  • 42,558
  • Perfect explanation, rigorous and precise. Very good. – Sebastiano Sep 13 '19 at 19:46
  • 2
    Thank you @Sebastiano. Your comments are always so kind. – Sandy G Sep 13 '19 at 21:34
  • :-) I'm said the truth :-):-). My best regards. – Sebastiano Sep 14 '19 at 11:54
  • This method still uses the accents package, whose use with unicode-math Ulrike Fischer has cautioned against (see https://tex.stackexchange.com/questions/507951/why-missing-number-for-blindmathpaper-if-use-accents-sty-blindtext-sty-with-x). In any case, the load order with accents is tricky. – murray Sep 15 '19 at 14:28
  • @murray, this method does not use accents. I left it in the code for comparison with OPs original attempts (which did use accents). I'll upload a new MWE to be more clear. – Sandy G Sep 15 '19 at 16:22
  • @SandyG: Sorry, I didn't read your answer carefully enough. But it does cause what seems to me odd height placement as in \reverse{g \ast f} \simeq \reverse{f} \ast \reverse{g}, where the left arrow over the f is considerably higher than the one over the g -- as does using \overscriptleftarrow from the halloweenmath package. On the other hand, the shorter length of the left arrow over a single symbol, such as \sigma, with your definition seems better than what \overscriptleftarrow gives. – murray Sep 16 '19 at 17:40
  • @murray, you're right. Different heights look odd. This happens, e.g., with \vec{a}\cdot\vec{b}. You can find solutions to this problem in this question and its answers. A quick fix is to use \reverse{\vphantom{f}g} for the last g. This will fake the height of the f. – Sandy G Sep 16 '19 at 19:07
  • @SandyG: neat! That fixes the height issue no matter whose over-arrows are being used -- yours (which I'm adopting) or those from halloweenmath. I hadn't known about \vphantom (but often use \phantom). – murray Sep 16 '19 at 20:11