Skip to content

Instantly share code, notes, and snippets.

@tleonardi
Last active September 7, 2015 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tleonardi/45ef113de95a5e7f63fd to your computer and use it in GitHub Desktop.
Save tleonardi/45ef113de95a5e7f63fd to your computer and use it in GitHub Desktop.
Knitr and pandoc-fignos
```{r set-options}
my_hook <- function(x, options) {
if (options$fig.show == 'animate') return(hook_plot_html(x, options))
"%n%" <- knitr:::"%n%"
base = opts_knit$get('base.url') %n% ''
cap = knitr:::.img.cap(options)
if (is.null(w <- options$out.width) & is.null(h <- options$out.height) &
is.null(s <- options$out.extra) & options$fig.align == 'default') {
return(sprintf('![%s](%s%s){#fig:%s} ', cap, base, knitr:::.upload.url(x), options$label))
}
# use HTML syntax <img src=...>
kmitr:::.img.tag(
knitr:::.upload.url(x), w, h, cap,
c(s, sprintf('style="%s"', knitr:::css_align(options$fig.align)))
)
}
knit_hooks$set(plot = my_hook)
```
```{r testFigure, fig.cap="This is the figure caption"}
plot(1,1)
```
This is a reference to Figure @fig:testFigure.
The md file can be compiled to html or pdf using pandoc:
pandoc --filter pandoc-fignos knitMe.md -o knitMe.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment