yihui
code.tex
文件内容如下:
\documentclass{ctexart}
\usepackage{minted}
\title{R语言}
\author{某某}
\begin{document}
\maketitle
\section{数据描述}
\begin{minted}{c}
int main() {
printf("hello, world");
return 0;
}
\end{minted}
\begin{minted}{python}
def boring(args = None):
pass
\end{minted}
\begin{minted}{r}
require(stats) # for lowess, rpois, rnorm
plot(cars)
lines(lowess(cars))
plot(sin, -pi, 2*pi) # see ?plot.function
## Discrete Distribution Plot:
plot(table(rpois(100, 5)), type = "h", col = "red", lwd = 10,
main = "rpois(100, lambda = 5)")
## Simple quantiles/ECDF, see ecdf() {library(stats)} for a better one:
plot(x <- sort(rnorm(47)), type = "s", main = "plot(x, type = \"s\")")
points(x, cex = .5, col = "dark red")
\end{minted}
\mint{python}|import this|
\end{document}
使用 minted
包的tex文件,需要在编译的时候使用-shell-escape
参数,如果使用 tinytex::xelatex
,不知道如何传这个参数?如果不能传递,谢大大是否可以再添加 args 选项让用户自己传递类似上述 -shell-escape
参数?
system2('xelatex', args = '-shell-escape code') # 没问题,但是要运行几遍才有目录索引
tinytex::xelatex(file = 'code.tex')
# I was unable to find any missing LaTeX packages from the error log code.log.
# ! Package minted Error: You must invoke LaTeX with the -shell-escape flag.
#
# Error: Failed to compile code.tex. See code.log for more info.
# In addition: Warning message:
# running command '"xelatex" -halt-on-error -interaction=batchmode "code.tex"' had status 1