[Tex/LaTex] The correct way to type tilde

tildeverbatim

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}

\hypersetup{colorlinks=true, urlcolor=blue}
\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 :/

Best Answer

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.

Related Question