This decision is inspired by the yihui hook example , this post and my buddy RJ.
\documentclass{article} \usepackage{xspace} \newcommand{\mytilde}{\lower.80ex\hbox{\char`\~}\xspace} \begin{document} <<setup, include=FALSE>>= library(knitr) hook_source = knit_hooks$get('source') knit_hooks$set(source = function(x, options) { txt = hook_source(x, options)
It also defines the \mytilde for general use. For example, an example R-code line: " in the form \texttt{response~\mytilde~predictors} ... ".
The xspace package xspace not strictly necessary (if you remove xspace in a new command), but makes the command more enjoyable to use.
source share