title: Perl in an .Rnw file: the 'tilde' character
body: <p>I'd like to write a report that contains both R code and perl, so to test things out, I added the following snippet (borrowed from <a href="https://github.com/yihui/knitr-examples/blob/master/028-engine-perl.Rmd" rel="nofollow">028-engine-perl.Rmd</a>) to the end of the file <a href="https://github.com/yihui/knitr-examples/blob/master/002-minimal.Rnw" rel="nofollow">002-minimal.Rnw</a> (I called the resulting file Minimal.Rnw):</p>
  
  <pre><code>&lt;&lt;CheckPerl&gt;&gt;=
  Sys.which('perl')
  @
  
  &lt;&lt;TestPerl, engine='perl'&gt;&gt;=
  $test = "jello world";
  $test =~ s/j/h/;
  print $test
  @
  </code></pre>
  
  <p>When I knit() the file (in emacs, using M-n s), Minimal.tex is produced, and the result of the substitution is correct, e.g., </p>
  
  <pre><code>...
  \begin{verbatim}
  ## hello world
  \end{verbatim}
  ...
  </code></pre>
  
  <p>However, when I try to produce the .pdf file, I get the following error message:</p>
  
  <pre><code>...
  ./Minimal.tex:108: Missing $ inserted.
  &lt;inserted text&gt; 
                  $
  l.108 ...\hlkwb{\$test\ }\hlstd{}\hlopt{=$\sim$\ }
                                                    \hlstd{}\hlkwc{s/j/h/}\hls...
  
  ? 
  ./Minimal.tex:108: Emergency stop.
  ...
  </code></pre>
  
  <p>The statement in l.108 (and others) are within the <code>alltt</code> environment, but according to the documentation for <code>alltt</code>, the <code>$</code> symbol just produces a dollar sign, and is not used to denote mathmode. So, if I manually replace <code>$\sim$</code> by <code>\(\sim\)</code>, I get a .tex file that compiles correctly and gives me the expected result. </p>
  
  <p>So, after all that, my question is: how can I get knitr to use <code>\(...\)</code> instead of <code>$...$</code> in the <code>alltt</code> environment?</p>
  
  <p>(R-3.0.1, emacs 23.3.1, ess 13.05, Ubuntu 12.04)</p>