문제

When I include an inline code trunk using \Sexpr{}, the matrix multiplication symbole %*% is interpreted as Latex commenting. How to get around this?

도움이 되었습니까?

해결책

This seems like a reasonable concern, but it doesn't happen to me (with R-devel/3.1.0, knitr 1.5). Also, logically it seems as though it shouldn't happen since the contents of code chunks are evaluated before LaTeX sees the file. Reproducible example please?

(As shown below, you can get into trouble if you try hard enough, but generally I think you shouldn't.)

If texmult.Rnw is this:

\documentclass{article}
\pagestyle{empty}
\begin{document}

hello

<<>>=
m <- matrix(1:4,nrow=1)
x <- 1:4
@

The result is \Sexpr{m %*% x}

This is a bad thing: \Sexpr{"%*%"} and then more stuff

\end{document}

Then library(knitr); knit2pdf("texmult.Rnw") gives me

enter image description here

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top