TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am currently trying to write text over a squiggly arrow (\rightsquigarrow). For normal arrows, I use the extarrows package, which provides commands like \xlongrightarrow and \xLongrightarrow which dynamically stretch the arrow depending on the text length. However, the package does not provide commands for squiggly arrows and I was not able to find another one which does so.

share|improve this question
1  
up vote 5 down vote accepted

EDITED to provide 2 REVISED solutions, one with default symbol set and the other with imported glyphs from MnSymbol (not the whole glyph set).

This gives the gist of how you might do it. The key is finding a symbol that is periodic. I used the \sim character, but there might be better. Also, I used the \! symbol for backspacing, but there may be more precise ways of doing it (you'll note the overlap is not perfect in my example).

I created three commands, for the squiggle, the left squig end, and the right squig end. One can just repeat invocations of \squig to make the squiggle longer.

Or one can use \squigs with an argument to get the desired number of squiggles. Next step was to create the commands that allow text to go over the squiggle.

So the real commands you would in general use are \rsquigarrow and \lsquigarrow, each with two arguments: the text to go atop the squiggle, and the squiggle length.

REVISED SOLUTION (DEFAULT GLYPHS)

This revised solution uses math mode consistently and is compatible with amsmath.

\documentclass[12pt]{article}
%%%%% REMOVE THESE FROM A GENERAL DOCUMENT
\parindent 0pt
\parskip 1ex
\textwidth 2in
%%%%%
\usepackage{amssymb,amsmath,stackengine}
\stackMath
\usepackage{ifthen}

\newcommand{\squig}{{\scriptstyle\sim\mkern-3.9mu}}
\newcommand{\lsquigend}{{\scriptstyle\lhd\mkern-3mu}}
\newcommand{\rsquigend}{{\scriptstyle\rule{.1ex}{0ex}\rhd}}
\newcounter{sqindex}
\newcommand\squigs[1]{%
  \setcounter{sqindex}{0}%
  \whiledo {\value{sqindex}< #1}{\addtocounter{sqindex}{1}\squig}%
}
\newcommand\rsquigarrow[2]{%
  \mathbin{\stackon[2pt]{\squigs{#2}\rsquigend}{\scriptscriptstyle\text{#1\,}}}%
}
\newcommand\lsquigarrow[2]{%
  \mathbin{\stackon[2pt]{\lsquigend\squigs{#2}}{\scriptscriptstyle\text{\,#1}}}%
}
\begin{document}
Here are the commands to make periodic squiggles, with no text above
them:

$2H_2 + O_2 \mathbin{\squig\squig\squig\rsquigend} 2H_2O $\\
$2H_2 + O_2 \mathbin{\lsquigend\squig\squig\squig} 2H_2O $

I can automate a group of squiggles

$\squigs{7}$

Now I will create commands to place text over them

$2H_2 + O_2 \rsquigarrow{exothermic}{7} 2H_2O $\\
$2H_2 + O_2 \lsquigarrow{heat}{3} ~ 2H_2O $
\end{document}

enter image description here

REVISED SOLUTION (IMPORTING 3 MnSymbol GLYPHS)

\documentclass[12pt]{article}
% =============================================
%Import symbols from font MnSymbol without importing the whole package
% =============================================
\DeclareFontFamily{U} {MnSymbolC}{}

\DeclareFontShape{U}{MnSymbolC}{m}{n}{
  <-6> MnSymbolC5
  <6-7> MnSymbolC6
  <7-8> MnSymbolC7
  <8-9> MnSymbolC8
  <9-10> MnSymbolC9
  <10-12> MnSymbolC10
  <12-> MnSymbolC12}{}
\DeclareFontShape{U}{MnSymbolC}{b}{n}{
  <-6> MnSymbolC-Bold5
  <6-7> MnSymbolC-Bold6
  <7-8> MnSymbolC-Bold7
  <8-9> MnSymbolC-Bold8
  <9-10> MnSymbolC-Bold9
  <10-12> MnSymbolC-Bold10
  <12-> MnSymbolC-Bold12}{}

\DeclareSymbolFont{MnSyC} {U} {MnSymbolC}{m}{n}

\DeclareMathSymbol{\MNrhd}{\mathbin}{MnSyC}{76}
\DeclareMathSymbol{\MNlhd}{\mathbin}{MnSyC}{78}
% =============================================
\DeclareFontFamily{U} {MnSymbolD}{}

\DeclareFontShape{U}{MnSymbolD}{m}{n}{
  <-6> MnSymbolD5
  <6-7> MnSymbolD6
  <7-8> MnSymbolD7
  <8-9> MnSymbolD8
  <9-10> MnSymbolD9
  <10-12> MnSymbolD10
  <12-> MnSymbolD12}{}
\DeclareFontShape{U}{MnSymbolD}{b}{n}{
  <-6> MnSymbolD-Bold5
  <6-7> MnSymbolD-Bold6
  <7-8> MnSymbolD-Bold7
  <8-9> MnSymbolD-Bold8
  <9-10> MnSymbolD-Bold9
  <10-12> MnSymbolD-Bold10
  <12-> MnSymbolD-Bold12}{}

\DeclareSymbolFont{MnSyD} {U} {MnSymbolD}{m}{n}
\DeclareMathSymbol{\MNsim}{\mathbin}{MnSyD}{2}

% =============================================

%%%%% REMOVE THESE FROM A GENERAL DOCUMENT
\parindent 0pt
\parskip 1ex
\textwidth 2in
%%%%%
\usepackage{amssymb,amsmath,stackengine}
\stackMath
\usepackage{ifthen}

\newcommand{\squig}{{\MNsim\mkern-3.6mu}}
\newcommand{\lsquigend}{{\MNlhd\mkern-4.3mu}}
\newcommand{\rsquigend}{{\mkern-1.2mu\MNrhd}}
\newcounter{sqindex}
\newcommand\squigs[1]{%
  \setcounter{sqindex}{0}%
  \whiledo {\value{sqindex}< #1}{\addtocounter{sqindex}{1}\squig}%
}
\newcommand\rsquigarrow[2]{%
  \mathbin{\stackon[1pt]{\squigs{#2}\rsquigend}{\scriptscriptstyle\text{\!\!#1}}}%
}
\newcommand\lsquigarrow[2]{%
  \mathbin{\stackon[1pt]{\lsquigend\squigs{#2}}{\scriptscriptstyle\text{#1\!\!}}}%
}

\begin{document}
Here are the commands to make periodic squiggles, with no text above
them:

$2H_2 + O_2 \mathbin{\squig\squig\squig\rsquigend} 2H_2O $\\
$2H_2 + O_2 \mathbin{\lsquigend\squig\squig\squig} 2H_2O $

I can automate a group of squiggles

$\squigs{7}$

Now I will create commands to place text over them

$2H_2 + O_2 \rsquigarrow{exothermic}{10} 2H_2O $\\
$2H_2 + O_2 \lsquigarrow{heat}{5} ~ 2H_2O $
\end{document}

enter image description here

LONGTIME ORIGINAL SOLUTION

This solution is sub-optimal because it mixes text and math modes indiscriminately. It is also incompatible with amsmath, I learned (the contents of \box0 were getting scrogged by amsmath).

\documentclass[12pt]{article}
\parskip 1ex
\usepackage{amssymb}
\usepackage{ifthen}
\textwidth 2in
\begin{document}
Here are the commands to make periodic squiggles, with no text above
them:

\newcommand{\squig}{$\scriptsize$\sim$\normalsize$\!}
\newcommand{\lsquigend}{$\scriptsize$\lhd\!$\normalsize$}
\newcommand{\rsquigend}{$\scriptsize\rule{.1ex}{0ex}$\rhd$\normalsize$}
\noindent
$2H_2 + O_2 ~\squig\squig\squig\rsquigend~ 2H_2O $\    $2H_2 + O_2 ~\lsquigend\squig\squig\squig~ 2H_2O $

Now I will create commands to place text over them

\newcounter{index}

\newcommand\squigs[1]{%
  \setcounter{index}{0}%
  \whiledo {\value{index}< #1}
  {\addtocounter{index}{1}\squig}
}

\newcommand\rsquigarrow[2]{$
  \setbox0\hbox{$\squigs{#2}\rsquigend$}%
  \tiny$%
  \!\!\!\!\begin{array}{c}%
  \mathrm{#1}\\%
  \usebox0%
  \end{array}%
  $\normalsize$\!\!%
}

\newcommand\lsquigarrow[2]{$
  \setbox0\hbox{$\lsquigend\squigs{#2}$}%
  \tiny$%
  \!\!\!\!\begin{array}{c}%
  \mathrm{#1}\\%
  \usebox0%
  \end{array}%
  $\normalsize$\!\!%
}

\noindent
$2H_2 + O_2 \rsquigarrow{exothermic}{7} 2H_2O $\    $2H_2 + O_2 \lsquigarrow{heat}{3} ~ 2H_2O $

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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