Ответ 1
Обновление: пересмотренное описание здесь
Это не отвечает на точный вопрос, но может быть и в случае использования. Недавно у меня была аналогичная задача: я хотел объединить запись и анализ в одном файле .rnw
, но мои соавторы не хотели использовать R/RStudio/GitHub/LaTeX.
Итак, я решил поделиться с ними вложенной папкой моего git репо с помощью Dropbox. Эта папка содержит три файла .docx
: introduction.docx
, methods.docx
и discussion.docx
(я пишу раздел результатов в файле .rnw
). Единственный улов в том, что они должны использовать некоторые очень простые LaTeX при написании, например \subsection{heading}
для заголовков, \cite{key}
для ссылок, `quotes '', escaping \%,\$и\&.
Вернувшись в файл .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}