6

Following on from this question, I'm totally stumped on getting LaTeX to give me a tilde when I'm in verbatim mode. It has to be a tilde because it's the type of a function!

sig symm : (Board, [(Int, Int)]) ~> Bool

Standard methods for displaying a tilde are printed verbatim, of course..

Any suggestions?

An edit to clarify: Typing a ~ in verbatim mode gives an accent above a blank space. I'm after a tilde as it appears at the beginning of this sentence.

Community
  • 1
  • 1
Sam
  • 67
  • 2
  • 2
  • 10

4 Answers4

5

If there are some characters that do not occur in your input, you can use fancyvrb and its commandchars option to insert TeX commands within verbatim text:

\documentclass{article}
\usepackage{fancyvrb}
\begin{document}
\newcommand{\mytilde}{$\sim$}
\begin{Verbatim}[commandchars=\\\{\}]
sig symm : (Board, [(Int, Int)]) \mytilde> Bool
\end{Verbatim}
\end{document}

See the documentation of fancyvrb for more.

Jouni K. Seppänen
  • 43,139
  • 5
  • 71
  • 100
2

If you are using listing command, you can set the tilde to be literal. Likt this.

\documentclass
\usepackage{listings}
\lstset{
    literate={~} {$\sim$}{1} % set tilde as a literal (no process)
}

\begin{document}

\begin{lstlisting}
~
\end{lstlisting}

\end{document}
NawaMan
  • 25,129
  • 10
  • 51
  • 77
2

Perhaps you should look at: LaTeX package to do syntax highlighting of code in various languages which has suggestions for typesetting code...


I assumed that listing would do it for you, but failing that alltt and fancyvrb are alternatives to verbatim. See this search on CTAN for other possibilities.

Community
  • 1
  • 1
dmckee --- ex-moderator kitten
  • 98,632
  • 24
  • 142
  • 234
  • That's an awful lot of effort just to get a tilde! And as far as I can see with experimenting and reading documentation, it still doesn't solve my problem. – Sam Mar 25 '09 at 16:19
  • alltt looked promising but still appears to give the accented tilde. I'll hunt though the options of both packages, cheers. – Sam Mar 25 '09 at 17:16
0
\begin{verbatim}
~
\end{verbatim}
klew
  • 14,837
  • 7
  • 47
  • 59