Question

How can I Sweave text with a #-sign?

Here, Sweaving and compiling is no problem:

<<echo=false,results=tex>>
cat("This is my text\n") 
@

But here, compiling gives an error:

<<echo=false,results=tex>>
cat("This is #my text\n")
@

The hash sign could not be compiled in tex. I have to set the Sweave option to "tex" because I want to print different text files in a loop and each text file should be separated by a new chapter.

<<results=tex>>
for(i in d){
  tx <- readLines(i)
  cat(tx, sep="\n")
  \chapter{i}
  }

Thanks for every hint.

TIM

Was it helpful?

Solution

You have to escape the hash-sign, since it has in LaTeX a special meaning.

\documentclass{article}

\begin{document}
\SweaveOpts{concordance=TRUE}

<<echo=false,results=tex>>=
cat("This is \\#my text\n") 
@


\end{document}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top