Hopefully this is quick and easy question. Is there an equivalent in R Markdown, either as a latex imbed or a chunk option for a float barrier for images / R output, as in \FloatBarrier ?
Obviously, I could compile the doc in LaTeX, but I'm hoping to do it quickly and easily via markdown.
R Markdown allows embedding raw HTML or raw Tex. As is typical for Markdown, it does not appear to provide that level of control natively.
Custom CSS can also be specified for the output HTML.
Related
I guess my question is a potential if not probable duplicate of How to use inline R code in a bookdown theorem or example environment. It's been nearly 3 years since this question was asked, so a refresh might be welcome in any case, all the more given #YiHui's comment: "That is not possible with bookdown (at least for now)"?
Background: I am trying to use #YiHui bookdown package to produce a book with lecture slides (see creating accompanying slides for bookdown project). A key feature for this purpose is to be able to use conditional formatting, such as eval = (out_type=="beamer"). The issue I am facing is therefore to be able to add code chunks or inline R code inside bookdown custom environments (see https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#theorems and https://bookdown.org/yihui/bookdown/custom-blocks.html). I would love to get the following to compile properly. Is there a solution? Would a hook work (see https://yihui.org/knitr/hooks/)? There is a hack that works for forcing pandoc to parse inside a latex environment, but i do no think it applies here. Would a lua filter work (I have no idea how to use this)?
En passant, I am also surprised to see $\digamma$ showing up properly in the html output, but not in the pdf output, though it is parsed correctly in the tex file. The amssymb package is loaded and it's supposedly defined in there - what am I missing?
Much appreciated any help on this. Here is a MWE - I just edited chapter 4 from the default bookdown project. You can simply replace the contents of the file 03-method.Rmd with the following:
# Methods
We describe our methods in this chapter.
So here is a theorem to prove 1+1 = `r 1+1`.
```{theorem, echo=TRUE}
we want to show that in R, 1+1 = 2.
We also wonder why `$\digamma$` ($\digamma$) not showing.
Shows in the html output only, not pdf.
But when I recompile the tex file produced by bookdown - shows up just fine!!
Indeed, is defined correctly from `\usepackage{amssymb}`.
```
```{proof, echo=TRUE}
- If I am not mistaken, I cannot get an Rmarkdown style list to work either in the proof environment.
- Well, this is where i would like to be able to use inline code.
- we use r to compute 1+1: `r 1+1`.
- Does not work.
- Just shows verbatim inline code.
```
With the current development version of bookdown:
remotes::install_github('rstudio/bookdown')
you can write theorems in Pandoc's fenced Divs, e.g.,
# Methods
We describe our methods in this chapter.
So here is a theorem to prove 1+1 = `r 1+1`.
::: {.theorem}
we want to show that in R, 1+1 = 2.
We also wonder why `$\digamma$` ($\digamma$) not showing.
Shows in the html output only, not pdf.
But when I recompile the tex file produced by bookdown - shows up just fine!!
Indeed, is defined correctly from `\usepackage{amssymb}`.
:::
::: {.proof}
- If I am not mistaken, I cannot get an Rmarkdown style list to work either in the proof environment.
- Well, this is where i would like to be able to use inline code.
- we use r to compute 1+1: `r 1+1`.
- Does not work.
- Just shows verbatim inline code.
:::
However, please note that this new syntax is not supported for beamer output yet.
I am making a presentation in latex (Oxygen Beamer Template) in the online latex editor Overleaf, it is the original template that overleaf is available to modify it, the idea is to be able to implement it in Rmarkdown. So my question is if there is any package in R or trick to be able to capture the result of latex as a presentation in Rmarkdown?
Anyway when I have an advance or discover something I share it in this same way.
Thanks for your time, regards!
I am writing a document with knitr (Rnw to be processed to PDF) that will be printed in black&white. I still would like the code chunks to have syntax highlighting.
Is it possible, and how, to modify default syntax highlighting colors to use some shades of gray etc.?
PS. I do not want to switch to LaTeX 'listings' package.
As suggested by #Roland, knitr themes (?knit_theme) do the job. In particular, the print theme seems to suite black-and-white printing best. A gallery of all built-in knitr themes can be found here http://animation.r-forge.r-project.org/knitr/
In particular, to set print theme in my Rnw document put this in the initial R code chunk:
opts_knit$set( out.format="latex" )
knit_theme$set("print")
I was wondering whether there is a way for me to completely use Markdown language for writing a scientific paper along with R. I gave up on using Latex with knitr a while ago, since most of the journals need .docx files for submission, and converting from Latex to docx with pandoc is not always easy, especially when you get long scientific papers and you end up wasting hours debugging pandoc for trivial errors that Latex (and pdflatex) can easily pass. Anyway, I would like to use the power of knitr with flexibility of pandoc, markdown seems to be a good common ground. The only problem seems to be the bibliography and different citation styles that journals require. My question is: does markdown provide a simple to use (similar to biblatex, natbib, etc) bibliography engine? If not, what do you recommend for me to have a seamless transition from analyzing my data to submitting my papers? I'm sick of converting Latex to docx.
I basically use this setup, i.e. markdown in emacs but the concept is editor-independent. You can use a latex-like way to cite your paper in markdown and then use pandoc and the *.csl files. Check out this post for more details.
I am not sure if this type of question complies with the SO rules for well-defined questions ;) ... anyway:
I want to convert several R Sweave files (.Rnw) to R markdown files (.Rmd). Jeromy Anglin has posted on this matter here but there is no code supplied. I tried to use pandoc, but of course pandoc cannot handle the chunk tags and inline code tags correctly.
Consclusion: I guess I will have do write some code to parse my .Rnw files to prepare them for pandoc conversion. Thus my questions:
Is there a better way to go?
Does someone by chance have code
available that will do the job?
TIA
As #Karl commented, LaTeX --> markdown is not a trivial conversion as there are far more options and environments available in LaTeX compared to markdown. You are probably best off working with something like pandoc (see Demo #5). Basically, instead of doing
.Rnw --> .Rmd --> .md
you would do
.Rnw --> .tex --> .md
with pandoc. If you really want to go from .Rnw --> .Rmd, you may want to check out the pander package to write a function to extract code chunks, convert the remaining LaTeX content to markdown, and then re-insert the code chunks into the markdown document.