RMarkdown xelatex !Missing & Inserted

不打扰是莪最后的温柔 提交于 2020-01-05 03:57:05

问题


I originally posted with issues here:

Rmarkdown with xelatex

I have since reinstalled, but now I'm having an entirely new issue.

Using the following code (inside a .Rmd file):

---
header-includes:
- \usepackage{graphicx}
output: 
  pdf_document:
    latex_engine: xelatex
---

```{r}


knitr::include_graphics("F:/Big Folder/My Folder/image.png")

```

I get the following error:

! Missing $ inserted.
<inserted text> 
            $
l.134 .../Big Folder/My Folder/image}

pandoc.exe: Error producing PDF
Error: pandoc document conversion failed with error 43

I think it has something to do with the space in the path, because when I put the image directly in F, it works fine.

Unfortunately, this project requires that I use folders with spaces in the name.

I'm on Windows 10 64 bit, running MikTex 2.9 with updated packages (including fontspec). Miktex is installed in program files, but I also tried an install to a different folder but had the same result.

I'm also running a recently installed/updated rstudio with updated knitr and rmarkdown packages.

This does work on pdflatex, even with spaces in the file name.


回答1:


Got it, the actual image file was formatted as image_something.png.

The "_" was throwing it off and removing it fixed it.

Also, if I want to keep the underscore I need to add two escape characters "\\".

F:/Big Folder/image\\_something.png

This is somewhat different than the non rmarkdown latex solution in that it only requires a single escape character.

This solution was modified from https://tex.stackexchange.com/questions/266575/how-can-i-write-an-under-dash-in-text-without-invoking-italics-or-some-weird-fon.

I would still be curious as to why spaces are allowed on pdflatex but not xelatex.



来源:https://stackoverflow.com/questions/47415473/rmarkdown-xelatex-missing-inserted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!