How to define reference_docx in rmarkdown file using pandoc 2.1 - r

I downloaded the latest version of RStudio and then upgraded to pandoc 2.1 because I wanted to control the custom table setting in the output .docx file.
However, in the previous version of pandoc with RStudio (1.9) the following YAML produced the correct .docx file:
---
title: "Report"
author: "Me"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
word_document:
reference_docx= ../support/word/rmd_styles.docx
toc: true
fig_caption: true
---
But when I upgraded to pandoc 2.1 (and verified it in RStudio console with):
> rmarkdown:::find_pandoc()
> as.list(rmarkdown:::.pandoc)
$version
[1] ‘2.1’
The reference to the .docx file in the YAML above no longer works and I get the following error:
--reference-docx has been removed. Use --reference-doc instead.
Try pandoc.exe --help for more information.
So when I switch reference_docx to reference_doc (not sure if that is correct?) I get the following error:
--reference-docx has been removed. Use --reference-doc instead.
Try pandoc.exe --help for more information.
Error: pandoc document conversion failed with error 2
In addition: Warning message:
running command '"C:/Users/Prevost~1.PRE/AppData/Roaming/local/bin/pandoc" +RTS -K512m -RTS Report.utf8.md --to docx --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output Report.docx --table-of-contents --toc-depth 3 --highlight-style tango --reference-docx "..\support\word\rmd_styles.docx"' had status 2
Execution halted
Hopefully I am just using the incorrect syntax in the YAML but I'm not sure what's going on. Any help is greatly appreciated!

I was having this issue with the rmarkdown package 1.6 and I solved it by updating to rmarkdown 1.8. You may do so by executing the following code
install.packages('rmarkdown')
and the loading it by executing
library(rmarkdown)

Related

Failed to compile test.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See test.log for more info. Execution halted

output file: test.knit.md
! pdflatex: warning: running with administrator privileges
! Sorry, but C:\Users\jjw11\AppData\Local\Programs\MIKTEX~1.9\miktex\bin\x64\pdflatex.exe did not succeed.
! The log file hopefully contains the information to get MiKTeX going again:
! C:\Users\jjw11\AppData\Local\MiKTeX\2.9\miktex\log\pdflatex.log
Error: Failed to compile test.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See test.log for more info.
Execution halted
I got this error message while I was trying to generate pdf file using r markdown.
How can I solve this? I installed tinytex using install.packages("tinytex")
I also tried tinytex::reinstall_tinytex(). But I got this error message
tinytex::reinstall_tinytex()
Error in system2("tlmgr", args, ...) : '"tlmgr"' not found
In addition: Warning message:
In tlmgr(c("info", "--list", "--only-installed", "--data", field, :
TeX Live does not seem to be installed. See https://yihui.name/tinytex/.
I installed tinytex using "tinytex::install_tinytex()".
When I installed tinytex using "tinytex::install_tinytex()", I got warning which implies other Latex distribution was already installed.
I tried to generate pdf file after I installed tinytex using "tinytex::install_tinytex()".
But this time I got this error message.
output file: test.knit.md
"C:/PROGRA~1/Pandoc/pandoc" +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.tex --template "C:\PROGRA~1\R\R-35~1.3\library\RMARKD~1\rmd\latex\DEFAUL~3.TEX" --highlight-style tango --pdf-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in" --variable "compact-title:yes"
! Package inputenc Error: Unicode character ??(U+B144)
(inputenc) not set up for use with LaTeX.
Try other LaTeX engines instead (e.g., xelatex) if you are using pdflatex. For R Markdown users, see https://bookdown.org/yihui/rmarkdown/pdf-document.html
Error: Failed to compile test.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See test.log for more info.
In addition: Warning message:
In grepl("==> Fatal error occurred", x[i], fixed = TRUE) :
input string 1 is invalid in this locale
Execution halted
Do I have to uninstall other Latex distributions?
Then, how can I uninstall other Latex distributions?
I've solved my problem.
First, I had to install Tex distribution.
I could install Tex distribution by using tinytex::install_tinytex().
Second, I was using CJK(Chinese, Japanese, Korean) characters.
so I had to use different latex engine.
In addition, I had to set mainfont which contains my language(korea) in the YAML header.
I attach YAML header which solved my problem.
title: "Untitled"
author: "jjw"
date: "2019년 10월 17일"
output:
pdf_document :
latex_engine : xelatex
mainfont : NanumGothic
I was getting the same error after installing MikTex. I then re-started RStudio and it worked for me.
I also had the same error but it was fixed after I used the following code
tinytex::install_tinytex() it was fixed.
But first I had Miktex installed which gave a total different error so I unstaulted it first then I run the code above and problem solved.

Error Message "latex-engine has been removed" when knitting to pdf

I'm working on a Mac and have an R script file that I would like to compile to a PDF document. I have inserted the following at the top for the output:
#' beamer_presentation:
#' toc: yes
#' slide_level: 2
#' latex_engine: xelatex
Once I press command+shift+k to knit this file, I get the following error message:
--latex-engine has been removed. Use --pdf-engine instead.
Try pandoc --help for more information.
Error: pandoc document conversion failed with error 2
Execution halted
I did download mactex and pandoc 2.0.1.1. from the pandoc website. Some of my colleages are able to knit the file, so I'm rather sure that the content is not the issue.
This issue has been reported and fixed in the current development version of rmarkdown, which you can install with:
if (!require("devtools")) install.packages("devtools")
devtools::install_github("rstudio/rmarkdown")

RMarkdown / pandoc fails to knit Pdf with latex color commands

Mac Os: 10.11.6
R version: 3.3.1
MacTex: 2016 / TexLive: 6.2.2
RMarkdown: 1.0.9014
Knitr: 1.14
Pandoc: 1.17
RMarkdown fails to knit PDF when latex commands such as:
\textcolor{blue}{Character String}
are present in the .rmd file. The error output is:
/usr/local/bin/pandoc +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.pdf --template ~/R/3.3/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --latex-engine /Library/TeX/texbin/pdflatex --variable graphics=yes --variable 'geometry:margin=1in'
! Undefined control sequence.
l.105 \textcolor
pandoc: Error producing PDF
Error: pandoc document conversion failed with error 43
Execution halted
Inclusion of an r code chunk with echo = TRUE such as:
```{r, echo = TRUE}
# I am a glitch
```
in the .rmd file allows for the successful creation of the PDF document.
If all r code chunks in the .rmd file are set with echo = FALSE or equivalent statements, the PDF file will not knit regardless of latex engine used if latex commands such as /textcolor are present. If only latex commands such as \begin{tabular}, many, etc… are used the error is not present.
Addition of “header-includes: \usepackage{color}” to the YAML header, as seen below, addresses the issue. However, it is unclear why insertion of an “echo = TRUE” R-code chunk also resolves the issue.
---
title: "test"
output: pdf_document
header-includes: \usepackage{color}
---
Interestingly, with a previous version of the R-Studio suite, as see below, inclusion of “header-includes: \usepackage{color}” in the YAML header, did not appear necessary prior to use of commands such as "\textcolor{blue}{Character String}" in the .rmd file.
Mac OS: 10.10.5
R Version: 3.2.2
MacTex: 2014 / TexLive: 6.2.0
Rmarkdown: 1.0
Knitr: 1.13
Pandoc: 1.13.1

Error: pandoc document conversion failed with error 43 Windows 7 R studio

I have search the answers in the forum, but they dont seem to work.
I am knitting a pdf document in Rstudio using the knitr package. I am using Windows 7 and Rstudio.
pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
In addition: Warning message:
running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" PA1_template.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output PA1_template.pdf --template "C:\R\Library\rmarkdown\rmd\latex\default.tex" --highlight-style tango --latex-engine pdflatex --variable "geometry:margin=1in"' had status 43
Execution halted
Thanks,
Luis
I had the same issue but on Linux using the latest rmarkdown package and pandoc 1.13. In essence it seems like pdflatex does not work with the output generated by pandoc - you need to replace the latex-engine pdflatex with xelatex (part of TeXLive)
For rmarkdown my solution was to edit the file
rmarkdown/templates/tufte_handout/resources/tufte-common.def
and replace the line
\typeoutbool{pdfatex}{#tufte#pdf}
with
\typeoutbool{xelatex}{#tufte#pdf}
Then xelatex will be used instead of pdflatex to generate pdf's with rmarkdown
I faced the same issue, here are the steps I took to solve the problem:
install devtools in Rstudio (install.packages(devtools))
install rmarkdown (devtools::install_github("rstudio/rmarkdown"))
fix the files tufte-common.def and tufte-handout.tex in ~/R/x86_64-pc-linux-gnu-library/3.2/rmarkdown/rmarkdown/templates/tufte_handout/resources/
If the rmarkdown installation did not go smoothly this way then do it like this (devtools::install_github("git://github.com/rstudio/rmarkdown"))
In tufte-common.def do the following:
Add this line
\typeoutbool{xelatex}{#tufte#pdf}
uncomment this line
\typeoutbool{xelatex}{#tufte#xetex} remember % is used to uncomment latex
Add the following lines in tufte-handout.tex:
% UTF encoding
\usepackage[utf8]{inputenc}
When I tried to compile a document I still got the following error (! Font \XeTeXLink#font=pzdr at 0.00002pt not loadable: Metric (TFM) file or ins talled font not found.), I tackled it by installing texlive-fonts-recommended:
sudo apt-get install texlive-fonts-recommended
I had a similar problem. Telling knitr where to find the pdf-engine was necessary even though I had it on the windows path. Here is the header of the knitr.Rmd-document, that solved the problem for me:
---
title: "XXX"
author: "XXX"
date: '2016-11-28'
output:
pdf_document:
keep_tex: yes
pandoc_args:
- --latex-engine
- C:/Program Files/MiKTeX 2.9/miktex/bin/x64/pdflatex.exe
toc: yes
---

RStudio on OSX Markdown Preview PDF Gives Pandoc Error 43

I am on OSX Mavericks and have the newest version of RStudio (0.98.994), R (3.1.1) and MacTex 2014 (25 May 2014). All R packages have been updated. When I try to preview a markdown file as a PDF, I get the following error:
/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc README.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output README.pdf --template /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rmarkdown/rmd/latex/default.tex --highlight-style tango --latex-engine pdflatex --variable geometry:margin=1in
pandoc: Error producing PDF from TeX source.
Error: pandoc document conversion failed with error 43
Execution halted
I don't know what I have done wrong but this simply doesn't work.
I was getting this same error while trying to use a markdown template, papaja, on a mac (OS X), even though I had the full version of MacTex installed.
What ultimately fixed the problem for me was installing pandoc on my computer: https://github.com/jgm/pandoc/releases/
As soon as I installed it, I was able to knit the markdown file into a PDF. Hopefully, this solution works for you, too!
You might need to install framed latex package. see the following links
PDF rendering in Rmarkdown2/
https://github.com/rstudio/rmarkdown/issues/39

Resources