# Why is tilde not available out of the box in TeX?

Today I need to type ~ in my document, but apparently it does not get rendered properly. I just got a blank space. I searched on the web and I found the same problem here. However, its solutions show me that tilde (~) seems to be a special crazy character that is not available out of the box in TeX world. Adjusting the vertical alignment of tilde seems to be one of the craziest ones.

Considering ~ is a character that is available on the normal keyboard, it should be available out of the box. But it is apparently not. I am wondering why it is not available. What is the reason?

# Edit

I need a simple macro that can render ~ as we can see in this sentence. This simple ~ should be available without any crazy adjustment. I don't understand why vertical adjustment is needed for ~ but not for other characters like a, b, c, d, e, f, ..., z, 1, 2, ..., 0?

Put simply, why is the character ~ not available without crazy vertical tweaking? ~ is just like other characters on the keyboard, right?

• Because you need special crazy characters for special typesetting needs. Just like you can't typeset an underscore out of the box, or a backslash. They are reserved. – Johannes_B Jul 25 '16 at 6:28
• % is also available easily but is a command as ~ – Romain Picot Jul 25 '16 at 6:30
• @SingleFighter: The command is there: $\sim$ as gilu provided in his answer – Christian Hupfer Jul 25 '16 at 6:38
• Why is the tilde so high? TL;DR: because TeX's policy is that the terribad defaults fonts from the 80s should not be fixed for "backward compatibility". – Federico Poloni Jul 26 '16 at 20:52
• This is a perfectly reasonable question phrased perfectly obnoxiously. Seriously, if you want people's help, don't tell them that everything they do is "crazy". – David Richerby Jul 27 '16 at 10:02

The command you are looking for is \textasciitilde (looks better with

\usepackage[T1]{fontenc}


than the default OT1 encoding, which doesn't include a tilde so uses the accent over an empty base)

But the basic premise of your question seems flawed, all programming languages use some of the "easily accessible" keyboard characters as control constructs. ~ makes a non breakable space so doesn't directly make a ~ just as \ and { and } are used for specific syntax constructs for Tex and do not directly typeset the corresponding character.

• My premise is not about accessibility, but why is ~ not available but a, etc available without vertical adjustment. – Artificial Stupidity Jul 25 '16 at 7:10
• @SingleFighter if you use T1 encoding as suggested here you should not need any vertical adjustment (you never showed what code you were using so hard to guess what you mean) – David Carlisle Jul 25 '16 at 7:14
• @DavidCarlisle: with cm (and T1) the tilde is rather high, with lmodern it is better. – Ulrike Fischer Jul 25 '16 at 7:18
• @SingleFighter and again, as noted above if you use the classic TeX OT1 encoding the fonts do not include a ~ so \textasciitilde is defined in that case to do \~{} which is a bit high but there is no reason to be using OT1 encoding these days (since about 1990) – David Carlisle Jul 25 '16 at 7:18
• @UlrikeFischer (as you know) for any character in any font you could comment on the artistic design of the glyph, but that seems to be a rather different issue than accessing the character in general, as phrased in the question here. – David Carlisle Jul 25 '16 at 7:20

You seem to ask two questions: Why doesn't the tilde print a tilde? and Why is the tilde in the default font placed so high?

The first question is answered in the TeX book:

Plain TeX also reserves the six symbols \ { } ^ _ ~, but you probably don't mind losing these, since they don't appear in normal copy.

So Knuth decided to use the tilde for a tie, a non-breaking space, as he thought that people wouldn't need a tilde symbol — quite rightly in my opinion: I can't remember when I last had to type a tilde, but I use non-breaking spaces almost every day.

The second question is why the tilde is so high in the default font. Here one can only speculate. In TeX the tilde is used as a tie and as an accent command, so I guess that Knuth designed it to reflect these functions. In the code examples of the TeX book the tilde looks, to my taste, quite good:

But sadly this means that if you want a tilde that is not so high you either has to tweak it with, for example, a \raisebox, or switch to some other font like lmodern:

Ulrike asks why the tilde is so high in the default font. The answer, probably, is that that's where a tilde goes. Remember that a tilde is an accent that goes over a letter, as the "n" in Spanish "señor".

The lower symbol "~" being discussed in this thread is properly known a swung dash.

• Hi there! Welcome to the site! This is a site that's a little strange, because it's a Q & A site, rather than a forum or bulletin board. For example, though we may occasionally use the word thread, we don't really have threads. The bit at the top is a question. If all is going well, this space down here is for answers only, which in any case are only ordered chronologically by choice. We don't have a back and forth down here. Instead, any comments should go ... in the comments! You need a little reputation to be able to comment on other people's posts, but that's really where a comment belongs – Au101 Jul 25 '16 at 8:56
• Anyway, I think this is, for the most part, true only in a very formal, nit-picking sense, most people use the word 'tilde' quite freely to refer to the ~. However if you rephrase this from a comment into an answer, and maybe add a reference, I actually think you're on to the right answer here – Au101 Jul 25 '16 at 8:58
• this is a valid answer I think, it says the OP made the wrongful assumption that a tilde should be lower. I.e. the question is based on a flawed premise, OP might be looking for a different character that is visually similar. – jiggunjer Jul 25 '16 at 12:49
• But this answer just turns the question around: why doesn't all the other software render tilde high? – jiggunjer Jul 25 '16 at 12:59
• Can someone please explain why this isn't considered an answer. – jiggunjer Jul 26 '16 at 0:51

I’m going to go back in time a bit to answer this question:1

why is the character ~ not available without crazy vertical tweaking? ~ is just like other characters on the keyboard, right?

The answer is — no. The tilde is not like other characters on the keyboard. And the reason for this is that the tilde doesn’t “exist” in conventional typography. To understand this, we need a bit of history, and luckily Wikipedia obliges.

Briefly, while the tilde character has been a staple of typewriting since the middle ages, it was always used as a combining character, rarely on its own. Its meaning also changes through the ages, and in the early 20th century the only real uses of the tilde seem to have been:

1. As a combining character in Spanish (ñ) and other languages (e.g. Portuguese ã, õ).
2. In mathematics, to denote “approximately”.

But a sentence such as the one you apparently want to typeset (“~ nari ~ nari”) has no conventional meaning (case in point, not many people here seem to know what the tilde denotes here); it’s a made-up character, same as the ones in a CollegeHumour post (this isn’t a problem, of course; it just means that TeX didn’t anticipate this usage).

So there we have it: the tilde, as a separate character, doesn’t occur in conventional typesetting so there’s no reason to provide it. Consequently, Knuth opted to use the available keyboard key for something else (protected space).

… Which leads us to the question: why is the tilde key on the keyboard at all? And the answer, once again, is given by Wikipedia:

On mechanical typewriters, Spanish keyboards … had a dead key, which contained the acute accent (´), used over any vowel, and the dieresis (¨), used only over u. It was a simple matter to create a dead key for a Portuguese keyboard (created later than the Spanish one) … and so the ~ was born as a typographical character, which did not exist previously as a type or hot-lead printing character.

— On mechanical typewriters, the tilde was added purely as a combining character. When computer keyboards came along, they took over the typewriter layout and that’s why we’re settled with the tilde. In time, people found other uses for this character (especially in computer programming and as a character in paths/URLs). But yet, these were special uses and there was never a need for TeX to support this out of the box. Rather, you can use the various packages (e.g. url) to typeset e.g. paths correctly. Similarly, when using the tilde in the context of mathematics, you can simply use the math-mode command \sim.

But in normal text mode, typesetting a tilde becomes a challenge because different types of fonts handle the character differently (and using $$\sim$$ usually looks ugly). A comprehensive overview of different ways to typeset the character are provided in a separate question.

In a nutshell, modern (OTF/TTF) fonts contain the expected glyph for tilde, so it can be accessed via \char~. Better yet, \textasciitilde produces the same character and will also work on other font encodings. Still other fonts may require more elaborate workarounds, which are provided by commands such as \texttildelow.

1 Other people have already answered this in parts but I’m missing a complete overview.

• Saying "it's a made-up character" is going a bit far; I think what's really intended here is the Javapanese wave dash. – hobbs Jul 26 '16 at 23:42
• Perhaps worth adding the tilde isn't unique, US keyboards also have other spacing-character versions of diacritics. E.g. accent grave/acute and diaeresis ( ´ ¨) which are also rendered high. I don't know why but the tilde was the exception in older monospaced fonts, and now modern (serif/sans serif) fonts also render the tilde lower. Perhaps because of its use as the tilde operator (which is stricly speaking another character in Unicode). – jiggunjer Jul 27 '16 at 3:33
• If the font encoding being used has the character in position ~ then \textaciitilde will produce that and is the preferred form even though \char~ (or its latex syntax version \symbol{~}) do work of course. – David Carlisle Jul 27 '16 at 6:52
• @DavidCarlisle why is \textasciitilde preferable over \char or \symbol? – jiggunjer Jul 27 '16 at 8:57
• which has the same answers as this one, tex.stackexchange.com/a/2883/1090 being nearest to the orthodox answer. in OT1 the fonts don't have ~ in the ascii slot so you get \~{} in everything else \textasciitilde gives you whatever the font designer put in slot 126 which you may find high in T1 encoded cm, but that's a design choice obviously you could mess with raisebox and fudge it, or simpler use a different font such as latin modern, or just accept the design, but textasciitilde works in all the cases mentioned in the referenced question, for a suitable definition of "work" – David Carlisle Jul 27 '16 at 11:36

EDITED to provide several versions of "auto"-tilde.

Here, I show with the macros \newtildeON[] and \newtildeOFF, how one can temporarily change the definition of ~ from a hard space to a redefinition of your choice. The MWE shows the default redefinition as a lowered version of the ttfamily character 126, though I also show variants on how to use the \sim or \~ instead.

\documentclass{article}
\let\svtilde~
\newcommand\newtildeA{\raisebox{-.7ex}{\ttfamily\char126}}
\newcommand\newtildeB{$\sim$}% ALTERNATE REDEFINITION
\newcommand\newtildeC{\raisebox{-.8ex}{\~{}}}% ALTERNATE REDEFINITION
\newcommand\newtildeON[1][A]{\def~{\csname newtilde#1\endcsname}}
\newcommand\newtildeOFF{\let~\svtilde}
\begin{document}
\newtildeON
T~i~l~d~e\par
\newtildeOFF
T~i~l~d~e\par
\newtildeON[B]
T~i~l~d~e\par
\newtildeOFF
T~i~l~d~e\par
\newtildeON[C]
T~i~l~d~e\par
\newtildeOFF
T~i~l~d~e\par
\end{document}


• If you're going to redefine it, why not use the rm font \~{} or \textasciitilde instead of the tt font version... – jiggunjer Jul 27 '16 at 2:52
• @jiggunjer Certainly, one can redefine it in whatever way suits best. Your suggestions are certainly good options. – Steven B. Segletes Jul 27 '16 at 3:11
• Yes but is there a specific reason you chose the tt family? Would be interesting to compare the results. – jiggunjer Jul 27 '16 at 8:19
• @jiggunjer I guess I think of tilde as intrinsically ttfamily (though of course it is not). I have edited my answer to reflect your suggestions. – Steven B. Segletes Jul 27 '16 at 10:05
• I think that stems from OT1 tt fonts traditionally having the tilde for char126, compared to non-tt fonts which have the spaced tilde (a.k.a. small tilde). T1 fonts have both. +1 for the good example! – jiggunjer Jul 28 '16 at 0:19

The tilde is a protected space. Use it to avoid word wraps. Example; don't wrap this: US$~200. To print a tilde, I use this: $\sim$. • I'm sorry, but $\sim$ is not how you print tilde in text mode. \sim is a mathematical relation symbol and does not necessarily have the same shape as the tilde in text mode. This is crucial if you use different text and math fonts. Please improve your answer. – Henri Menke Jul 25 '16 at 6:44 • How special is ~ from TeX experts' point of view until they don't provide us the simple ~ that works like other characters available on the keyboard. It is what I don't understand. Is it about font? – Artificial Stupidity Jul 25 '16 at 6:50 • I want to type "~ nari ~ nari" as you can see in this sentence. No more than this. – Artificial Stupidity Jul 25 '16 at 7:01 • @HenriMenke the default OT1 fonts don't have a tilde other than the tt font or the accent command so classically this answer is OK, and not really deserving a downvote. If you use T1 encoding then the text fonts do have a ~ character though. – David Carlisle Jul 25 '16 at 7:12 • @jiggunjer I don't disbelieve that you did but I still would be very surprised if xetex/luatex accounted for more than say 5% of tex usage generally. – David Carlisle Jul 26 '16 at 6:04 I'll add my 2¢. First, let's establish what you mean with typesetting a tilde. Unicode defines several tildes: 1. Tilde (007E) 2. Tilde operator (223C) 3. Combining tilde (0303) 4. Spaced tilde (02DC) (decomposes into space + combining version) A similar character called the swung dash may be substituted by the tilde, similar to how apostrophes are substituted by quotation marks. Based on OP's comment he wants a wave dash (301C), a form of japanese punctuation similar to our dash. A wavedash looks like a longer mirrored tilde and isn't really related semantically. But in case you want a tilde read on. When you type the ~ key on a US keyboard you're inserting the 007E character (Tilde). This is also what \textasciitilde should insert. In TeX, \~ is not an escaped tilde, but a control character for the diacritic function of tilde, so \~{} would be the equivalent of a spaced tilde (02DC)--which no US-keyboard supports. In contrast, OT1 fonts don't cover ASCII (read: US-keyboards) completely, e.g. they define 02DC, but not 007E, causing a glyph substitution similar to what happens with the < > | characters, albeit a less obvious one. If you use a tt font or a T1 encoded font there is a defined glyph for 007E, but how it is implemented depends on the font--there may not be much difference with 02DC! Historically, tildes were only used as diacritics or math operators, as such the Tilde character 007E is somewhat undefined. As a font designer, what glyph should you give it if there is no known usage? Some fonts chose the 'spaced diacritic' version, others (especially monospace fonts) preferred the 'math operator' version--the latter also having value as a swungdash. The only other pure diacritic on keyboards was the accent grave--unlike tilde it is not ambiguous--which also got a spaced diacritic glyph (i.e. high rendering) in practically all fonts. It is hard to say which implementation of 007E is 'correct', but the tilde key is used as a deadkey in US-international layouts to input the diacritic characters, similar to how other diacritic deadkeys are used. Using a space with a diacritic deadkey produces the spaced diacritic, e.g. the accent grave: . Since it seems analogous to the backtick (accent grave), the tilde \textasciitilde should exist in the spaced diacritic version. But then it is not clear why the 02DC version was defined, as it seems redundant (by comparison there is no secondary 'spaced accent grave' character in Unicode). Nowadays the math version is more dominant and people tend to use it in irregular ways. So LaTeX does have a tilde out-of-the-box, its appearance just varies more on a per font basis! You may expect a lower version because that is common in monospace fonts, which in turn tend to be used more in programming and math. This is just conjecture: using the semantically ambiguous 007E tilde had advantages for the size-constrained ASCII developers: they could cram 3 things into one character, a diacritic, a math operator and a swungdash. In contrast the pure diacritic character "grave accent" was rather useless besides its use as a diacritic, and even then the spaced diacritic glyph itself had little value, the correct encoding being more important for rendering. @Ulrike Fischer and @gilu answered the question as to how you might add a tilde in your text. If you are looking for a short way of adding it ($\sim$ or \textasciitilde are too long) you could define something like this in your preamble \newcommand{\myveryshortcommandforatilde}{$\sim\$}


also, This.