# 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?

• Welcome to TeX.SE! – Mico Dec 7 '15 at 10:59
• Are you using Plain TeX or LaTeX? – egreg Dec 7 '15 at 12:59

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).

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.

\documentclass{article}
\usepackage{mathtools} % for "\mathclap" macro; loads "amsmath" package
\begin{document}
$= \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})$
\end{document}


\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{booktabs,array,lmodern}
\newcolumntype{C}{>{$}c<{$}} % automatic-math version of "c" column type
\begin{document}
\begin{tabular}{@{} l c c >{\itshape}c l C C @{}}
\toprule
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} \\
\midrule
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}\\
\bottomrule
\end{tabular}
\end{document}

• Thank you for the answer. It's very helpful. May I ask a separate question about Tex code you give for the table? What does @{} do? How do you align "Math Mode" with second "How to"? – Christin Sep 15 '16 at 23:07
• @Christin - The @{} directives serve to suppress the vertical whitespace (in the amount of \tabcolsep) that would otherwise be inserted at the left-hand and right-hand edges of the tabular environment. To left-align the "Math mode" header with the right-hand "how to" header, change \multicolumn{2}{c@{}}{Math mode} to \multicolumn{2}{l@{}}{Math mode}. – Mico Sep 16 '16 at 0:33

Text accents and math accents have different syntax in LaTeX: to get Ã, you would use \~{A} in textmode, but \tilde A or \widetilde A (the latter for a wider version) in mathmode.

Here is a table showing how to get different kinds of accents in textmode and mathmode.

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

• While you're at it, you should also replace | with \mid. The spacing around the two symbols is quite different. – Mico Dec 7 '15 at 6:16
• Or use a better construction for set syntax. \mid is not the proper symbol to use in general as it cannot be scaled (when needed). But useful as a one of. – daleif Dec 7 '15 at 6:26
• @daleif: a bar in the middle is the way I generally denote set syntax in writing, and I try to keep that notation in LaTeX. What would I use to make it scale when needed? – Arun Debray Dec 7 '15 at 16:55
• These days I tend to use this construction: tex.stackexchange.com/a/150516/3929, the idea behind it is (1) if I choose to use a bar syntax, I'd like it to be scalable along with the braces. (2) the spacing should be fully configurable from the preamble, not something that is manually inserted each time. (3) the input syntax should not be dependent on the choice for "given" symbol (here a bar), the syntax should make sense no matter the output symbol. (4) I want to get the scaller macros out of the way. In this construction "*" means autoscalling, and [\big]  us manually scaled. – daleif Dec 7 '15 at 18:39

I solved the issue by replacing \~{A} with \tilde{A}.

• Your answer has already been provided by Mico, hasn't it? – Stefan Pinnow Jul 12 '16 at 10:13

Just use the package lmodern.

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{verbatim}

\usepackage{lmodern}

\begin{document}

$$y = w( \~{A} )$$

You can also disregard the use of \verb=\~{A}= and use Ã directly, like the example below:

$$y = w( Ã )$$

\end{document}


• You get LaTeX Warning: Command \~ invalid in math mode and moreover the A is not in math italic. Is it so difficult to use \tilde{A}, which is the proper markup? – egreg Apr 4 '19 at 20:30
• Yes, Kurt, you're right. I didn't see that before posting here. At Mico's answer, however, the usage of lmodern` package is not explicit from the beginning. Thank you for the welcome. – Roberto de Freitas Cabral Apr 6 '19 at 1:50