tags:

views:

2452

answers:

5

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.

+2  A: 

Perhaps you should look at: http://stackoverflow.com/questions/300521/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.

dmckee
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.
aradnuk
ooh, alltt looks cool
Noah
alltt looked promising but still appears to give the accented tilde. I'll hunt though the options of both packages, cheers.
aradnuk
+1  A: 
\begin{verbatim}
~
\end{verbatim}
klew
LOL. I just assume that aradnuk had alread tried and failed! +1
dmckee
A single tilde places an accent over an invisible letter, if you will, so it's up high rather than in the centre of the line.
aradnuk
@aradnuk: You should probably edit the question to reflect your desire to have a "full-sized" tilde centered vertically...
dmckee
@aradnuk: no, it places tilde in the centre of the line. I tried many combinations and I get always tilde in the center of line.
klew
maybe this depends on the encoding of the input file? just a guess
Kim
+3  A: 

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
That's exactly what I needed. Thanks a lot!
aradnuk
A: 

See http://xianblog.wordpress.com/2009/10/27/verbatim-code/ for a resolution that shares a lot with the solutions above. alltt is what I ended up using in my book even though listing seems to be more advanced and more customisable.

Xi' an
A: 

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