nathaneastwood/knitrhooks

Convert tiktz plot to png

Opened this issue · 0 comments

cderv commented

Another hook found in knitr example
https://github.com/yihui/knitr-examples/blob/master/047-tikz-png.Rnw

knit_hooks$set(tikz2png = function(before, options, envir) {
  # use this hook only for dev='tikz' and externalized tikz graphics
  if (before || options$dev != 'tikz' || !options$external || options$fig.num == 0) return()
  figs = knitr:::all_figs(options, ext = 'pdf')  # all figure names
  # note the tikz2png option is the extra parameters passed to 'convert'
  for (fig in figs) {
    system(sprintf('convert %s %s %s', options$tikz2png, fig, sub('\\.pdf$', '.png', fig)))
  }
})