[Tex/LaTex] Trying to use “\~” to generate tilde symbol in math mode


$$ = \sum_{e \in A} w(e)
   = \sum_{e \in A} w(e)+ \sum_{e \in \{(r,v)| v \in V(G)\}} w(e) 
   = w( \~{A} ) $$

I get the following error message:

Error: Please use \mathaccent for accents in math mode for the following code

I'm not sure what's wrong with it. I'm in math mode by using $$ $$, am I not?

Best Answer

The immediate problem is solved by replacing the text-mode instruction \~{A} with the math-mode directive \tilde{A}.

You may also want to make the equation both more compact and more readable by (a) introducing a line break in the material set below the third \sum symbol (via a \substack instruction) and (b) eliminating the whitespace that's otherwise inserted to the left and right of that summation symbol (via a \mathclap instruction).

enter image description here

Addendum: For the sake of completeness/reference, here's a list of common accents and how they should be produced in text and math mode, respectively. Note that the positions and, in the case of text-upright versus text-italic font shapes, even the shapes of the accents can differ between text and math modes. In math mode, in contrast, the shapes of the math-accent characters are the same regardless of whether \mathrm ("math roman") or \mathit ("math italics" -- the default) is in effect.

enter image description here

\usepackage{mathtools} % for "\mathclap" macro; loads "amsmath" package
   = \sum_{e \in A} w(e)
   = \sum_{e \in A} w(e) + 
     \sum_{\mathclap{\substack{e \in \{(r,v)\} \\ \text{s.t.}\, v \in V(G)}}} w(e) 
   = w(\tilde{A}) 

\newcolumntype{C}{>{$}c<{$}} % automatic-math version of "c" column type
\begin{tabular}{@{} l c c >{\itshape}c l C C @{}}
Accent name & \multicolumn{3}{c}{Text mode} 
            & \multicolumn{3}{c@{}}{Math mode} \\
\cmidrule(lr){2-4} \cmidrule(l){5-7}
            & how to & \multicolumn{2}{c}{result} 
            & how to & \multicolumn{2}{c@{}}{result} \\
acute             & \verb|\'| & \'A & \'A & \verb|\acute| & \acute{\mathrm{A}} & \acute{A} \\
grave             & \verb|\`| & \`A & \`A & \verb|\grave| & \grave{\mathrm{A}} & \grave{A} \\
circumflex        & \verb|\^| & \^A & \^A & \verb|\hat|   & \hat{\mathrm{A}}   & \hat{A}   \\
squiggle, tilde   & \verb|\~| & \~A & \~A & \verb|\tilde| & \tilde{\mathrm{A}} & \tilde{A} \\
macron, bar       & \verb|\=| & \=A & \=A & \verb|\bar|   & \bar{\mathrm{A}}   & \bar{A}   \\
dot accent        & \verb|\.| & \.A & \.A & \verb|\dot|   & \dot{\mathrm{A}}   & \dot{A}   \\
diereris, Umlaut  & \verb|\"| & \"A & \"A & \verb|\ddot|  & \ddot{\mathrm{A}}  & \ddot{A}  \\
breve             & \verb|\u| &\u{A}&\u{A}& \verb|\breve| & \breve{\mathrm{A}} & \breve{A} \\
caron, check, v-check&\verb|\v|&\v{A}&\v{A}&\verb|\check| & \check{\mathrm{A}} & \check{A} \\
ring              & \verb|\r| &\r{A}& \r{A}&\verb|\mathring|&\mathring{\mathrm{A}}& \mathring{A}\\