【问题标题】:Convert a (LATEX) .tex file into .cls so it can be used in RMarkdown将 (LATEX) .tex 文件转换为 .cls 以便在 RMarkdown 中使用
【发布时间】:2019-01-27 06:18:20
【问题描述】:

我有兴趣获得在 RMarkdown 工作的 LATEX template。在过去,我可以通过实现.cls 文档来实现这一点。但这不适用于此模板。

在 LATEX 模板的主目录中,我看到了 structure.texmain.tex。其中structure.tex 似乎与我过去使用的以前的.cls 文件相同。

这是我过去如何在 .Rmd 文档中实现此功能的示例

---
title: My Title Goes Here
author: "Author Name"
output:
  pdf_document:
    keep_tex: yes
    latex_engine: xelatex
documentclass: styles/thesis-umich3 #This is where the .cls document is stored
---

这导致我收到以下错误,声称 /chaptermark 未定义。

`documentclass` searches specifically for a `.sty` file

然而在第 173 行我有:

\renewcommand{\chaptermark}[1]{\markboth{\sffamily\normalsize\bfseries\chaptername\ \thechapter.\ #1}{}} % Styling for the current chapter in the header

我已经尝试过什么

in_header 中而不是在documentclass 中调用.tex 文档

---
title: "fNIRS Guide"
output:
  pdf_document:
    includes:
      in_header: style/structure.tex
---

这会导致以下错误

tlmgr search --file --global "/numeric.dbx"
tlmgr search --file --global "/biblatex-dm.cfg"
! LaTeX Error: Command \chaptermark undefined.

Error: Failed to compile index.tex. See index.log for more info.
In addition: Warning messages:
1: In parse_packages(logfile, quiet = c(TRUE, FALSE, FALSE)) :
  Failed to find a package that contains numeric.dbx
2: In parse_packages(logfile, quiet = c(TRUE, FALSE, FALSE)) :
  Failed to find a package that contains biblatex-dm.cfg
Execution halted

我也试过打电话给documentclass

---
title: "index"
output: 
  pdf_document:
    keep_tex: yes
    latex_engine: xelatex
documentclass: style/structureSavedAsCLS
---

这也不起作用。有没有人有任何关于将此模板放入cls 以便我可以在 RMarkdown 中使用它的建议?

我知道这可能是一个非常入门级的问题,我不确定它是不是 RMarkdown 或 Latex 问题。非常感谢任何输入。

【问题讨论】:

  • 您是否尝试过在文档正文的早期使用 LaTeX 命令\input{structure.tex}? (这里假设放在文档正文中是有效的。)一般来说,LaTeX 宏是通过 Markdown 传递的。
  • 向我们展示structure.texmain.tex 中提到的位置和方式会很有帮助。

标签: latex r-markdown pdflatex


【解决方案1】:

特定错误Command \chaptermark undefined. 是由structure.tex 期望book.cls 引起的,而rmarkdown 默认使用article.cls。你可以试试

---
title: "fNIRS Guide"
output:
  pdf_document:
    includes:
      in_header: style/structure.tex
documentclass: book
---

但我预计structure.tex 中加载的包与默认模板中加载的包之间存在其他不兼容性。将tex 转换为cls 文件时可能会出现相同类型的问题。因此,我建议将main.texstructure.tex 组合起来形成一个新的模板文件。引用 rmarkdown 书中的 3.3.7.4 Custom templates 部分:

您还可以使用模板选项替换底层 Pandoc 模板:

---
title: "Habits"
output:
  pdf_document:
    template: quarterly-report.tex
---

有关模板的更多详细信息,请参阅 Pandoc templates 上的文档。也可以以default LaTeX template为例进行学习。

【讨论】:

  • 谢谢,我今天就试一试。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-08
  • 1970-01-01
  • 2010-12-02
相关资源
最近更新 更多