include Rmarkdown pdf output code into a seperate latex theisis tex file - latex

I am trying to write a report.tex theists using TexMAKER,and I need to include a lot of r,
So I run my chunk code file with this preamble in Rmarkdow
title: "rcode"
author: ".."
date: "..."
output:
pdf_document:
keep_tex: yes
fig_caption: yes
html_document: default
then include the rcode.pdf output file in my original report.tex file using the command \includepdf[]{rcode.pdf}
this method is not so good because the page numbering in my report.pdf gets mixed up with the numbering of the Rmardown pdf output rcode.pdf,
So I am wondering if there is a new way to extract the rcode.tex code then include it in my report.tex file ?
Or is the better way just to start wring all of the theisis report in the rmardown file with out having any Latex complications ?
thanks for the help

Related

Repeat Title and Date R Markdown PDF

I am struggling what what is likely a trivial markdown matter. I am hoping to avoid YAML and additional header templates and such if I can. So my question is straightforward and I welcome your feedback. For an R Markdown knitted as a PDF, how can I repeat the title and date on each printed page?
Alternatively I am happy to use headers using the '#' syntax. But if I can use the title parameters that would be preferred.
The Header thus far:
---
title: "Dashboard"
date: '`r paste(Sys.Date(), " to ", Sys.Date()+14)`'
output:
pdf_document:
latex_engine: xelatex
mainfont: Calibri
geometry: margin=1cm
classoption: landscape
params:
set_title: !r test_title
header-includes:
- \usepackage{titling}
- \pretitle{\begin{flushleft}\huge}
- \posttitle{\end{flushleft}}
- \preauthor{\begin{flushleft}}
- \postauthor{\end{flushleft}}
- \predate{\begin{flushleft}\large}
- \postdate{\end{flushleft}}
---
From the rmarkdown cookbook:
When a Rmd document is compiled, all of its metadata in the YAML section
will be stored in the list object rmarkdown::metadata. You can use this object
in your R code. For example, rmarkdown::metadata$title gives you the title
of the document.

Calligra font with RMarkdown

This is my Rmarkdown code:
---
title: "My Title"
header-includes:
- \usepackage{calligra}
- \usepackage[T1]{fontenc}
output:
pdf_document:
latex_engine: xelatex
---
# Section 1
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
I was studying the best way to change fonts in Rmarkdown. In texlive the installed calligra package appears and calligra-type1 also.
When I run the script with the calligra package it generates the pdf but the font does not match the calligra font.
And when I run the script for calligra-type1 the pdf is not even generated.
Any help, guys?
The calligra.sty does not set-up the Calligra as default font, but you can do so by adding
\renewcommand{\rmdefault}{calligra}
to header-includes.
BTW, there is no need to call fontenc.sty, since calligra.sty does so already. In addition, using xelatex is not necessary here.

Apply knitr option function in "before_body" when using Rmarkdown to compile PDF

As question, I am using knitr option (i.e. include=temp.switch) to compile multiple reports based on the value given to a "switch" (i.e. temp.switch), this are working well for the content, but I would like to use similar function to modify the cover page of the report, which is stored in the tex file read in yaml, like the one below:
---
output:
pdf_document:
# template: template.tex
number_sections: true
keep_tex: true
includes:
in_header: preamble.tex
before_body: doc-prefix.tex
papersize: a4
editor_options:
chunk_output_type: console
---
Can anyone tell me how to make the doc-prefix.tex "conditional" based on the value of the "switch"? Thanks!

RMarkdown pdf document chunk output exceeds page margins

While I am knitting a document as a PDF using RMarkdown some code chunk outputs exceeds the page margins as seen on the pic.
Any ideas to fix this?
I think your problem could be the typo, not widt
options(width = 60) ## I usually use 50 -60
Many functions do not respond correctly to the page size config. So to solve such an issue, you have to include the following configuration for the output file.
output:
pdf_document:
pandoc_args: --listings
includes:
in_header: preamble.tex
create the file preamble.tex in the same folder where the Rmarkdown file exists, and its content is the following:
\lstset{
breaklines=true
}
For more information, check https://bookdown.org/yihui/rmarkdown-cookbook/text-width.html.

Pandoc Error producing PDF with markdown body text and YAML metadata file

I'm running the following Pandoc 2.0.3 command on the Mac Terminal command line:
pandoc one.md "metadata.yaml" -o two.pdf
This should take the markdown file one.md and output two.pdf using the yaml file metadata.yaml, a minimal version of which is:
---
header-includes:
- \usepackage{fancyhdr}
...
This Pandoc run produces a PDF as expected for the following version of one.md:
# Report
However, it fails to produce a PDF for the following version of one.md, which contains body text:
# Report
Lorem.
The resulting error message is:
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.65 header-includes: - \usepackage
I don't understand why including that one word creates a failure.
Your one.md likely doesn't end with a newline. Pandoc concatenates all input files, adding a single newline between files. So the resulting input will be:
# Report
Lorem.
---
header-includes:
- \usepackage{fancyhdr}
...
As a result, the opening dashes of the YAML block are interpreted as underlines for Lorem., which is then read as a second-level header. This doesn't happen if the line above the --- dashes is an ATX-style header.
Just add a newline to the end of one.md and everything should work the way you expected.

Resources