0
votes

I am interested in getting a LATEX template working in RMarkdown. In the past I have been able to get this to work by implementing a .cls document. But this is not available for this template.

In the main directory of the LATEX template I see a structure.tex and main.tex. Where structure.tex seems identical to previous .cls files I have used in the past.

Here is an example of how I implemented this in the past within an .Rmd document

---
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
---

This causes me to get the following error claiming that /chaptermark is undefined.

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

Yet on line 173 I have:

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

WHAT I HAVE TRIED

Calling a .tex document within in_header rather than in documentclass

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

This causes the following error

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

I have also tried to call documentclass

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

This also fails to work. Does anyone have any suggestions on getting this template into a cls so I can use it in RMarkdown?

I understand this might be a very entry level question and I was not certain if it was moreso an RMarkdown or Latex question. Any input is greatly appreciated.

1
Have you tried using the LaTeX command \input{structure.tex} early in the main text of your document? (This assumes it is valid to put it in the body of the document.) Generally speaking, LaTeX macros pass through Markdown.user2554330
Showing us where and how structure.tex is mentioned in main.tex would help a lot.user2554330

1 Answers

0
votes

The particular error Command \chaptermark undefined. is caused by structure.tex expecting book.cls, while rmarkdown uses article.cls by default. You could try

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

But I expect other incompatibilities between the packages loaded in structure.tex and those loaded in the default template. The same type of problems might occur when converting the tex to a cls file. So instead I would suggest to combine main.tex and structure.tex to form a new template file. Quoting section 3.3.7.4 Custom templates from the rmarkdown book:

You can also replace the underlying Pandoc template using the template option:

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

Consult the documentation on Pandoc templates for additional details on templates. You can also study the default LaTeX template as an example.