Bibliography causes rmarkdown::render() to fail - runtime-error

trying to render my rmarkdown into a MS Word, if I add a bibliography I get this error:
pandoc-citeproc: when expecting a product (:*:), encountered Object instead
Error running filter pandoc-citeproc:
Filter returned error status 1
Error: pandoc document conversion failed with error 83
These are the headers of my .rmd file:
title: XXX.
author: "Angelo D'Ambrosio"
date: "10/8/2020"
delete_merged_file: true
bibliography: references.bib
output:
word_document:
reference_docx: style.docx
pandoc_args: ['-F', 'pandoc-crossref']
toc: yes
---
I read around that it could be a matter of pandoc versions. I updated my pandoc with brew, since the RStudio one is too old and couldn't work with pandoc-crossref.
UPDATE:
It is indeed related to pandoc version. To make pandoc work with pandoc-crossref I need to force rmarkdown to use the version of pandoc I downloaded with rmarkdown::find_pandoc(dir = "/usr/local/Cellar/pandoc/2.10.1/bin"). But then this version don't like pandoc-citeproc. So if I use rstudio default pandoc I get pandoc-citeproc and if I use the one I downloaded I get pandoc-crossref. How can I get both??

Related

Error when building Vignette - R package development

My apologies in advance if this is an obvious question but I have searched both stack overflow and what have been otherwise very useful resources like R packages by Hadley Wickham or this blog and can not find an answer.
My issue occurs when trying to run build_vignettes() on my developed R package (myPackage). The vignette for the package (myPackage.Rmd) will create as expected using knit in RStudio but when I run build_vignettes(), I get the following error:
> devtools::build_vignettes()
Building cosni vignettes
--- re-building ‘myPackage.Rmd’ using rmarkdown
--- finished re-building ‘myPackage.Rmd’
Error: Directory '✓ Setting active project to \'path/to/package/directory/'' does not exist.
The top of my myPackage.Rmd file is:
---
title: "A title"
date: "`r Sys.Date()`"
author: "Name"
output:
html_document:
toc: true
toc_float: true
number_sections: true
theme: "paper"
pdf_document:
toc: true
vignette: >
%\VignetteIndexEntry{A title}
%\VignetteEngine{knitr::rmarkdown}
\usepackage[utf8]{inputenc}
---
This file is located in the vignettes folder of my package folder. There are also 3 png images in this folder which are called in the myPackage.Rmd file as follows:
```{r, echo=FALSE, out.width = '98%', out.height='98%'}
knitr::include_graphics("an_image.png")
```#
Otherwise the vignette only contains text.
The package will run and I can install it locally with either devtools::build() or
devtools::install(build_vignettes = TRUE) they will work but then when I run browseVignettes("myPackage") and click on the HTML, source or R code I get the following error:
Not Found
The requested URL /library/myPackage/doc/myPackage.html was not found on this server.
Also, in the package's DESCRIPTION file I have included the following:
Suggests:
knitr,
rmarkdown
VignetteBuilder: knitr
----------- EDIT --------------
Through repeatedly trying to get the devtools::build_vignettes to work I have noted that sometimes I get the following error rather than the first I mentioned:
> devtools::build_vignettes()
Building cosni vignettes
--- re-building ‘myPackage.Rmd’ using rmarkdown
--- finished re-building ‘myPackage.Rmd’
Error in if (dir_exists(path %||% "") && is_in_proj(path)) { :
missing value where TRUE/FALSE needed
I solved the second error you get updating packages devtools and usethis.

R markdown not recognizing loaded LaTeX packages

I'm trying to use the LaTeX package gensymb in my R markdown document (PDF output), but it seems to not work. These two examples work:
IN LaTeX as a .tex file compiled with PDFLaTeX:
\documentclass{article}[12pt]
\usepackage{gensymb}
\begin{document}
It is 90 \degree F outside.
\end{document}
As well as this one In RStudio as a .rmd file using knitr and pdfLaTeX:
header-includes:
output:
pdf_document:
fontsize: 12pt
geometry: margin=1in
---
It is 90 $^{\circ}$ F outside.
But the following does not compile in a .rmd file.
header-includes:
- \usepackage{gensymb}
output:
pdf_document:
fontsize: 12pt
geometry: margin=1in
---
It is 90 \degree F outside.
The error from R reports
tlmgr.pl: Local TeX Live (2019) is older than remote repository (2020).
Cross release updates are only supported with
update-tlmgr-latest(.sh/.exe) --update
See https://tug.org/texlive/upgrade.html for details.
! LaTeX Error: File `gensymb.sty' not found.
Any help is greatly appreciated!
The errors suggest that there are two distributions of TeX installed. One of them is not updated to the same version as the repository from which it is trying to get gensymb and therefore fails to download the package.
It is wise to only have one distribution installed to prevent errors or confusion like that.

Very simple .rmd --> beamer_presentation; still cannot get rid of "Option clash for package xcolor"

I cannot compile to a pdf-beamer from a very simple minimal example (below), with no packages.
I click - Knit - Knit to pdf
(Note this is not a duplicate of previous posts, because those all involved using Kable; I am not using it; fresh restart not calling any packages here)
I tried with and without classoption: table
Knit to html works just fine.
Restarted Rstudio; no improvement
---
title: "Untitled"
author: "Test"
date: "20 novembre 2018"
classoption: table
output:
beamer_presentation:
keep_tex: yes
---
# Test nothing
blah
```
Throws error: ! LaTeX Error: Option clash for package xcolor.
I want it to compile a beamer pdf slide show, of course.
I've put the log file here
My default.beamer (stored at /Users/yosemite/.pandoc/templates/default.beamer I think) is linked HERE

RMarkdown xelatex !Missing & Inserted

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.

Garbled or missing LaTeX math formulas in RMarkdown->PDF knitr-converted document

I'm using Rstudio to write an RMarkdown document that I turn into a PDF using MiKTeX on Windows through knitr and pandoc. LaTeX engine is xelatex.
My .Rmd file YAML header:
---
title: "My Title"
author: "Me"
geometry: margin=2cm
output:
pdf_document:
fig_caption: no
fig_height: 4
fig_width: 6
latex_engine: xelatex
html_document:
css: styles.css
keep_md: no
fontsize: 10pt
---
In the text I have
...parameter $\lambda=0.2$ with...
and I get "parameter = 0 2 with" -- both the lambda and even the dot are missing.
This line
mean of $\frac{1}{\lambda}=5$ of the
turns into
EDIT: When I try to add as an experiment (I'm on Windows)
mainfont: Arial
to the YAML header I get a pandoc error
! Undefined control sequence.
\fontspec_calc_scale:n ...ec_tmpb_dim }\fp_div:Nn
\l_fontspec_tmpa_fp {\l_fo...
l.18 \setmainfont{Arial}
pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
UPDATE:
Running pdflatex report1.pdf produces a correct PDF.
RStudio runs "C:/Program Files/RStudio/bin/pandoc/pandoc" report1.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output report1.pdf --template "D:\Documents\R\win-library\3.2\rmarkdown\rmd\latex\default.tex" --highlight-style tango --latex-engine xelatex
So it seems the elsewhere recommended engine "xelatex" produces faulty output, while "pdflatex" works. Unfortunately I forgot the reasons given by some sources incl. SO that I followed a few days ago when switching to xelatex, I only remember it was highly recommended to use that with knitr in RStudio rather than pdflatex.
I'm posting this answer to increase the visibility of #user1983395 's comment regarding this error.
I was facing the same error as OP. pdflatex just produced the mentioned error, and xelatex produced an error whenever there was a call to a math formula ( $X_i$ or $$X_i$$ ).
After running C:\Program Files\MiKTeX 2.9\miktex\bin\x64\updmap.exe I was able to generate a pdf both with pdflatex and xelatex. Please notice that you may need to run it as administrator.

Resources