Different rendering between .Rmd and .Rmarkdown when using blogdown - rstudio

I have found some strange differences in the way .Rmd files are rendered compared to .Rmarkdown.
My setup:
Beautiful hugo theme
Blogdown 0.9
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
If change the file extension between Rmd and Rmarkdown, I observe the following differences:
Rmd doesn't render multi level lists properly
Rmd doesn't render footnotes [^1] properly
Rmarkdown doesn't render math properly
Python code chunks don't have a nice little execute button in the upper right in Rmd.
Is this expected behavior? Is there something with the theme that causes this?

Yes the difference between .Rmd and .Rmarkdown is expected and Yihui et al. outlines it in their book (it's around the middle of the page)
You cannot use Markdown features only supported by Pandoc, such as fenced Divs.
Math expressions only work if you apply the JavaScript solution mentioned in Section B.3.
The main thing to note is that .Rmarkdown gets converted to .markdown documents first and gets passed onto Hugo's Markdown renderer (e.g., Goldmark or Blackfriday) to generate a html while .Rmd uses Pandoc by default.

Related

markdown or markup to powerpoint?

I need to maintain some slides in both latex beamer and in powerpoint. (This is to make slides available for instructors elsewhere, too, 90% of which do not know how to use latex and are unwilling to learn it. and I am a latex guy on linux.)
I have tried the route via Libreoffice (and opendocument), but this did not come out well. right now, the best method that I have found is to author pdf in beamer, then run it through a nuance OCR program to get MS Word...and not even go all the way to Powerpoint (which is where I really need to be).
If I only had a markup language that produced nice Powerpoint, I could probably code a perl translator from markdown to this intermediate markup language. (going from markdown to latex beamer is relatively easy.)
I don't think this exists, but hope springs eternal. after all, it is almost 2014 now. does anyone know of a solution?
One solution is to use odpdown: It converts markdown to the OpenOffice Presenter format, which can be imported into PowerPoint.
It is not yet complete, i.e. table support is missing and possibly not running on certain Windows setups, but nevertheless it could be a start. Possibly, you have Linux running, where it seems to work.
Steve Rindsberg's answer in the comments works on PP 2007 works! Let me repeat it here:
I suspect that PowerPoint is the likeliest solution. ;-) But what sort
of slides are you creating? If they're simple heading and bullet point
slides, all you need to produce is a simple text file. Any text that
starts in the left column will be the heading of a new slide. Indent
one tab and it becomes a first-level bullet point under the current
heading; indent two tabs, it becomes a second level bullet point and
so on. Simply use File | Open on the text file to pull it into PPT.
Steve: Is this all that PP converts? Or is there a reference of other "sneaky" markup that PP knows about?
(pandoc: unfortunately, the conversion from libreoffice to powerpoint is pretty poor when I tried it last. I also tried to save and understand the powerpoint xml format, but that was REAL bad.)
The easiest way to handle this is to work with:
RStudio (and R if not already installed)
RMarkdown
Pandoc 2.0.5 (minimum)
Install those 3 (or 4) items, then read: https://bookdown.org/yihui/rmarkdown/powerpoint-presentation.html
The installation time is worth the time saved copy-pasting everything from scratch.
I also am a Linux guy and I also use LateX engines to create nice documents. Based on my experience, here's what you should do :
Stop writing directly in LaTeX and start using org-mode to write documents instead (I spent years writing in LaTeX and now it's over (except when I use modernv package))
Org supports latex math formulas and .org files are easily exported in .tex files
Org can also be easily exported in markdown
Once you have your markdown, there are several tools that will allow you to create a PowerPoint. Two of them are pandoc and md2pptx

How to set size for local image using knitr for markdown?

I have a local image that I would like to include in an .Rmd file which I will then knit and convert to HTML slides with Pandoc. Per this post, this will insert the local image :
![Image Title](path/to/your/image)
Is there a way to modify this code to also set the image size?
The question is old, but still receives a lot of attention. As the existing answers are outdated, here a more up-to-date solution:
Resizing local images
As of knitr 1.12, there is the function include_graphics. From ?include_graphics (emphasis mine):
The major advantage of using this function is that it is portable in the sense that it works for all document formats that knitr supports, so you do not need to think if you have to use, for example, LaTeX or Markdown syntax, to embed an external image. Chunk options related to graphics output that work for normal R plots also work for these images, such as out.width and out.height.
Example:
```{r, out.width = "400px"}
knitr::include_graphics("path/to/image.png")
```
Advantages:
Over agastudy's answer: No need for external libraries or for re-rastering the image.
Over Shruti Kapoor's answer: No need to manually write HTML. Besides, the image is included in the self-contained version of the file.
Including generated images
To compose the path to a plot that is generated in a chunk (but not included), the chunk options opts_current$get("fig.path") (path to figure directory) as well as opts_current$get("label") (label of current chunk) may be useful. The following example uses fig.path to include the second of two images which were generated (but not displayed) in the first chunk:
```{r generate_figures, fig.show = "hide"}
library(knitr)
plot(1:10, col = "green")
plot(1:10, col = "red")
```
```{r}
include_graphics(sprintf("%sgenerate_figures-2.png", opts_current$get("fig.path")))
```
The general pattern of figure paths is [fig.path]/[chunklabel]-[i].[ext], where chunklabel is the label of the chunk where the plot has been generated, i is the plot index (within this chunk) and ext is the file extension (by default png in RMarkdown documents).
Un updated answer: in knitr 1.17 you can simply use
![Image Title](path/to/your/image){width=250px}
edit as per comment from #jsb
Note this works only without spaces, e.g. {width=250px} not {width = 250px}
You can also read the image using png package for example and plot it like a regular plot using grid.raster from the grid package.
```{r fig.width=1, fig.height=10,echo=FALSE}
library(png)
library(grid)
img <- readPNG("path/to/your/image")
grid.raster(img)
```
With this method you have full control of the size of you image.
Here's some options that keep the file self-contained without retastering the image:
Wrap the image in div tags
<div style="width:300px; height:200px">
![Image](path/to/image)
</div>
Use a stylesheet
test.Rmd
---
title: test
output: html_document
css: test.css
---
## Page with an image {#myImagePage}
![Image](path/to/image)
test.css
#myImagePage img {
width: 400px;
height: 200px;
}
If you have more than one image you might need to use the nth-child pseudo-selector for this second option.
If you are converting to HTML, you can set the size of the image using HTML syntax using:
<img src="path/to/image" height="400px" width="300px" />
or whatever height and width you would want to give.
Had the same issue today and found another option with knitr 1.16 when knitting to PDF (which requires that you have pandoc installed):
![Image Title](path/to/your/image){width=70%}
This method may require that you do a bit of trial and error to find the size that works for you. It is especially convenient because it makes putting two images side by side a prettier process. For example:
![Image 1](path/to/image1){width=70%}![Image 2](path/to/image2){width=30%}
You can get creative and stack a couple of these side by side and size them as you see fit. See https://rpubs.com/RatherBit/90926 for more ideas and examples.
Another option that worked for me is playing with the dpi option of knitr::include_graphics() like this:
```{r}
knitr::include_graphics("path/to/image.png", dpi = 100)
```
... which sure (unless you do the math) is trial and error compared to defining dimensions in the chunk, but maybe it will help somebody.
The knitr::include_graphics solution worked well for resizing the figures, but I was unable to figure out how to use it to produce side-by-side resized figures. I found this post useful for doing so.

How can you embed multiple SVG images in a print layout using a scripted procedure?

I currently have a script that produces a large amount of 3.5-inch-square SVG images. What I need is to be able to put these SVGs in a layout which can be easily and accurately printed.
I have tried using an HTML template, but HTML/CSS does not have sufficiently robust printing support.
What document layout language is most appropriate for handling SVG images, and how could this be implemented in a scripting language?
I use Ruby to generate my SVGs, and although preferable, it is not required that Ruby also be the language used to generate the print layout.
I'd suggest compiling all SVGs to a larger SVG, placing everything where you want it, and convert that to PDF using one of multiple options:
Using Inkscape on the command line, like
inkscape -f in.svg -A out.pdf
Using Batik
java -jar batik-rasterizer.jar -m application/pdf -d out.pdf in.svg
Using librsvg, like
rsvg-convert -f pdf -o out.pdf in.svg
(Probably the most lightweight option)
You might also be able to use the rsvg2 Ruby gem with a Cairo PDF surface. Documentation seems scarce or scattered, though.
If you have a budget, Prince is what you want. Since you've already tried to use CSS+HTML to get it working, you may have a working solution almost ready. Just generate the HTML, SVG, and CSS (use the CSS3 paged media extensions for best control), then pass it off to Prince to generate the PDF. I've used this for several projects, and it works great.
There are free options that work like Prince, notably wkhtmltopdf, but they might not respect your paging options as much as Prince.
Otherwise, you might be able to hack something together using Cairo, by creating a page-sized SVG image and laying it out, adding links to the multiple external SVG files.
Either of these options will end up generating a PDF, which is the only way to ensure that it will print the same no matter which browser or OS is being used.

wkhtmltopdf with full page background image

I've got wkhtmltopdf working with a header and footer image, and everything spaced well. But the task is to use a full page background image which looks like a sort of frame, with the page text in the center. I thought I could place this in the header, but it doesn't work - maybe the use of a full page header doesn't make sense here.
(These are multi-page documents, which could be of any length).
Any ideas of how to do this?
Thanks in advance.
John
I have a similar problem, this is what I understood so far:
It's not possible to center the text vertically on the page simply via CSS+wkhtmltopdf on a multi-page document (might find some complex javascript stuff, but it wasn't worth in my case);
since wkhtmltopdf uses webkit, and webkit doesn't support #page rules, it's not possible to define a "paged" background via CSS
Hence what? You will need a little hack and use pdftk
1. In your CSS define:
body {
background: white;
}
(if you have a body tag in your header.html and footer.html make sure that rule applies to them as well)
2. Create a one-page pdf with your background image (using the same page size as your final pdf)
3. Install pdftk and from command line:
$ pdftk yourfile.pdf background background.pdf output yourfile_b.pdf
4. Enjoy :)
You can use a solution BASED on webkit, like HTM2PDF - you'll be able to add a feature called 'stationary' where you can integrate any image as a full page background.
more info at the documentation from the API page

Is there a jQuery plugin for Dot language file visualization?

Is there a jQuery plugin for displaying Dot files live in the browser as specified here?
I've seen a proof of concept at Visual Politics, but it doesn't seem to fully support the Dot language as even -- doesn't display correctly.
Any libraries out there I could have a look at for this?
I need to implement network graphs in the browser from dot files loaded via Ajax (rather than server side generated PNGs)
Check out Canviz: http://code.google.com/p/canviz/
Demos are located here: http://www.ryandesign.com/canviz/
As I was looking for the same answer, I found "viz.js" providing a java script version of GraphViz for DOT (see https://github.com/mdaines/viz.js).
Using this, I build myself WP GraphViz, a plugin for WordPress (see http://wordpress.org/plugins/wp-graphviz/).
I've been working on this for almost a week.
There are three different implementations:
1.Render svg in simple js, no needs install of graphviz
jquery.graphviz.svg https://github.com/mountainstorm/jquery.graphviz.svg
jQuery plugin to make Graphviz SVG output more interactive and easier to navigate. Makes it easy to have features like:
Highlight nodes/edges
Zoom in/out
Graph navigation - select linked nodes
Fancy UI tooltips; bootstrap supported out the box
Move things forward/back in the graph
Have a look at the demo: https://cdn.rawgit.com/mountainstorm/jquery.graphviz.svg/master/demo.html
2.Based on d3.js
<https://github.com/dagrejs/dagre-d3> d3.js + dagre
<https://github.com/dagrejs/dagre> pure js library
or:
<https://github.com/magjac/d3-graphviz> d3.js + graphviz c++ build
<https://github.com/hpcc-systems/hpcc-js-wasm> build graphviz 2.47
3.server side call graphviz to generate svg file.
<http://viz-js.com/>
<https://github.com/mdaines/viz.js>
<https://github.com/dreampuf/GraphvizOnline>

Resources