[My environment: Win 7 Pro / R 3.2.1 / knitr_1.12.3 / R Studio Version 0.99.892]
I am trying to write an article in .Rmd format using R Studio, Knit -> PDF, and I've been following http://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html for details of how to get pandoc and pandoc-citeproc to produce a References section and citations
in the text.
My BibTeX references are in several different .bib files, which, when using
LaTeX in .Rnw files, are all found in my local texmf tree via
\bibliography{statistics, graphics}
I can't seem to make this work with pandoc-citeproc. My YAML header
has the following, that works for one .bib file, as long as it is
in the same directory as the source .Rmd file:
---
title: "Notes on Testing Equality of Covariance Matrices"
author: "Michael Friendly"
date: '`r format(Sys.time(), "%B %d, %Y")`'
output:
pdf_document:
fig_caption: yes
keep_tex: yes
number_sections: yes
csl: apa.csl
bibliography: statistics.bib
---
Following advice in the link given above, I tried:
bibliography: [statistics.bib,graphics.bib]
this gives:
pandoc-citeproc.exe: "stdin" (line 50, column 12):
unexpected ":"
expecting letter, digit, white space or "="
pandoc.exe: Error running filter pandoc-citeproc
Filter returned error status 1
[Edit: For completeness, I show the generated pandoc command, where it looks like both .bib files are passed correctly]:
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS EqCov.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output EqCov.pdf --template "C:\R\R-3.2.1\library\rmarkdown\rmd\latex\default-1.15.2.tex" --number-sections --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in" --bibliography statistics.bib --bibliography graphics.bib --filter pandoc-citeproc
output file: EqCov.knit.md
So do all the following forms:
bibliography: ["statistics.bib","graphics.bib"]
bibliography:
- "statistics.bib"
- "graphics.bib"
bibliography:
- statistics.bib
- graphics.bib
Ideally, I'd like to be able to use one of the following forms, and not have to copy the .bib files to the document directory.
bibliography: ["C:/Dropbox/localtexmf/bibtex/bib/statistics.bib","C:/Dropbox/localtexmf/bibtex/bib/graphics.bib"]
bibliography:
- "C:/Dropbox/localtexmf/bibtex/bib/statistics.bib"
- "C:/Dropbox/localtexmf/bibtex/bib/graphics.bib"
For the record: I raised this as an issue for pandoc-citeproc at https://github.com/jgm/pandoc-citeproc/issues/220
It turns out that there were problems in how pandoc-citeproc handles some characters in #{string={}} and non-ASCII characters in .bib files, so what I was trying now works, with hard-coded pathnames, in all the forms I tried.
To make it work more like processing of .Rnw files via Latex/bibtex it would be nice to be able to use something like
bibliography:
- `r system(kpsewhich statistics.bib)`
- `r system(kpsewhich graphics.bib)`
Those commands do find the right files in an R session, but not from a YAML header.
Related
After I updated MikTex to the latest version, my Rmd files don't compile anymore. I installed tinytex, reinstalled miktex, R and RStudio several times. I use some newcommands like \C, \G etc. in a tex document which I include in my Rmd file. I use windows 10, the latest versions of R, RStudio and Miktex.
I asked a colleague (who had no compiling issues) to update his MikTex as well. After updating his MikTex, he had the same issue.
Here is the Rmd code:
---
documentclass: scrartcl
fontsize: 11pt
output:
pdf_document:
includes:
in_header: commands.tex
---
This is an example:
\begin{itemize}
\item hello
\item world
\end{itemize}
And here is the tex code:
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{icomma}
\usepackage[right,official]{eurosym}
\usepackage{hyperref}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage[shortlabels]{enumitem}
\usepackage{setspace}
\singlespacing
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Seitenformat und Layoutparameter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\hbadness=1000
\tolerance=10000
\voffset-2.80cm
\hoffset-2.60cm
\topmargin1.50cm
\headheight0.65cm
\headsep1.0cm
\topskip0cm
\textheight24.00cm
\footskip1.5cm
\footnotesep11pt
\evensidemargin2.50cm
\oddsidemargin2.50cm
\textwidth16cm
%\parindent0cm
%\parskip1.5ex plus0.5ex minus 0.5ex
% simple letters
\newcommand{\A}{{\mathbb A}}
\newcommand{\B}{{\mathbb B}}
\renewcommand{\C}{{\mathbb C}}
\newcommand{\D}{{\mathbb D}}
\newcommand{\E}{{\mathbb E}}
And I get:
processing file: example1.Rmd
|......................................................................| 100%
ordinary text without R code
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS example1.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output example1.tex --lua-filter "C:\Users\saski\Documents\R\win-library\4.0\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\saski\Documents\R\win-library\4.0\rmarkdown\rmarkdown\lua\latex-div.lua" --self-contained --highlight-style tango --pdf-engine pdflatex --include-in-header commands.tex --variable graphics
output file: example1.knit.md
! LaTeX Error: Command \C undefined.
Fehler: LaTeX failed to compile example1.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See example1.log for more info.
Ausführung angehalten
The best solution would be to avoid one letter macro names
your code no longer works because \C is now only defined by hyperref under certain circumstances, see https://tex.stackexchange.com/questions/582625/command-c-already-defined-and-the-hyperref-package/582630#582630 for more information
If you use \newcommand instead of \renewcommand you can see that the error vanishes
% simple letters
\newcommand{\A}{{\mathbb A}}
\newcommand{\B}{{\mathbb B}}
\newcommand{\C}{{\mathbb C}}
\newcommand{\D}{{\mathbb D}}
\newcommand{\E}{{\mathbb E}}
(but you should still not do that, use some other macro names instead if the one letter names)
Conclusion: don't use one letter macro names
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.
Can I write a YAML header to produce multiple output formats for an R Markdown file using knitr? I could not reproduce the functionality described in the answer for the original question with this title.
This markdown file:
---
title: "Multiple output formats"
output:
pdf_document: default
html_document:
keep_md: yes
---
# This document should be rendered as an html file and as a pdf file
produces a pdf file but no HTML file.
And this file:
---
title: "Multiple output formats"
output:
html_document:
keep_md: yes
pdf_document: default
---
# This document should be rendered as an html file and as a pdf file
produces an HTML file (and an md file) but no pdf file.
This latter example was the solution given to the original question. I have tried knitting with Shift-Ctrl-K and with the Knit button in RStudio, as well as calling rmarkdown::render, but only a single output format is created, regardless of the method I use to generate the output file.
Possibly related, but I could not identify solutions:
How do I produce R package vignettes in multiple formats?
Render all vignette formats #1051
knitr::pandoc can't create pdf and tex files with a single config #769
Multiple formats for pandoc #547
An allusion to multiple output format support in a three year old RStudio blog post
Using R version 3.3.1 (2016-06-21), knitr 1.14, Rmarkdown 1.3
I actually briefly mentioned in Render all vignette formats #1051 and you missed it:
rmarkdown::render('your.Rmd', output_format = 'all')
It is documented on the help page ?rmarkdown::render.
Notwithstanding Yihui Xie's authoritative answer, and with due respect to the author of a great package, there are many cases in which output_format = 'all' is sub-optimal.
One of the issues that this solution raises is that the R script is re-processed from scratch for each format. Proof:
rmarkdown::render("new.Rmd", output_format = c("html_document", "pdf_document"))
processing file: new.spin.Rmd
|....................... | 33%
ordinary text without R code
|............................................... | 67%
label: unnamed-chunk-1
|......................................................................| 100%
ordinary text without R code
output file: new.knit.md
"C:/Users/fabrn/AppData/Local/Pandoc/pandoc" +RTS -K512m -RTS new.utf8.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output new.html --lua-filter "C:\Users\fabrn\R\win-library\4.0\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\fabrn\R\win-library\4.0\rmarkdown\rmarkdown\lua\latex-div.lua" --email-obfuscation none --self-contained --standalone --section-divs --template "C:\Users\fabrn\R\win-library\4.0\rmarkdown\rmd\h\default.html" --no-highlight --variable highlightjs=1 --variable "theme:bootstrap" --include-in-header "C:\Users\fabrn\AppData\Local\Temp\RtmpW6Vban\rmarkdown-str3490247b1f1e.html" --mathjax --variable "mathjax-url:https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
Output created: new.html
processing file: new.spin.Rmd
|....................... | 33%
ordinary text without R code
|............................................... | 67%
label: unnamed-chunk-1
|......................................................................| 100%
ordinary text without R code
output file: new.knit.md
"C:/Users/fabrn/AppData/Local/Pandoc/pandoc" +RTS -K512m -RTS new.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output new.tex --lua-filter "C:\Users\fabrn\R\win-library\4.0\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\fabrn\R\win-library\4.0\rmarkdown\rmarkdown\lua\latex-div.lua" --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --variable "geometry:margin=1in"
This really is an issue when it comes to processing big data.
In real-world examples, I usually use latex output as a single rmarkdown::render output, then reprocess the .tex files using pandoc or similar tools (like prince for pdf). So my workflow is like:
rmarkdown::render('new.R', output_format = 'latex_document')
lapply(c("html", "pdf", ...),
function(form) rmarkdown::pandoc_convert("new.tex", output=paste0("new.", form)))
The bottom line is: all depends on your data. If small, output_format='all' is straightforward.
If big, you are better off with a common-ground format (latex is a good choice but html may be better in some cases) as an input to conversion tools.
I'm trying to get a watermark image like here:
How to add a watermark image on rmarkdown?
I almost did it, but as I wrote on my original question the background.png image that the \includegraphics get comes from C:\Program Files (x86)\MiKTeX 2.9\tex\plain\present
I'm currently using my Latex code from an external file using the follwing at beginning of my .Rmd:
output:
pdf_document:
includes:
in_header: header.tex
And in header.tex I'm using the following code:
\usepackage{eso-pic,graphicx,transparent}
\AddToShipoutPictureFG{
\put(0,0){%
\parbox[b][\paperheight]{\paperwidth}{%
\centering
{\transparent{0.3} \includegraphics[width=\paperwidth,height=\paperheight,%
keepaspectratio]{background.png}}%
}
}
}
But I just can't get the background.png from where my .tex file is (that is the same that my .Rmd file is).
How I tell to my .tex file get this image from the relative path to my .tex?
--EDIT--
I'm using the render function from rmarkdown to make the report, follow is a screenshot from the insides of my folder with .Rmd, the .tex file and the error when I try to insert a test.png:
"It works for me." Here is a minimal Rmarkdown file, trimmed down from one of the templates offered by RStudio:
---
title: "Demo"
author: "Dirk"
date: "October 3, 2016"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. We include one figure
\includegraphics{Rlogo.png}
La fin.
I can hit the knit button just fine, or run this by hand:
/tmp$ cat includeDemo.Rmd
---
title: "Demo"
author: "Dirk"
date: "October 3, 2016"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. We include one figure
\includegraphics{Rlogo.png}
La fin.
/tmp$ Rscript -e 'rmarkdown::render("includeDemo.Rmd")'
processing file: includeDemo.Rmd
|...................... | 33%
ordinary text without R code
|........................................... | 67%
label: setup (with options)
List of 1
$ include: logi FALSE
|.................................................................| 100%
ordinary text without R code
output file: includeDemo.knit.md
/usr/bin/pandoc +RTS -K512m -RTS includeDemo.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output includeDemo.pdf --template /usr/local/lib/R/site-library/rmarkdown/rmd/latex/default-1.15.2.tex --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable 'geometry:margin=1in'
Output created: includeDemo.pdf
/tmp$
Maybe something is playing tricks with you by switching from the current directory to a temporary processing directory. In which an (icky!!) absolute path may help...
I just did it.
The problem were on MiKTeX for Windows.
I just followed the steps on this answer, remembering to assure that the folder is TDS-compliant (with a tex folder in it), and after I just put the image on the tex folder.
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.