更新:此处修改了描述
这并不能回答确切的问题,但也许可以回答用例。我最近遇到了类似的挑战:我想将写作和分析合并在一个.rnw文件中,但我的合作者不想使用 R/RStudio/GitHub/LaTeX。
因此,我决定通过 Dropbox 与他们共享我的 git 存储库的子文件夹。该文件夹包含三个.docx文件:introduction.docx、methods.docx和discussion.docx(我将结果部分写入该.rnw文件内)。唯一的问题是他们在写作时必须使用一些非常基本的 LaTeX,例如\subsection{heading}标题、参考文献\cite{key}、“引号”、转义 \%、\$ 和 \&。
回到.rnw文件中,我将.docx文件转换为.txt:
system("textutil -convert txt introduction.docx")
然后将文件扩展名从重命名.txt为.tex:
file.rename("introduction.txt", "introduction.tex")
然后在代码块之外R,我使用以下命令调用.tex文件:
\input{introduction}
我在 GitHub 上发布了一个小示例。
\documentclass{article}
\makeatletter
\renewcommand{\@biblabel}[1]{\quad#1.}
\makeatother
\date{}
\bibliographystyle{plain}
\begin{document}
\begin{flushleft}
{\Large
\textbf{My Title}
}
\end{flushleft}
\section{Introduction}
% do not write in this section...let collaborators write in introduction.docx
<<intro, include=FALSE>>=
# assumes wd set to root folder collaborate
# convert docx to txt
system("textutil -convert txt introduction.docx")
# rename txt to tex
file.rename("introduction.txt", "introduction.tex")
@
% pull in introduction.tex
\input{introduction}
\section{Methods}
<<methods, include=FALSE>>=
system("textutil -convert txt methods.docx")
file.rename("methods.txt", "methods.tex")
@
\input{methods}
\section{Results}
<<results>>=
dat <- data.frame(x=runif(30, 0, 30))
mean <- mean(dat$x, na.rm=TRUE)
@
The mean is \Sexpr{round(mean, 1)}.
\section{Discussion}
<<discussion, include=FALSE>>=
system("textutil -convert txt discussion.docx")
file.rename("discussion.txt", "discussion.tex")
@
\input{discussion}
\bibliography{example.bib}
\end{document}
Run Code Online (Sandbox Code Playgroud)