svmiller / svm-r-markdown-templates

This is my (deprecated) suite of R Markdown templates for academic manuscripts, beamer presentations, and syllabi. DOWNLOAD {stevetemplates} INSTEAD.
http://svmiller.com/stevetemplates/
Other
896 stars 737 forks source link

Error compiling the template: unexpected "\\" #28

Closed raphael-lorenzdelaigue closed 3 years ago

raphael-lorenzdelaigue commented 3 years ago

Hi,

I get an error message when trying to knit a .Rmd document using your custom latex template.

Error compiling template "svm-latex-ms.tex" (line 101, column 3474):
  unexpected "\\"
expecting ".", "/", "(", ":", "[" or "$"
Error: pandoc document conversion failed with error 5
Execution halted

What i find at line 101, column 3474 of the *.tex document is a single backslash, not a double one - namely the second backslash in the following expression :

\"$opt_dummy_attribute\",

Any idea what might be going wrong?

svmiller commented 3 years ago

This will probably lean on the raw .tex document (and not the template), because this is line 101 of the template itself.

If I'm reading the error message correctly, is this a case of trying to compile the template directly to PDF?

raphael-lorenzdelaigue commented 3 years ago

Hi, sorry, I rushed too much when writing the issue and mixed up the raw .tex document and the template.

So, what I find at the aforementioned line (and around column 3474) is this:

\\"$opt_dummy_attribute\\"

The backslash after "attribute" should be the exact character at the exact line and column.

My goal is to convert a .Rmd document to PDF, but my .Rmd document will contain some LateX (-> math formulas) and citations, which is why I am trying to setup the document to use your template.

This is what the output part of my YAML header looks like:

output: 
  pdf_document:
    template: svm-latex-ms.tex
svmiller commented 3 years ago

Absent a reprex, it's hard to diagnose what might be happening here. I compiled the starter version of the template from the associated R package and line 101 of the document .tex file (not the template itself) is still preamble stuff. Can you send along a minimal example so that I might see what's happening in it? This might be one blind spot in my templates. As a social scientist, our readers are loathe to read formulas/math so it's conceivable including code and math might break a few things.

raphael-lorenzdelaigue commented 3 years ago

Sorry, I am struggling a bit to make a proper reprex including the YAML header and Markdown code.

I copy and paste manually:

  1. The content of my .Rmd document (reduced to minimal example)
---
title: "reprex_tex_error"
output: 
  pdf_document:
    template: svm-latex-ms.tex
---

$$s_i = \sum_{j}^n w_i$$
  1. The output I get when I knit the document:
==> rmarkdown::render('C:/Users/Raphael/Documents/git/masterarbeit/thesis/reprex_tex_error.Rmd',  encoding = 'UTF-8', knit_root_dir = '~/git/masterarbeit');
  |......................................................................| 100%
  ordinary text without R code

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS reprex_tex_error.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output reprex_tex_error.tex --lua-filter "C:\Users\Raphael\Documents\R\win-library\4.1\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\Raphael\Documents\R\win-library\4.1\rmarkdown\rmarkdown\lua\latex-div.lua" --self-contained --template svm-latex-ms.tex --highlight-style tango --pdf-engine pdflatex 

processing file: reprex_tex_error.Rmd
output file: reprex_tex_error.knit.md

Error compiling template "svm-latex-ms.tex" (line 101, column 3474):
unexpected "\\"
expecting ".", "/", "(", ":", "[" or "$"
Error: pandoc document conversion failed with error 5
Execution halted

Of note that I haven't installed the package, I simply downloaded the .tex file and am trying to use it via the header

svmiller commented 3 years ago

I'm using {stevetemplates} (the R package for my templates) and this ends up working fine for me.

https://gist.github.com/svmiller/3c15669b44dee45ab354b1e9ef43f1dc

raphael-lorenzdelaigue commented 3 years ago

Okay thanks works for me too.

Then my mistake was to try and use the .tex manually and not install your package (I like to try and have my setup more minimal when possible^^).

svmiller commented 3 years ago

Yeah, I've taken to updating my templates in the R package and leaving this repo more as a legacy (because it's already been forked hundreds of times). When in doubt, check the package. If it still fails, raise it there.

More than that, I'm glad this ended up working out for you.

raphael-lorenzdelaigue commented 3 years ago

Okay, thanks for the quick answers!