I'm trying to knit the mwe below to pdf using rstudio (1.2.5019)
---
title: "Test"
author: "Me"
output:
pdf_document:
fig_caption: yes
keep_tex: yes
fig_crop: yes
---
This should be cropped
```{r}
library(knitr)
```
```{r named-chunk}
plot(x <- 0:100, dbinom(x, size=100, prob=0.6), type='l',
main="Not cropped", xlab="Looks good", ylab="Nok")
```
The output pdf looks fine except the plot has not been cropped with pdfcrop.
Here's the log output.
processing file: cropping.Rmd |..................
| 25% ordinary text without R code
|...................................
| 50% label: unnamed-chunk-1
|....................................................
| 75% ordinary text without R code
|......................................................................|
100% label: named-chunk
output file: cropping.knit.md
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS
cropping.utf8.md --to latex --from
markdown+autolink_bare_uris+tex_math_single_backslash --output
cropping.tex --self-contained --highlight-style tango --pdf-engine
pdflatex --variable graphics --lua-filter
"C:/Users/marti/Documents/R/win-library/3.6/rmarkdown/rmd/lua/pagebreak.lua"
--lua-filter "C:/Users/marti/Documents/R/win-library/3.6/rmarkdown/rmd/lua/latex-div.lua"
--variable "geometry:margin=1in"
Output created: cropping.pdf
pdfcrop works just fine from my command line but isn't called by rstudio. It is also located by rstudio.
Sys.which('pdfcrop')
pdfcrop
"C:\texlive\2019\bin\win32\pdfcrop.exe"
What am I missing?
This actually solved it.
``` {r crop-hook,cache=FALSE}
knit_hooks$set(crop=hook_pdfcrop)
```
```{r named-chunk, crop=TRUE}
plot(x <- 0:100, dbinom(x, size=100, prob=0.6), type='l',
main="Not cropped", xlab="Looks good", ylab="Nok")
```
As far as I understood from the documentation this shouldn't be necessary?
Install pdfcrop via livetex or miktex --- the one you are using to write latex documents.
Related
I'm trying to create a book with bookdown as pdf. It works well creating an EPUB file.
My YAML is this:
---
title: "Title Here"
subtitle: "Subtitle here"
author: "me"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
bibliography: [book.bib]
biblio-style: apalike
link-citations: yes
description: "description goes here."
cover-image: "cover.png"
lang: "es"
always_allow_html: true
output:
pdf_document:
latex_engine: xelatex
pdf_document2:
latex_engine: lualatex
---
At some point in chapter 4 I have a Japanese letter, U+305B.
I've tried creating the pdf book with:
bookdown::render_book("index.Rmd", output_format = bookdown::pdf_document2())
and
bookdown::render_book("index.Rmd", output_format = bookdown::pdf_book())
Both of them complain that:
! Package inputenc Error: Unicode character せ (U+305B)
(inputenc) not set up for use with LaTeX.
and recommend me to check this part of the rmarkdown cookbook. From there is where I took the 4 last lines of the YAML preamble.
I couldn't help but noticing that the call to pandoc is taking pdflatex as the pdf-engine (see third-to-last line):
/usr/lib/rstudio/bin/pandoc/pandoc +RTS -K512m -RTS myFileName.knit.md --to latex
--from markdown+autolink_bare_uris+tex_math_single_backslash
--output herramientasBasicasMejoramiento.tex
--lua-filter /usr/local/lib/R/site-library/bookdown/rmarkdown/lua/custom-environment.lua
--lua-filter /usr/local/lib/R/site-library/rmarkdown/rmarkdown/lua/pagebreak.lua
--lua-filter /usr/local/lib/R/site-library/rmarkdown/rmarkdown/lua/latex-div.lua
--metadata-file /tmp/RtmpAbwGga/file565f3d087e3c --self-contained
--table-of-contents --toc-depth 2 --number-sections
--highlight-style tango --pdf-engine pdflatex --variable graphics
--wrap preserve --variable tables=yes
--standalone -Mhas-frontmatter=false --citeproc
I'm working in Ubuntu and have installed both texlive and tinytex.
whereis xelatex
xelatex: /home/gp/bin/xelatex /usr/local/texlive/2019/bin/x86_64-linux/xelatex
There is an unanswered question with a problem that looks similar.
What am I doing wrong, and what can I do to make it work?
You need to specify the output format in a way that will see your latex_engine argument, e.g.
bookdown::render_book("index.Rmd", output_format = "pdf_document2")
(naming one of the output formats from your YAML), or
bookdown::render_book("index.Rmd",
output_format = bookdown::pdf_document2(latex_engine = "xelatex"))
(specifying it independently).
I'm trying to include plots in a knitted Rmd pdf document, but the plots always come out cropped. Here's a small example of what I'm experiencing:
---
output:
pdf_document: default
---
```{r}
plot (cars)
```
```{r, fig.width=2}
plot (cars)
```
```{r, out.width='\\textwidth'}
plot (cars)
```
This Rmd produces a pdf that looks something like this (note the chopped off x axis labels):
Any ideas what causes this?
Software info:
knitr 1.23
pandoc 2.7.2
R 3.6.0
The call that compiles the document is
/usr/bin/pandoc +RTS -K512m -RTS rmdtest.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output rmdtest.tex --template /usr/lib/R/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --pdf-engine pdflatex --variable graphics=yes --variable 'geometry:margin=1in' --variable 'compact-title:yes'
I'm writing a report on Rmarkdovn but when you try to compile - pandoc_args options ignored when compile pdf.
I find this question:
Is it possible to include svg image in pdf document rendered by rmarkdown?
But it does not work because --latex-engine-opt replaced by --pdf-engine-opt. I replaced, but also did not work.
Compilation command:
Rscript -e "rmarkdown::render('test.rmd')"
test.rmd
---
title: Test
papersize: a4paper
output:
pdf_document:
latex_engine: pdflatex
pandoc_args: [
--pdf-engine-opt, -shell-escape,
--pdf-engine-opt, -interaction=nonstopmode]
header-includes:
- \usepackage{minted}
---
Output:
processing file: test.rmd
|................................ | 50%
ordinary text without R code
|.................................................................| 100%
label: unnamed-chunk-1 (with options)
List of 1
$ engine: chr "python"
output file: test.knit.md
/usr/bin/pandoc +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.tex --template /home/renesat/R/x86_64-pc-linux-gnu-library/3.5/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --pdf-engine pdflatex --variable graphics=yes --pdf-engine-opt --shell-escape --pdf-engine-opt -interaction=nonstopmode --variable 'geometry:margin=1in' --variable 'compact-title:yes'
! Package minted Error: You must invoke LaTeX with the -shell-escape flag.
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 can use knitr -> pandoc -> xelatex, but it would be more convenient to use YAML header.
R Markdown documents are compiled to PDF via tinytex::latexmk(). To enable the -shell-escape option for your LaTeX engine, you may set the global option tinytex.engine_args, e.g., add this code chunk to your document:
```{r, include=FALSE}
options(tinytex.engine_args = '-shell-escape')
```
See the help page ?tinytex::latexmk for more information.
The LaTeX engine is called by tinytex::latexmk() instead of Pandoc, so the Pandoc argument --pdf-engine-opt won't work.
I am using the fabulous knitr() package in R to render rmarkdown to PDF via LaTeX. Since the default syntax highlighting is not what I want, and the LaTeX environment listings has severe limitations in highlighting R code, I wanted to use the LaTeX minted package, simply embedding the knitted code into the minted environment.
Did anybody make it work to use the LaTeX package minted with knitr?
I already am failing loading the minted package with a weird error :D
---
title: "Test"
author: "me"
date: "10. March 2019"
output:
pdf_document
header-includes:
- \usepackage{minted}
---
```{r}
library(knitr)
minted_hook = function(x, options) { paste0("\\begin{minted}{R}", x, "\\end{minted}\n") }
knit_hooks$set(
source = minted_hook,
warning = minted_hook,
message = minted_hook,
error = minted_hook
)
```
# Test
```{r}
# this is a comment
a <- 1:10
a
```
As soon as I load minted I get the error
"C:/PROGRA~1/PANDOC~1.1/pandoc" +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.tex --template "[path not shown]\R\WIN-LI~1\3.5\RMARKD~1\rmd\latex\DEFAUL~3.TEX" --highlight-style tango --pdf-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in" --variable "compact-title:yes"
tlmgr search --file --global "/(.sty"
Fehler in grep(paste0("/", x[j], "$"), l)
> invalid regular expression '/(.sty$', Reason 'Missing ')
I did install pygminted as outlined here.
I wanted to use RStudio (Version 0.99.903) and knitr to convert a .Rmd file (please see below) to a PDF file.
---
title: "test"
output: pdf_document
---
Roses are \textcolor{red}{red}, violets are \textcolor{blue}{blue}.
When I run "Knit PDF" I got the following error message:
processing file: test.Rmd
output file: test.knit.md
! Undefined control sequence.
l.87 Roses are \textcolor
pandoc.exe: Error producing PDF
Error: pandoc document conversion failed with error 43
In addition: Warning message:
running command '"C:/PROGRA~2/Pandoc/pandoc" +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.pdf --template "C:\Users\fuq\R\R-3.3.1\library\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"' had status 43
Execution halted
However, if I add a R code chunk anywhere in that .Rmd file, for example:
---
title: "test"
output: pdf_document
---
Roses are \textcolor{red}{red}, violets are \textcolor{blue}{blue}.
```{r}
summary(cars)
```
I could then successfully get a PDF that I expected.
But what was weird was that if set echo=FALSE in the above .Rmd file (see below)
---
title: "test"
output: pdf_document
---
Roses are \textcolor{red}{red}, violets are \textcolor{blue}{blue}.
```{r, echo=FALSE}}
summary(cars)
```
Then again, I got the same error message:
! Undefined control sequence.
l.87 Roses are \textcolor
pandoc.exe: Error producing PDF
Error: pandoc document conversion failed with error 43
In addition: Warning message:
running command '"C:/PROGRA~2/Pandoc/pandoc" +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.pdf --template "C:\Users\fuq\R\R-3.3.1\library\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"' had status 43
Execution halted
I worked on Windows 7 64bit, and have got the latest version of MiKTex. Please could anyone give me some idea what was going wrong?
You have to include the package color, then it works. I don't know why this works just with an R chunk in it. But this solution will solve this problem:
---
title: "test"
output: pdf_document
header-includes: \usepackage{color}
---
Roses are \textcolor{red}{red}, violets are \textcolor{blue}{blue}.
If you want to knit colors to HTML, you have to use this code:
---
title: "test"
output: html_document
---
Roses are <span style="color:red">red</span>,
violets are <span style="color:blue">blue</span>.