In the kramdown markdown documentation I read that I can insert multi line footnotes by indenting the next lines in the footnote. I tried to insert a knitr chunk into the footnote like this:
---
title: "test"
output: html_document
layout: post
---
My text[^1]
[^1]:This should appear in a footnote:
```{r}
runif(1:10)
```
This worked when compiling the footnote directly with knitr:
If I let jekyll compile it it looks differently:
The code chunk is not really in the footnote. It is above it. And it is indented like this is not properly recognized as footnote annotation.
In config.yaml I defined markdown: kramdown.
Knitr uses pandoc under the hood. To achieve the same output with Jekyll, you should use jekyll-pandoc, thus in config.yaml instead of markdown: kramdown then markdown: pandoc.
As #mb21 pointed out switching markdown: kramdown to pandoc makes jekyll use the same markdown compiler as knitr does by default. You have to install the jekyll-pandoc gem first. This is best done with bundler:
According to bundler.io, in a command line:
gem install bundler
cd /path/to/my/project
bundle init
According to jekyll-pandoc:
nano Gemfile
overwrite with the following:
source "https://rubygems.org"
gem "jekyll-pandoc"
save.
Then:
bundle install
This will install jekyll-pandoc and all dependencies.
In your project add this to your _config.yaml:
# Build settings
gems:
- jekyll-pandoc
markdown: pandoc
(replace markdown: kramdown).
To generate your site use this command inside R:
servr::jekyll(command="bundle exec jekyll build")
Related
I'm writing a paper using R Markdown and TinyTex, using Biblatex for referencing. It works fine with default referencing styles, but I need to add a custom bibliography and citation style for the journal I'm writing for.
I need to follow the Unified Stylesheet for Linguistics, for which there is a Biblatex implementation available on Github here, containing a .bbx and .cbx file.
I've tried adding those .bbx and .cbx files to my local copy of TinyTex, inside Library/TinyTex/texmf-local/tex/latex/biblatex. My YAML header includes:
output:
pdf_document:
citation_package: biblatex
biblatexoptions: [bibstyle=biblatex-sp-unified, citestyle=sp-authoryear-comp]
When I knit the document, I get the following error:
tlmgr search --file --global '/biblatex-dm.cfg'
! Package keyval Error: bibstyle undefined.
I don't have a biblatex-dm.cfg file (nor do I really understand what that would be). I would have thought the .bbx and .cbx files would be sufficient, based on the regular installation instructions in the style's Github repo.
Where should I put .bbx and .cbx files, so that tlmgr can find them? And/or what additional steps do I need to take to use this style with my paper?
====================================================================
UPDATE: The problem seems to be coming from the Pandoc LaTeX template that R Markdown uses.
Setting aside R Markdown, I created a smaller minimal LaTeX example:
main.tex
references.bib
Where main.tex is:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[bibstyle=biblatex-sp-unified,citestyle=sp-authoryear-comp]{biblatex}
\addbibresource{references.bib}
\begin{document}
Something something \citep{darwin_origin_1859}.
\printbibliography
\end{document}
And references.bib is:
#book{darwin_origin_1859,
location = {London},
title = {On the Origin of Species by Means of Natural Selection},
publisher = {J. Murray},
author = {Darwin, Charles},
date = {1859}
}
I had success compiling this example using the sequence of commands pdflatex, biber, pdflatex, pdflatex. Thus it seems my local TeX installation knows about the biblatex-sp-unified.bbx and sp-authoryear-comp.cbx files I added and can use them just fine.
Subsequently, I created an equivalent minimal R Markdown document with the YAML header:
title: "Untitled"
output:
pdf_document:
citation_package: biblatex
bibliography: references.bib
biblatexoptions: [bibstyle=biblatex-sp-unified, citestyle=sp-authoryear-comp]
and body:
Something something [#darwin_origin_1859].
This time, I got the same old error message from before:
tlmgr search --file --global '/biblatex-dm.cfg'
! Package keyval Error: bibstyle undefined.
This would seem to suggest that the problem is caused by something in Pandoc's LaTeX template, but I don't know what.
Just to confirm that it's definitely the Pandoc template and not my own installation/setup, I took the .tex file that gets produced when I knit the minimal R Markdown example above, and tried to compile it in Overleaf (with biblatex-sp-unified.bbx and sp-authoryear-comp.cbx files added). I reproduced the same error.
Although I think I've localised the problem, I'd still very much like to understand what and where the problem is in the Pandoc template. I'd also be keen to hear if anyone has any fixes (other than just using a different template or writing my own).
UPDATE: This seems to be an issue with using an out-of-date version of R Markdown and/or Pandoc.
I was using rmarkdown package v.1. At time of writing, the most up-to-date version is 2.1.
I updated all my packages and updated Rstudio (which currently ships with Pandoc v2.3.1) and no longer experience problems. I also upgraded R (from 3.5.something to 3.6.2) and did a fresh re-install of tinytex while I was at it, but I'm not sure whether those things had an effect for this particular problem.
Now, when I put biblatexoptions: [bibstyle=biblatex-sp-unified, citestyle=sp-authoryear-comp] in my YAML header, it's correctly converted into the LaTeX command \usepackage[bibstyle=biblatex-sp-unified,citestyle=sp-authoryear-comp]{biblatex}, rather than the \ExecuteBibliographyOptions command as described below.
Ralf Stubner initially suggested I check my R Markdown/Pandoc versions in the comments. Please give his comments an upvote if you them useful as well.
Problem recap:
I'm writing a document in R Markdown and I have a particular referencing style that I'd like to use with biblatex. I have a .bbx and .cbx file defining the style, available on Github (linked above). The problem is that the document fails to compile, saying biblio/citation styles are undefined (even when the style files are in the project folder itself).
I've found that the problem was caused by the way I was passing options to biblatex. In my YAML Header, the line:
biblatexoptions: [bibstyle=biblatex-sp-unified, citestyle=sp-authoryear-comp]
gets converted to the latex command:
\ExecuteBibliographyOptions{bibstyle=biblatex-sp-unified,citestyle=sp-authoryear-comp}
I'm not sure why, but when this command is included, it produces the errors I was observing.
Installing new Biblatex style:
I'm finding that TeX doesn't know about the .bbx and .cbx files when they're in my ~/Library/TinyTex/texmf-local/tex/latex/biblatex directory (which is where I expected to put them based on the Github installation instructions).
To get the referencing style recognised by the system, I placed .bbx and .cbx files inside ~/Library/TinyTex/texmf-dist/tex/latex/biblatex/bbx and ~/Library/TinyTex/texmf-dist/tex/latex/biblatex/cbx respectively. Then, in the terminal, I ran sudo mktexlsr.
(Alternatively, for use only with a particular document, the .bbx and .cbx files could simply be kept in the project directory with the R Markdown file)
Original hacky answer (but see update above):
Instead of using biblatexoptions in the YAML header of the R Markdown document, I simply knitted it with citation_package: biblatex (and no extra options). I also added keep_tex: yes. Then, I opened the resulting tex file, found the \usepackage{bibtex} command and added the desired options, so it read \usepackage[bibstyle=biblatex-sp-unified,citestyle=sp-authoryear-comp]{biblatex}.
Finally, I ran pdflatex and biber on the tex file in the terminal. Clearly far from ideal, but it will technically produce the desired output.
Building a post for a Jekyll site from an RMarkdown document and running into a problem with pandoc's "helpful" URL encoding of links. I hit the RStudio "Knit" button on this document:
---
output: md_document
---
```{r setup, include=FALSE}
knitr::opts_knit$set(base.url = '{{ site.baseurl }}/')
knitr::opts_chunk$set(fig.path = 'assets/images/')
```
```{r sin_plot}
plot(1:100, sin(1:100))
```
And I get this markdown document:
plot(1:100, sin(1:100))
![](%7B%7B%20site.baseurl%20%7D%7D/assets/images/sin_plot-1.png)
What I need is this markdown document:
plot(1:100, sin(1:100))
![]({{ site.baseurl }}/assets/images/sin_plot-1.png)
The liquid tag will be handled by Jekyll, but pandoc is getting in the way.
Issue opened with rmarkdown
Since you don't need Pandoc at all, you don't need to use rmarkdown, either. You can just use "vanilla" knitr (note that rmarkdown = knitr + Pandoc), i.e., knitr::knit() instead of rmarkdown::render().
For Jekyll websites, blogdown may make your life a little easier since it supports Jekyll, too: https://bookdown.org/yihui/blogdown/jekyll.html You won't need to hit the Knit button but just blogdown::serve_site() and enjoy LiveReload. If you have never used blogdown before, you need to read at least Chapter 1 of the blogdown book (but ignore Hugo there).
As noted in the other answer, the "Knit" button calls rmarkdown::render and is unavoidably knitr + Pandoc. To give the RStudio users contributing to this blog a button to push, I moved everything to a simple Makefile.
RMD := $(shell find _posts/ -name '*.Rmd')
PORT = 4321
export GEM_HOME = ~/.gem
.PHONY: all
all: Gemfile.lock $(RMD:%.Rmd=%.md)
bundle exec jekyll build --drafts --baseurl=/p/$(PORT)
Gemfile.lock:
bundle install
%.md: %.Rmd
Rscript --vanilla -e "knitr::knit('$<', '$#')"
For a live preview, the RStudio users can leave a servr::httw('_site') process running in their console and hit the "Build" button to update.
I want to generate from an rmarkdown file (using RStudio) a Gitlab flavored markdown(GFM), so the file is displayed properly on a gitlab server.
I am especially interested in having Latex formula to be displayed properly.
In the gitlab documentation specify that the formulas should be written between $` and `$
$`a^2+b^2=c^2`$
But Rmarkdown require the $ $ synthax (no `)
$a^2+b^2=c^2$
Currently I have tryied to create github flavored markdown with the following yaml in the preamble:
output:
html_document:
keep_md: false
md_document:
variant: markdown_github
but when entering the following in my Rmd file:
$A=\displaystyle\sum_{b} c_b$
I get the following in the markdown:
*A* = ∑<sub>*b*</sub>*c*<sub>*b*</sub>
How can I configure my Rmarkdown or Rstudio so I will get this in the md file:
$`A=\displaystyle\sum_{b} c_b`$
I would like to convert a *.Rmd to document to PDF without rstudio being available.
Current approach
Current approach follows the following steps:
*.Rmd document is passed to knitr: knit(input = "report.Rmd"))
Obtained md is converted via pandoc:
# Convert
pandoc --smart --to latex \
--latex-engine pdflatex \
-s report.md \
-o report.PDF
Problems
This results in the following problems, the top section of the Rmarkdown document:
---
title: "Report Title"
author: "Person"
output: pdf_document
classoption: landscape
---
and shows as:
all text is centered, whereas I would like for it to be left-aligned:
Possible approach
I would like to make use of the rmarkdown::render; however, despite setting RSTUDIO_PANDOC (as discussed here), the command fails on pandoc not being available.
Desired outcome
I don't care much whether the utilised mechanism makes use of the rmarkdown::render, what I want to achieve is:
Landscape page layout across all pages
Left-aligned text
Ability to exercise minimum control over the document by controlling default fonts
Ideally, I would like to do as much as in the *.Rmd file as possible without the need to add parameters to the pandoc command.
Updates, following comments
I'm working on Linux and pandoc is installed, I can execute pandoc command pass files and generate exports with no problems. It only doesn't work with the rmarkdown::render package.
Concerning the hooks and *.Rmd files, this is what I'm trying to understand as I see that that the first section of my *.Rmd file is ignored. The current process looks as follows:
*.Rmd (not much in it, just title section and dummy text and code that renders but wrongly justified) >
*.R file running one line knit(input = "report.Rmd")) >
*.sh file running pandoc command and generating PDF
Concerning:
if all that is in place, it is indeed just a call to
rmarkdown::render(...)
The rmarkdown::render(...) fails:
Error: pandoc version 1.12.3 is required and was not found ...
However:
>> rmarkdown::pandoc_available()
[1] TRUE
and:
$ pandoc -v
pandoc 1.9.4.1 (...)
The RSTUDIO_PANDOC points to pandoc.
A few things:
"the command fails on pandoc not being available." well you must have pandoc installed in order to call it -- but you didn't say what OS you have. On Linux it is pretty trivial to install pandoc from the package manager; otherwise jgm has binaries for you on the site; "should" be similar on OS X
for different styling you need to modify the LaTeX code which you can via numerous hooks to include macro files; see the RMarkdown cheat sheets for detail
if you want to exercise more control, you can supply your own template; I have done so in the tint package
(which is also on CRAN)
if all that is in place, it is indeed just a call to rmarkdown::render(...)
Error: pandoc version 1.12.3 is required and was not found
I think the error says it plainly: you need pandoc 1.12.3 and you have pandoc 1.9.4.1
I do not know, however, why such a specific version is required.
I am trying to use Pandoc to convert a .md file to PDF. In doing this, I would like to add a LaTeX template into it. Is there a way to do this? If so, what is the command for doing it in RStudio?
The command I am currently using is the following
```{r}
pandoc("foo.md", format="latex")
```
Thank you in advance.
One way to do it is to use the function system and run pandoc directly, adding a Latex header.
For example:
system("pandoc -f markdown -t latex -o foo.pdf -H template.tex -V papersize:\"a4paper\" -V geometry:\"top=2cm, bottom=3cm, left=2cm, right=2cm\" foo.md ")
-f inicates the origin language, though I mix MarkDown and Latex and it works fine.
-t is the result language, though it really compiles the created latex and what you get is a .pdf document
-o the name of the file you want to create
-H a header to add. There is where you can put your template
-V many variables that you can set. Here I set the paper size and margins
at the end you write the name of your MarkDown file
template.tex is a tex file with the header I want in the Latex document. I use it to add packages, headers and some other parameters. For example:
\usepackage{booktabs}
\usepackage[spanish, es-tabla]{babel}
\usepackage{colortbl}
\usepackage{float}
\usepackage{fancyhdr}
\usepackage[singlelinecheck=false]{caption}
\setlength{\headheight}{40pt}
\pagestyle{fancy}
\lhead{My Title}
\rhead{\includegraphics[height=50pt]{MyGraph.png}}