简体   繁体   English

从 RMarkdown 中提取 LaTeX 图形和标题标签列表以复制到 Overleaf

[英]Extracting a list of LaTeX figure and caption labels from RMarkdown to copy into Overleaf

I am working with coauthors.我正在与合著者合作。 We want to produce all figures and tables (including an appendix) in a single RMarkdown document but write the paper jointly in Overleaf (excellent for simultaneous editing, which we don't need for the statistical code).我们希望在单个 RMarkdown 文档中生成所有图形和表格(包括附录),但在 Overleaf 中共同编写论文(非常适合同时编辑,我们不需要统计代码)。

Here is an example Rmd which knits to a pdf.这是一个与 pdf 结合的示例 Rmd。 (The pdf will be appended manually to the main paper.) (pdf 将手动附加到主论文中。)

---
title: "Nice document"
output: pdf_document
date: '2022-08-12'
---

```{r}
library(kableExtra)
```


```{r pressure, echo=FALSE, fig.cap="\\label{fig:pressure} Nice caption."}
plot(pressure)
```
```{r echo=FALSE, fig.cap="\\label{fig:diffpressure} Better caption."}
kable(head(mtcars), longtable = T, booktabs = T, caption = "Cool table", label = "tab:carssummary") 
```


\appendix

\setcounter{figure}{0}
\setcounter{table}{0}
\renewcommand{\thefigure}{S\arabic{figure}}
\renewcommand{\thetable}{S\arabic{table}}


```{r echo=FALSE, fig.cap="\\label{fig:diffpressure} Better caption."}
plot(pressure/3.5)
```

I want a extract a character vector from the Rmd that is the following:我想从 Rmd 中提取一个字符向量,如下所示:

\begin{figure}
\caption{empty}
\label{fig:pressure}
\end{figure}

\begin{table}
\caption{empty}
\label{tab:carssummary}
\end{table}

\appendix

\setcounter{figure}{0}
\setcounter{table}{0}
\renewcommand{\thefigure}{S\arabic{figure}}
\renewcommand{\thetable}{S\arabic{table}}

\begin{figure}
\caption{empty}
\label{fig:pressure2}
\end{figure}

I will then copy and paste this to the bottom of the Overleaf doc, enabling us to do the automated cross referencing with minimal hassle (and easy updating if and when the analysis output changes).然后,我会将其复制并粘贴到 Overleaf 文档的底部,使我们能够以最小的麻烦进行自动交叉引用(并且在分析 output 发生变化时轻松更新)。

How can I extract that LaTeX code from the Rmd?如何从 Rmd 中提取 LaTeX 代码?

Assuming your markdown document is called test.rmd and you included the keep_tex: true option to the header假设您的 markdown 文档名为test.rmd并且您在 header 中包含了keep_tex: true选项

---
title: "Nice document"
output: 
  pdf_document:
    keep_tex: true
date: '2022-08-12'
---

You can upload the test.aux file to overleaf and then include the cross-refs in your overleaf document with the xr-hyper package:您可以将test.aux文件上传到背页,然后使用xr-hyper package 在您的背页文档中包含交叉引用:

\documentclass{article}

\usepackage{xr-hyper}
\externaldocument{test}

\usepackage{hyperref}

\begin{document}
    
some cross-ref: \ref{fig:diffpressure}
    
\end{document}

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM