Use before_body in Rmarkdown for a html document - yaml

I want to add an image (an html file called "Logo.html") at the top of another html document.
for that i use "before_body":
I save my Logo.html in the same file as my Rmarkdown and i get the following error when "kniting" my rmd:
pandoc.exe: Logo.html: openFile: does not exist (No such file or directory)
is there a specific place to put my "Logo.html"? do you know what is incorrect in my code?
output:
html_document:
include:
before_body: Logo.html
fig_caption: true
code_folding: hide

You must be careful with the indentation and nesting of the YAML parameters.
This works for me:
---
output:
html_document:
includes:
before_body: Logo.html
fig_caption: true
code_folding: hide
---

Related

How to include multiple rows of LaTeX code via the YAML header (header-includes field) in RMarkdown?

I need to include the following code in a .tex file that is generated from a custom template via RMarkdown, in order to get rid of an error. However, if I try it as below in the YAML heading:
header-includes:
\newenvironment{CSLReferences}%
{}%
{\par}
it gets parsed into the .tex file as single line, like \newenvironment{CSLReferences}% {}% {\par}, thus commenting out everything after %. So how can I change the YAML part so that it correctly gets interpreted as 3 different lines?
Instead of worrying about the markdown parsing, you can write the command in a single line:
header-includes:
\newenvironment{CSLReferences}{}{\par}
Alternatively avoid all these annoying problems with markdown parsing and put your definition in a .tex file which you can include via
includes:
in_header: header.tex
After some trials & searching this works (found a solution while writing the question):
header-includes:
- "\\newenvironment{CSLReferences}%"
- "{}%"
- "{\\par}"
Interestingly, I couldn't find much in the official documentation.
EDIT:
As #samcarter mentioned in the comments & an answer, in this particular case a single line would've been enough, as
header-includes:
\newenvironment{CSLReferences}{}{\par}

How to include a latex document into a markdown using yaml metadata `include-after-body`

I want include a latex document into a markdown .md file using the YAML metadata. I have two files in a directory:
markdown.md
---
title: test fuer pdf eingeschlossen
author: AUF
keywords: test
abstract: Versuch
publish: True
include-after-body: testlatex.tex
---
A simple exampe for a test.
and testlatex.tex
some text without sense
\begin{itemize}
\tightlist
\item
firstly, a fundamental human need is;
\item
secondly, a cost-effective technical mean,
\end{itemize}
I can include the testlatex.tex file into the body of the markdown.md on the commandline with
pandoc --pdf-engine=lualatex --toc -o test.pdf markdown.md --include-after-body=testlatex.tex
but the equivalent value put into the YAML metadata seems not to have any effect (author and title are however used). I thought that the value included on the command line or in the YAML metadata would be equivalent. I checked in the pandoc latex template and see there an include for the include-after but I also wonder where the filename is converted to its content.
If I put
include-after: testlatex.tex
in the YAML metadata the name of the file is printed in the output, but the file content is not used!
Thank you for your help!

How to add multiple CSS files to a revealjs presentation in R Markdown?

I am trying to put together a reveal.js presentation in RStudio using R Markdown. I want to include multiple CSS files:
---
title: "Slick Presentation"
output:
revealjs::revealjs_presentation:
css: "css/style.css","fonts/fonts.css"
---
I have tried a comma separated list of values, but the YAML parser does not appear to like this.
You need to put the list of CSS files in square brackets, i.e.
---
title: "Slick Presentation"
output:
revealjs::revealjs_presentation:
css: ["css/style.css","fonts/fonts.css"]
---
or list the files prefixed by a hyphen, i.e.
---
title: "Slick Presentation"
output:
revealjs::revealjs_presentation:
css:
- "css/style.css"
- "fonts/fonts.css"
---
This is being parsed by the yaml package, not by pandoc. See ?yaml::yaml.load for a description of ways to produce a vector of strings, which is what the css parameter is looking for.

How can I specify pandoc's markdown extensions using a YAML block?

Background
Pandoc's markdown lets you specify extensions for how you would like your markdown to be handled:
Markdown syntax extensions can be individually enabled or disabled by appending +EXTENSION or -EXTENSION to the format name. So, for example, markdown_strict+footnotes+definition_lists is strict markdown with footnotes and definition lists enabled, and markdown-pipe_tables+hard_line_breaks is pandoc’s markdown without pipe tables and with hard line breaks.
My specific question
For a given pandoc conversion where, say, I use grid tables in my source:
pandoc myReport.md --from markdown+pipe_tables --to latex -o myReport.pdf
How can I write a pandoc YAML block to accomplish the same thing (specifying that my source contains grid tables?)
A generalized form of my question
How can I turn extensions on and off using pandoc YAML?
Stack Overflow Questions that I don't think completely answer my question
Can I set command line arguments using the YAML metadata - This one deals with how to specify output options, but I'm trying to tell pandoc about the structure of my input
What can I control with YAML header options in pandoc? - Answerers mention pandoc's templates, but neither the latex output template nor the markdown template indicate any sort of option for grid_tables. So, it's not clear to me from these answers how knowing about the templates will help me figure out how to structure my YAML.
There may also not be a way to do this
It's always possible that pandoc isn't designed to let you specify those extensions in the YAML. Although, I'm hoping it is.
You can use Markdown Variants to do this in an Rmarkdown document. Essentially, you enter your extensions into a variant option in the YAML header block at the start of the your .Rmd file.
For example, to use grid tables, you have something like this in your YAML header block:
---
title: "Habits"
author: John Doe
date: March 22, 2005
output: md_document
variant: markdown+grid_tables
---
Then you can compile to a PDF directly in pandoc by typing in your command line something like:
pandoc yourfile.md -o yourfile.pdf
For more information on markdown variants in RStudio: http://rmarkdown.rstudio.com/markdown_document_format.html#markdown_variants
For more information on Pandoc extensions in markdown/Rmarkdown in RStudio:
http://rmarkdown.rstudio.com/authoring_pandoc_markdown.html#pandoc_markdown
You can specify pandoc markdown extension in the yaml header using md_extension argument included in each output format.
---
title: "Your title"
output:
pdf_document:
md_extensions: +grid_tables
---
This will activate the extension. See Rmarkdown Definitive Guide for details.
Outside Rmarkdown scope, you can use Pandocomatic to it, or Paru for Ruby.
---
title: My first pandocomatic-converted document
pandocomatic_:
pandoc:
from: markdown+footnotes
to: html
...
As Merchako noted, the accepted answer is specific to rmarkdown. In, for instance, Atom md_extensions: does not work.
A more general approach would be to put the extensions in the command line options. This example works fine:
----
title: "Word document with emojis"
author: me
date: June 9, 2021
output:
word_document:
pandoc_args: ["--standalone", "--from=markdown+emoji"]
----
For people stumbling across this in or after 2021, this can be done without Rmarkdown. You can specify a YAML "defaults" file, which basically includes anything you could want to configure.
In order to do what OP wanted, all you'd need to do is
from: markdown+pipe_tables
in the defaults file, then pass it when you compile.
You can also specify the input and output files, so you can end up with the very minimal command
pandoc --defaults=defaults.yaml
and have it handle the rest for you. See https://pandoc.org/MANUAL.html#extensions for more.

Header and footer in YAML metablock for rmarkdown and pandoc

Is it possible to specify in the YAML metablock a pdf header and/or footer?Something you could set to appear on every page. This is in rmarkdown and will then be rendered to a pdf (using pandoc and knitr). I have not been able to find anything (header: and footer: sadly did not work!)
---
title: testpdf | test
footer: "test footer"
theme: "zenburn"
date: "`r Sys.Date()`"
output: "pdf_document"
fig_width: 12
fig_height: 6
fig_caption: true
---
There is no native pandoc-markdown support of headers and footers. However, since pandoc generates pdf documents through latex, you can tweak your latex template to accommodate those.
Create a new template from the default one :
pandoc -D latex > footer_template.latex
Add the following lines in the latex preamble (this is a very basic example that should produce a centered footer, see the fancyhdr user manual if you need something more advanced)
$if(footer)$
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyfoot[C]{$footer$}
$endif$
Finally, add this to your document yaml header :
output:
pdf_document:
template: test.latex
Your template should either be in ~/.pandoc/templates or in the same directory as test.rmd for this to work.

Resources