I am a beginner in R and I need to export R markdown file into pdf. I downloaded MikTex, TexStudio and uploaded the package tinytex. I tried to plug the code \begin{document} but it doesn't seem to be working, so I am not sure if I am plugging it in the right space.
output:
pdf_document:
fig_caption: yes
fig_height: 6
fig_width: 7
number_sections: yes
toc: yes
toc_depth: 3
html_document: default
word_document:
toc: yes
toc_depth: '3'
header-includes: |
```{=latex}
\usepackage{fvextra}
\begin{document}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{
showspaces = false,
showtabs = false,
breaklines,
commandchars=\\\{\}
always_allow_html: yes
There are a couple of syntax errors:
output: should not be indented. This is a parent key for pdf_document: etc.
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{ is missing the closing }
you don't actually need to escape to raw latex in the header-includes:
Don't use \begin{document} in the preamble.
"I downloaded [...] TexStudio" -> TeXstudio is not really great for editing rmd files. I suggest to have a look at Rstudio instead.
---
output:
pdf_document:
fig_caption: yes
fig_height: 6
fig_width: 7
number_sections: yes
toc: yes
toc_depth: 3
keep_tex: true
html_document: default
word_document:
toc: yes
toc_depth: '3'
header-includes: |
\usepackage{fvextra}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{
showspaces = false,
showtabs = false,
breaklines,
commandchars=\\\{\}
}
always_allow_html: yes
---
test
Related
I got a problem when rendering a markdown document to pdf in VSC with the quarto extensions. A pdf document is created but it does not include the title and it does not use the specified font.
My .qmd file:
---
title: "Flood forecasting"
subtitle: "Termpaper 1 "
author: "Author"
bibliography: Termpaper1_literature.yaml
format:
pdf:
colorlinks: true
mainfont: Tahoma
sansfont: Tahoma
monofont: Tahoma
---
## Abstract
Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see <https://quarto.org>.
## Introduction
## Artificial Neural Networks
## Discussion
## References
::: {#refs}
:::
This is the output I get in the terminal:
➜ TERMPAPER1 Kopie git:(master) ✗ quarto preview "/Users/.../TERMPAPER1.qmd" -
-to pdf --no-browser --no-watch-inputs
pandoc
to: latex
output-file: TERMPAPER1.tex
standalone: true
pdf-engine: xelatex
variables:
graphics: true
tables: true
default-image-extension: pdf
metadata
documentclass: scrartcl
classoption:
- DIV=11
- numbers=noendperiod
papersize: letter
header-includes:
- '\KOMAoption{captions}{tableheading}'
block-headings: true
running xelatex - 1
This is XeTeX, Version 3.141592653-2.6-0.999994 (TeX Live 2022) (preloaded format=xelatex)
restricted \write18 enabled.
entering extended mode
running xelatex - 2
This is XeTeX, Version 3.141592653-2.6-0.999994 (TeX Live 2022) (preloaded format=xelatex)
restricted \write18 enabled.
entering extended mode
Output created: TERMPAPER1.pdf
And the pdf looks like this:
Thanks for helping!
Changing the latex engine doesn't result in anything sadly.
I have compiled an Rmd file that should knit to PDF, whereof the code is derived from another model which does knit to pdf. However, with the exact same yaml header parameters, the knitting defaults to HTML instead of pdf for the first model (When clicking 'knit to pdf'. I am using R version 3.6.1.
---
title: "Title"
subtitle: "Subtitle"
author:
- Piet en Henk
date: "`r format(Sys.time(), '%B %d, %Y')`"
abstract: "This document provides the description of the used R code for ...."
geometry: "left=1in, right=1in, top=1in, bottom=1in, headsep=0.4in"
output:
pdf_document:
highlight: zenburn
number_sections: true
toc: true
toc_depth: 2
header-includes:
- \usepackage{eso-pic}
- \usepackage{graphicx}
- \usepackage{transparent}
- \usepackage{fancyhdr}
- \usepackage{datetime}
- \usepackage{hyperref}
- \usepackage{float}
- \usepackage{amsmath}
- \usepackage{courier}
- \usepackage{placeins}
- \pagestyle{fancy}
- \numberwithin{figure}{section}
- \newdateformat{mydate}{\monthname[\THEMONTH] \THEYEAR}
- \renewcommand{\headrulewidth}{1pt}
- \renewcommand{\footrulewidth}{0.5pt}
- \fancyhead[L]{\includegraphics{Company.png}}
- \fancyfoot[RO]{Company}
- \fancyfoot[L]{Version 1.0}
---
```{=latex}
% Trigger ToC creation in LaTeX
\renewcommand{\baselinestretch}{0.7}\normalsize
\renewcommand{\baselinestretch}{1.2}\normalsize
\tableofcontents
```
\pagebreak
And the loggings from the Rmarkdown pane:
processing file: index.Rmd
|......................................................................| 100%
inline R code fragments
output file: index.knit.md
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS index.knit.md --to html4 --from markdown+autolink_bare_uris+tex_math_single_backslash --output index.html --lua-filter "C:\PROGRA~1\R\R-36~1.1\library\bookdown\RMARKD~1\lua\CUSTOM~1.LUA" --lua-filter "C:\PROGRA~1\R\R-36~1.1\library\RMARKD~1\RMARKD~1\lua\PAGEBR~1.LUA" --lua-filter "C:\PROGRA~1\R\R-36~1.1\library\RMARKD~1\RMARKD~1\lua\LATEX-~1.LUA" --metadata-file "C:\Users\mpruijs\AppData\Local\Temp\2\RtmpER5E5P\file2bec2a1279b1" --wrap preserve --standalone --section-divs --table-of-contents --toc-depth 3 --template "C:\PROGRA~1\R\R-36~1.1\library\bookdown\TEMPLA~1\GITBOO~1.HTM" --highlight-style pygments --number-sections --css style.css --include-in-header "C:\Users\mpruijs\AppData\Local\Temp\2\RtmpER5E5P\rmarkdown-str2bec4d551488.html" --mathjax
Output created: index.html
Warning message:
In as.POSIXlt.POSIXct(x, tz) : unable to identify current timezone 'C':
please set environment variable 'TZ'
I started using markdown together with pandoc a few weeks ago. I'm especially fond of the markdown editor writemonkey v.3! I have one slight problem with converting my .md to .pdf, and I it's caused by the first line in my document. The first line in the document (see below) is how you give the document a name in writemonkey.
name: seminarium 1
---
author: my name
date: 22 Augusti 2020
bibliography: testlibrary.bib
geometry:
- top=2.5cm
- bottom=2.5cm
- left=2.5cm
- right=2.5cm
pagesize: a4
font: Times New Roman
fontsize: 12pt
header-includes:
- \usepackage{setspace}
- \setstretch{1.0}
- \pagenumbering{gobble}
---
If I remove this first line, the pandoc conversion works like a charm. Otherwise I get this:
pandoc sem1.md -o sem1.pdf --bibliography library.bib -V lang=sv
Error producing PDF.
! LaTeX Error: Can be used only in preamble.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.78 \usepackage
Now - I realize that I've combined a YAML with LaTex code, I am hoping that my formatting is "bad" and that I might improve it so I don't have to remove the first line every time. Maybe tell Pandoc/LaTex to ignore the first line or make a separate .yaml file would help?
Ok! This what I did. Works great with Writemonkey. Just copy-paste in Notepad and save as a .ps1 file and run in Powershell!
CD C:\Users\username\Desktop\ppp2020 # Filepath of .md, .yaml and .bib
Get-Content cap.md -Encoding UTF8 | Select-Object -Skip 2 | Set-Content cap_temp.md -Encoding UTF8 # Removes the first line (name:) from markdown document
pandoc cap_temp.md default.yaml -o cap.pdf --bibliography library.bib -V lang=sv # converts .md to .pdf
Remove-Item 'C:\Users\username\Desktop\ppp2020\cap_temp.md' # This removes the tempfile
I am quite new with Knitr, and I am trying to write my first document "importing" some "\newcommand" from my latex files.
All my "\newcommand" are processed perfectly with the exception of those with "arguments".
For instance I have added the packages I normally use in latex:
header-includes:
-\usepackage{a4wide,amsmath,amsthm,epsfig,graphicx}
- \usepackage{amsmath,amsthm,amssymb}
- \usepackage{amsfonts}
- \usepackage{graphics}
- \usepackage{subfigure}
- \usepackage{dsfont}
- \usepackage{bbm}
- \usepackage{bm}
- \usepackage{xcolor}
- \usepackage{dcolumn}
- \usepackage{pstricks,fancyhdr,fancybox}
- \usepackage{dcolumn}
- \usepackage{bm}
But the following does not work
\newcommand{\PR}[1]{\bm{P}\left\{{#1}\right\}}
The error is
output file: newfile.knit.md
"../Documents/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS newfile.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output newfile.pdf --template "C:\Users\P14814\Documents\R\win-library\3.4\rmarkdown\rmd\latex\default-1.17.0.2.tex" --highlight-style tango --latex-engine pdflatex --variable graphics=yes --variable "geometry:margin=1in"
! Missing $ inserted.
<inserted text>
$
l.180 \newcommand{\PR}{[}1{]}\{\bm{P}
pandoc.exe: Error producing PDF
Error: pandoc document conversion failed with error 43
In addition: Warning message:
running command '"../Documents/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS newfile.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output newfile.pdf --template "C:\Users\P14814\Documents\R\win-library\3.4\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
Your help is very much appreciated!!
I strongly recommend you to put these commands in an external file, say, preamble.tex, and include it via the includes option.
output:
pdf_document:
includes:
in_header: preamble.tex
See Section 3.3.7.3 of the R Markdown book: https://bookdown.org/yihui/rmarkdown/pdf-document.html
Using header-includes is not entirely safe. Pandoc may mangle certain characters when generating the LaTeX output. If your Pandoc version is higher than 2.0 (check rmarkdown::pandoc_version()), you may use a raw LaTeX block to protect the LaTeX content, e.g.,
header-includes: |
```{=latex}
\usepackage{a4wide,amsmath,amsthm,epsfig,graphicx}
\usepackage{amsmath,amsthm,amssymb}
......
```
I have some Latex slides I want to put in an rmarkdown beamer presentation, e.g.
---
title: "Untitled"
author: "Me"
date: "8 November 2017"
output: beamer_presentation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
\section{First section}
\begin{frame}{List 1}
\begin{itemize}
\item Point A
\item Point B
\item Point C
\end{itemize}
\end{frame}
This returns an error:
"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS
presentation3.utf8.md --to beamer --from
markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash
--output presentation3.pdf --highlight-style tango --latex-engine pdflatex output file: presentation3.knit.md
! Missing \endgroup inserted.
\endgroup l.85 \end{frame}
pandoc.exe: Error producing PDF Fehler: pandoc document conversion
failed with error 43 Zusätzlich: Warnmeldung: Ausführung von Kommando
'"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS
presentation3.utf8.md --to beamer --from
markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash
--output presentation3.pdf --highlight-style tango --latex-engine pdflatex' ergab Status 43 Ausführung angehalten
How to fix this?