# The correct way to type tilde?

So, I know there are a lot of posts about this already, with answers like \textasciitilde, \texttildelow and $\sim$ and they all seam to work in their own way. But what I've found is that they look like tilde when typeset, but when you highlight the character, copy it and paste it into a terminal window, it's a completely different character.

I've found that \texttildelow is the only command that creates an "actual" tilde-character, when copied and pasted into a terminal. However, it is printed very low in the pdf when used, and it looks like something else.

I need help managing all these ways to type tilde. I want to type tilde in both verbatim text and in normal text mode. What I would like is for the characters to look like a normal tilde when typeset, and also be the "real" tilde when copied into the terminal window. This is to simplify the process of using the commands I write. I don't think a sample text is necessary in this particular post, but if needed I can edit that in.

\documentclass[11pt]{paper}
\usepackage{hyperref, xcolor, graphicx, textcomp}

\setlength\parindent{0pt}

\newenvironment{accs}
{\color{black}
\begin{tt}
\fontsize{11pt}{11pt}\selectfont}
{\end{tt}}

\title{Resequencing Analysis}

\begin{document}
\maketitle

~/glob/gatk

\begin{accs}
$mkdir ~/glob/gatk \end{accs}\\ \end{document}  I have now solved a part of the problem by using the environment \newenvironment{vtim} {\verbatim \fontsize{11pt}{11pt}\selectfont} {\endvarbatim}  instead, but the tilde character still looks weird in the .pdf as it is raised up... If I use the$\sim\$ it can't be copied into the terminal :/

-
A sample text is necessary. Look and copy&paste depends on the font and font encoding you are using. –  Ulrike Fischer Jul 3 at 8:34
Also it would show what packages you are using: where \texttildelow is defined for example –  David Carlisle Jul 3 at 8:37
I thought that the accsupp package, with something like \BeginAccSupp{ActualText={~}}\textasciitilde\EndAccSupp{} would work, but it does not: you can have two different symbols, one printed and one copy/pastable, but in that specific case it yield \protect\unhbox\voidb@x\penalty\@M\{}! –  Clément Jul 3 at 8:39
@UlrikeFischer Added the important parts from my text, as you can probably notice I am quite new to this. Any and all help is very much appreciated. –  Rikardny Jul 3 at 13:13
@DavidCarlisle So a more appropriate package can change the definition of '\texttildelow' to something that I would like? –  Rikardny Jul 3 at 13:14

You can use the accsupp package to set the text that is copied from the document separately from what the document displays.

For example, you could use \textasciitilde as your tilde in a command \actualtilde with

\documentclass{article}
\usepackage{accsupp}

\newcommand{\actualtilde}{\BeginAccSupp{method=hex,unicode,ActualText=007E}\textasciitilde\EndAccSupp{}}

\begin{document}
Here is my document text including a \actualtilde\ that copies correctly.
\end{document}


As for using this in a verbatim environment I am unsure, but if you put your code in a listings environment, this answer may be of assistance.

-
I like the idea of masking the text, that way the students can see the "right" tilde-sign, and also copy-paste it without getting some weird symbol in the terminal. Thanks, I'll look into it! –  Rikardny Jul 3 at 13:17

If you use \textasciitilde it will use a tilde character in ascii position if

\usepackage[T1]{fontenc}


is used. in the default OT1 encoding it uses a tilde accent over nothing as the fonts do not contain an ascii spacing tilde character (other than cmtt as used in verbatim)

The actual appearance depends on the font but in all cases it is a single character in position 126 so should cut and paste as such.

computer modern roman, computer modern tt and Times Roman

\documentclass{article}

\usepackage[T1]{fontenc}

\begin{document}

aaa\textasciitilde aaa

\texttt{aaa\textasciitilde aaa}

\fontfamily{ptm}\selectfont

aaa\textasciitilde aaa

\end{document}

-
remembering the classic paper “goto considered harmful”, we could perhaps publish something like “ot1 considered harmful”. i would try to concoct something for the faq, if i was still working on it, but... –  wasteofspace Jul 3 at 9:12
So using \usepackage[T1]{fontenc} should put the tilde sign in the middle? I can't seem to get it to work, it just makes the pdf-text look weird. –  Rikardny Jul 3 at 13:25
@Rikardny see updated answer –  David Carlisle Jul 3 at 13:48