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.
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.
Related
Whenever I tried to knit R markdown in beamer presentation format, it keeps on giving me undefined control sequence.
It is fraustrating because it worked fine until yesterday and I have no idea what I changed that causes this error.
To show that my code is not the source of the problem, I simply tried to knit an empty page.
code:
---
title: "untitled"
output: beamer_presentation
---
Output:
output file: a.knit.md
! Undefined control sequence.
<argument> ...{subsubsection}\addtobeamertemplate
{theorem begin}{\expandaft...
l.322 }{}
My original file returns the exaclty same error message.
I tried:
reinstall LaTeX
reinstall RStudio
upgrade all packages in R
Any idea how to fix this?
This was just fixed by #UlrikeFischer. #JosephWright is preparing a new beamer release as we speak, it should be available as beamer v3.67 on ctan tomorrow.
As a temporary workaround, place these two files in the folder of your .rmd file:
https://raw.githubusercontent.com/josephwright/beamer/main/base/beamer.cls
https://raw.githubusercontent.com/josephwright/beamer/main/base/beamerbasesection.sty
(don't forget to delete these files again once you have the new beamer version, otherwise they might interfere with future updates)
I'm writing a paper using R Markdown and TinyTex, using Biblatex for referencing. It works fine with default referencing styles, but I need to add a custom bibliography and citation style for the journal I'm writing for.
I need to follow the Unified Stylesheet for Linguistics, for which there is a Biblatex implementation available on Github here, containing a .bbx and .cbx file.
I've tried adding those .bbx and .cbx files to my local copy of TinyTex, inside Library/TinyTex/texmf-local/tex/latex/biblatex. My YAML header includes:
output:
pdf_document:
citation_package: biblatex
biblatexoptions: [bibstyle=biblatex-sp-unified, citestyle=sp-authoryear-comp]
When I knit the document, I get the following error:
tlmgr search --file --global '/biblatex-dm.cfg'
! Package keyval Error: bibstyle undefined.
I don't have a biblatex-dm.cfg file (nor do I really understand what that would be). I would have thought the .bbx and .cbx files would be sufficient, based on the regular installation instructions in the style's Github repo.
Where should I put .bbx and .cbx files, so that tlmgr can find them? And/or what additional steps do I need to take to use this style with my paper?
====================================================================
UPDATE: The problem seems to be coming from the Pandoc LaTeX template that R Markdown uses.
Setting aside R Markdown, I created a smaller minimal LaTeX example:
main.tex
references.bib
Where main.tex is:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[bibstyle=biblatex-sp-unified,citestyle=sp-authoryear-comp]{biblatex}
\addbibresource{references.bib}
\begin{document}
Something something \citep{darwin_origin_1859}.
\printbibliography
\end{document}
And references.bib is:
#book{darwin_origin_1859,
location = {London},
title = {On the Origin of Species by Means of Natural Selection},
publisher = {J. Murray},
author = {Darwin, Charles},
date = {1859}
}
I had success compiling this example using the sequence of commands pdflatex, biber, pdflatex, pdflatex. Thus it seems my local TeX installation knows about the biblatex-sp-unified.bbx and sp-authoryear-comp.cbx files I added and can use them just fine.
Subsequently, I created an equivalent minimal R Markdown document with the YAML header:
title: "Untitled"
output:
pdf_document:
citation_package: biblatex
bibliography: references.bib
biblatexoptions: [bibstyle=biblatex-sp-unified, citestyle=sp-authoryear-comp]
and body:
Something something [#darwin_origin_1859].
This time, I got the same old error message from before:
tlmgr search --file --global '/biblatex-dm.cfg'
! Package keyval Error: bibstyle undefined.
This would seem to suggest that the problem is caused by something in Pandoc's LaTeX template, but I don't know what.
Just to confirm that it's definitely the Pandoc template and not my own installation/setup, I took the .tex file that gets produced when I knit the minimal R Markdown example above, and tried to compile it in Overleaf (with biblatex-sp-unified.bbx and sp-authoryear-comp.cbx files added). I reproduced the same error.
Although I think I've localised the problem, I'd still very much like to understand what and where the problem is in the Pandoc template. I'd also be keen to hear if anyone has any fixes (other than just using a different template or writing my own).
UPDATE: This seems to be an issue with using an out-of-date version of R Markdown and/or Pandoc.
I was using rmarkdown package v.1. At time of writing, the most up-to-date version is 2.1.
I updated all my packages and updated Rstudio (which currently ships with Pandoc v2.3.1) and no longer experience problems. I also upgraded R (from 3.5.something to 3.6.2) and did a fresh re-install of tinytex while I was at it, but I'm not sure whether those things had an effect for this particular problem.
Now, when I put biblatexoptions: [bibstyle=biblatex-sp-unified, citestyle=sp-authoryear-comp] in my YAML header, it's correctly converted into the LaTeX command \usepackage[bibstyle=biblatex-sp-unified,citestyle=sp-authoryear-comp]{biblatex}, rather than the \ExecuteBibliographyOptions command as described below.
Ralf Stubner initially suggested I check my R Markdown/Pandoc versions in the comments. Please give his comments an upvote if you them useful as well.
Problem recap:
I'm writing a document in R Markdown and I have a particular referencing style that I'd like to use with biblatex. I have a .bbx and .cbx file defining the style, available on Github (linked above). The problem is that the document fails to compile, saying biblio/citation styles are undefined (even when the style files are in the project folder itself).
I've found that the problem was caused by the way I was passing options to biblatex. In my YAML Header, the line:
biblatexoptions: [bibstyle=biblatex-sp-unified, citestyle=sp-authoryear-comp]
gets converted to the latex command:
\ExecuteBibliographyOptions{bibstyle=biblatex-sp-unified,citestyle=sp-authoryear-comp}
I'm not sure why, but when this command is included, it produces the errors I was observing.
Installing new Biblatex style:
I'm finding that TeX doesn't know about the .bbx and .cbx files when they're in my ~/Library/TinyTex/texmf-local/tex/latex/biblatex directory (which is where I expected to put them based on the Github installation instructions).
To get the referencing style recognised by the system, I placed .bbx and .cbx files inside ~/Library/TinyTex/texmf-dist/tex/latex/biblatex/bbx and ~/Library/TinyTex/texmf-dist/tex/latex/biblatex/cbx respectively. Then, in the terminal, I ran sudo mktexlsr.
(Alternatively, for use only with a particular document, the .bbx and .cbx files could simply be kept in the project directory with the R Markdown file)
Original hacky answer (but see update above):
Instead of using biblatexoptions in the YAML header of the R Markdown document, I simply knitted it with citation_package: biblatex (and no extra options). I also added keep_tex: yes. Then, I opened the resulting tex file, found the \usepackage{bibtex} command and added the desired options, so it read \usepackage[bibstyle=biblatex-sp-unified,citestyle=sp-authoryear-comp]{biblatex}.
Finally, I ran pdflatex and biber on the tex file in the terminal. Clearly far from ideal, but it will technically produce the desired output.
Is it possible to use pandoc-crossref in bookdown?
I tried to change the yaml header to:
output:
bookdown::tufte_book2:
toc: yes
highlight: tango
pandoc_args: -F /usr/local/bin/pandoc-crossref
Which should pass the filter to pandoc, but I get the error:
pandoc: Error running filter pandoc-crossref:
Could not find executable ' pandoc-crossref'.
The above error does not make sense, as I entered the correct path. What kind of env is bookdown using, which is precluding the access to the filter file?
Here is an example
---
output: bookdown::html_document2
---
# Section name {#id}
```{r pressure, echo=FALSE, fig.cap='test plot'}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot. To cross-reference the figure, use `\#ref(fig:pressure)` to produce Figure \#ref(fig:pressure). All this is found within the section \#ref(id).
Which produces...
See https://bookdown.org/yihui/bookdown/figures.html for the official documentation.
I had a similar issue while I was trying to put numbers to equations in Word files (SO question). I got the same error Could not find executable 'pandoc-crossref'.
My RStudio installation (on Windows) did not come with pandoc-crossref. Here is what I did:
Downloaded pandoc-crossref from here.
Find the path where RStudio saved the file pandoc.exe:
rmarkdown::find_pandoc()
Put the pandoc-crossref.exe in the folder I got in (2).
I'm trying to put together some course notes as a PDF, and am having trouble getting certain Unicode characters to display properly.
Using the xelatex latex engine is necessary for the document to be rendered at all (using the default engine results in an error due to the unrecognized characters), however, only the first Unicode character (uppercase delta) is displayed properly.
For example, when using the rmarkdown render() function to render the following .Rmd file:
---
output:
pdf_document:
latex_engine: xelatex
---
- works - Δ
- doesn't work - ⌘
The resulting PDF only shows the first unicode character (uppercase delta), and not the later one (looped square).
I know that there are different character subsets that make up the full UTF-8 character encoding, so it seems like perhaps only more basic subsets are supported.
Just to be certain, I checked the encoding of the file using iconv -f UTF-8 your_file -o /dev/null [1], and it does indeed appear to be a valid UTF-8 document.
Finally, the document renders fine as HTML using the default options, so the issue is specific to PDF output.
Any ideas how to get the second character to render to PDF?
System Information
Linux 64-bit
R 3.3.1
rmarkdown 1.0
pandoc 1.17.2
XeTeX 3.14159265-2.6-0.99996
Locale: en_US.UTF-8
The problem might be that the default font does not have that character. You'll need to find a font that has it. On Linux, fc-list lists the fonts that are available on your computer. Pick one and add it to your yaml front matter:
---
output:
pdf_document:
latex_engine: xelatex
mainfont: FreeMono
---
- works - Δ
- doesn't work - ⌘
Here, I am using FreeMono, which is the first one I found that has the ⌘ character, but there probably is a better one.
When I try to knit to PDF I have this error:
! Package inputenc Error: Unicode char \u8:。 not set up for use with LaTeX.
See the inputenc package documentation for explanation.
Type H for immediate help.
...
l.387 explained by ``gdp''。
Try running pandoc with --latex-engine=xelatex.
pandoc: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
Execution halted
I did includes all files in the working directory but still don't know why.
I could not comment on the previous post by scoa, but the YAML header argument misses a space and should read:
output:
pdf_document:
latex_engine: xelatex
I had a similar problem once. Try installing Pandoc on your machine, reboot and try again. You can download Pandoc here.
Also, you'd most likely need to install MiKTeX.
I hope this helps.
This is an encoding error. The easiest way to deal with it is to add the following line in the YAML preamble of your document.
---
output:
pdf_document:
latex_engine:xelatex
---