10

I know that LaTeX has the \vec{} command to denote vectors with an arrow above them, but I was taught to denote vectors using a squiggly line beneath them. Is it possible to denote vectors like this in LaTeX too?

7
  • 3
    Feel free to add squiggly lines underneath if you wish, but I do remember my physics teacher telling us that squiggly lines underneath was the way they used to indicate "put this character in bold", back when they wrote up texts by hand that would be later typeset by others.
    – JonathanZ
    Mar 10, 2020 at 20:35
  • 5
    I have literally never seen this notation for vectors. I would therefore advise against doing this. Use either an over-arrow (expressive, maybe a bit cluttered, good for handwriting, LaTeX default) or bold text (clean, though perhaps not obvious-enough). These are, it turns out, also the two ISO-approved ways to denote vectors.
    – geometrian
    Mar 11, 2020 at 1:08
  • 1
    @JonathanZsupportsMonicaC Yep, that's an old-style way to indicate boldface (it was used in typescripts as well so when I made the cmpica font, the "bold" version includes the squiggly underline.
    – Don Hosek
    Mar 11, 2020 at 14:59
  • @BH2017: Unrelated with this question, but I have a simple solution to your question about Argand diagram, that you deleted, using pstricks, if you're interested.
    – Bernard
    Mar 15, 2020 at 15:15
  • @Bernard I am interested, I only deleted that question because it was attracting downvotes and I thought it would inevitably get closed eventually.
    – Josh Pinto
    Mar 15, 2020 at 15:39

5 Answers 5

15

You can put a \tilde under the symbol with \underaccent:

\documentclass{article}
\usepackage{accents}
\renewcommand{\vec}[1]{\underaccent{\tilde}{#1}}

\begin{document}
\[
   \vec{x} = \cdots 
\]
\end{document}

enter image description here

12

Here are two possibilities using TikZ, \mathpalette and \fontdimen in order to adapt the vertical shift to the current math font and style (i.e., \displaystyle, \textstyle, \scriptstyle or \scriptscriptstyle).

1.

enter image description here

2.

enter image description here

With the first code, the “squiggly line” is lower for symbols that have descenders. With the second code, the “squiggly line” is shifted by the same minimal amount from the baseline for all symbols (but this amount depends on the current math font and style), and more if what is being underlined has unusually low descenders (see when the whole ux vector is underlined in the screenshot).1

For people who also want the squiggly line above a math expression instead of below, I'll give a variant of the second code that provides two macros: one that puts the squiggly line above the given math expression, and the other below the math expression.

First code

\documentclass{article}
\usepackage{xparse}  % Not needed if the LaTeX format is at least 2020-10-01
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\makeatletter
% Command from egreg (https://tex.stackexchange.com/a/499972/73317)
\newcommand{\math@param}[3]{%
  \fontdimen#3
  \ifx#1\displaystyle\textfont#2
  \else\ifx#1\textstyle\textfont#2
  \else\ifx#1\scriptstyle\scriptfont#2
  \else\scriptscriptfont#2 \fi\fi\fi
}

\newdimen\@my@yshift
\NewDocumentCommand{\myvec}{m}{\mathord{\mathpalette\@myvec{#1}}}

\newcommand*{\@myvec}[2]{%
  \begin{tikzpicture}[baseline=(n.base)]
  \node (n) [inner sep=0]
    {\global\@my@yshift=-0.5\math@param{#1}{2}{5}%
     $\m@th #1#2$};
    \draw[decorate, decoration={snake, amplitude=0.3pt, segment length=2pt}]
      ([yshift=\@my@yshift]n.south west) -- ([yshift=\@my@yshift]n.south east);
  \end{tikzpicture}%
}
\makeatother

\begin{document}

$\alpha \myvec{x} + \beta \myvec{y} + \gamma \myvec{z} = \myvec{0}$

\bigskip
$u_{\myvec{x}} = v^{\myvec{y}}$\qquad
$\myvec{u_{\myvec{x}}} = \myvec{v^{\myvec{y}}}$

\end{document}

Second code

\documentclass{article}
\usepackage{xparse}  % Not needed if the LaTeX format is at least 2020-10-01
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\makeatletter
% Command from egreg (https://tex.stackexchange.com/a/499972/73317)
\newcommand{\math@param}[3]{%
  \fontdimen#3
  \ifx#1\displaystyle\textfont#2
  \else\ifx#1\textstyle\textfont#2
  \else\ifx#1\scriptstyle\scriptfont#2
  \else\scriptscriptfont#2 \fi\fi\fi
}

\newdimen\@my@yshift
\NewDocumentCommand{\myvec}{m}{\mathord{\mathpalette\@myvec{#1}}}

\newcommand*{\@myvec}[2]{%
  \begin{tikzpicture}[baseline=(n.base)]
    \node (n) [inner sep=0]
      {\global\@my@yshift=\math@param{#1}{2}{5}%
       \vrule width 0pt height 0pt depth 0.5\@my@yshift\relax
       $\m@th #1#2$};
    % Make sure the snake is always drawn with a little shift below the south
    % border of node n.
    \draw[decorate, decoration={snake, amplitude=0.3pt, segment length=2pt}]
      ([yshift=-0.3\@my@yshift]n.south west) --
      ([yshift=-0.3\@my@yshift]n.south east);
  \end{tikzpicture}%
}
\makeatother

\begin{document}

$\alpha \myvec{x} + \beta \myvec{y} + \gamma \myvec{z} = \myvec{0}$

\bigskip
$u_{\myvec{x}} = v^{\myvec{y}}$\qquad
$\myvec{u_{\myvec{x}}} = \myvec{v^{\myvec{y}}}$

\end{document}

Above or below

Here is a variant of the second code that provides two macros: one that puts the squiggly line above the given math expression, and the other below it:

\documentclass{article}
\usepackage{xparse}  % Not needed if the LaTeX format is at least 2020-10-01
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\makeatletter
% Command from egreg (https://tex.stackexchange.com/a/499972/73317)
\newcommand{\math@param}[3]{%
  \fontdimen#3
  \ifx#1\displaystyle\textfont#2
  \else\ifx#1\textstyle\textfont#2
  \else\ifx#1\scriptstyle\scriptfont#2
  \else\scriptscriptfont#2 \fi\fi\fi
}

\newdimen\@my@yshift
\NewDocumentCommand{\myvecBelow}{m}{\mathord{\mathpalette\@myvecBelow{#1}}}
\NewDocumentCommand{\myvecAbove}{m}{\mathord{\mathpalette\@myvecAbove{#1}}}

% Squiggly line below the math expression
\newcommand*{\@myvecBelow}[2]{%
  \begin{tikzpicture}[baseline=(n.base)]
    \node (n) [inner sep=0]
      {\global\@my@yshift=\math@param{#1}{2}{5}%
       \vrule width 0pt height 0pt depth 0.5\@my@yshift\relax
       $\m@th #1#2$};
    % Make sure the snake is always drawn with a little shift below the south
    % border of node n.
    \draw[decorate, decoration={snake, amplitude=0.3pt, segment length=2pt}]
      ([yshift=-0.3\@my@yshift]n.south west) --
      ([yshift=-0.3\@my@yshift]n.south east);
  \end{tikzpicture}%
}

% Squiggly line above the math expression
\newcommand*{\@myvecAbove}[2]{%
  \begin{tikzpicture}[baseline=(n.base)]
    \node (n) [inner sep=0]
      {\global\@my@yshift=\math@param{#1}{2}{5}%
       \vrule width 0pt height 1.2\@my@yshift depth 0pt\relax
       $\m@th #1#2$};
    % Make sure the snake is always drawn with a little shift above the north
    % border of node n.
    \draw[decorate, decoration={snake, amplitude=0.3pt, segment length=2pt}]
      ([yshift=0.3\@my@yshift]n.north west) --
      ([yshift=0.3\@my@yshift]n.north east);
  \end{tikzpicture}%
}
\makeatother

\newcommand{\testText}{%
  $\alpha \myvec{x} + \beta \myvec{y} + \gamma \myvec{z} = \myvec{0}$

  \bigskip
  $u_{\myvec{x}} = v^{\myvec{y}}$\qquad
  $\myvec{u_{\myvec{x}}} = \myvec{v^{\myvec{y}}}$%
}

\begin{document}

\begin{tabular}{ @{} p{0.3\linewidth} p{0.3\linewidth} @{}}
  \let\myvec=\myvecBelow \testText &
  \let\myvec=\myvecAbove \testText
\end{tabular}

\end{document}

enter image description here


Footnote

  1. This feature could be easily reverted using amsmath and $\m@th #1\smash[b]{#2}$ instead of $\m@th #1#2$ in the node text.
5
  • What did you mean in your footnote by "reverted"? That the squiggle can be made overline instead of underline?
    – Evan Aad
    Mar 21, 2021 at 10:46
  • 1
    Hmm, not really. I meant that in the second code, in case you don't want the squiggle to be pushed down when the argument of \myvec has unusually low descenders, you can apply the little change described in the footnote (which requires amsmath). Of course, if you do so, the squiggle may cross descenders from \myvec's argument.
    – frougon
    Mar 21, 2021 at 12:40
  • 1
    @EvanAad My latest edit of the answer added a piece of code that provides two macros \myvecAbove and \myvecBelow so that you can choose to have the squiggly line above the math expression or below, as you wish.
    – frougon
    Mar 21, 2021 at 13:26
  • Thank you very much. I suggest that you make your definitions robust as per Ulrike Fischer's comment to this post of mine.
    – Evan Aad
    Apr 6, 2021 at 15:17
  • @EvanAad Done in revision 10, thanks for the suggestion.
    – frougon
    Apr 6, 2021 at 15:39
6

I use the vector package

In the options, select wavy. I find it works very well.

\documentclass{article}
\usepackage[wavy]{vector}
\begin{document}
 \uvec{a} % gives a vector
\uuvec{a} % gives a unit vector
\end{document}
1
  • 2
    +1 nice, could you add some code?
    – DG'
    Mar 10, 2020 at 23:11
3

Just only to remember that exist also a "squiggly line" using a specific package that a very good user can be use in math-mode called \Amem. This package named protosem (here there is an example http://ctan.mirror.garr.it/mirrors/CTAN/fonts/archaic/protosem/tryprotosem.pdf).

My code, as required by the user, it has been created for a single vector, as in the image below using \usepackage{stackengine} of the user @Steven B. Segletes. You can se the use of the command \sqbar{...}.

enter image description here

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\usepackage{protosem}
\newcommand\afc{\mathord{\textproto{\Amem}}}
\usepackage{stackengine}
\usepackage{bm}

\newcommand\sqbar[1]{\stackunder[-1pt]{$#1$}{$\scriptstyle\afc$}}
\begin{document}
\[\sqbar{v}, \sqbar{\bm{v}}\]
\end{document}
1

I used the undertilde package for my dissertation way back when, but there was a small bug in it that gave inconsistent spacing between equation and align environments.

This question has a fix for that bug if you use that.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .