Skip to content

Instantly share code, notes, and snippets.

@naupaka
Forked from noamross/pandoc-newpage-filter.R
Created March 21, 2018 17:06
Show Gist options
  • Save naupaka/8243089c3b259a6e7b022b763c2df3cc to your computer and use it in GitHub Desktop.
Save naupaka/8243089c3b259a6e7b022b763c2df3cc to your computer and use it in GitHub Desktop.
#!/usr/bin/env Rscript
json_in <- file('stdin', 'r')
lat_newp <- '{"t":"RawBlock","c":["latex","\\\\newpage"]}'
doc_newp <- '{"t":"RawBlock","c":["openxml","<w:p><w:r><w:br w:type=\\"page\\"/></w:r></w:p>"]}'
ast <- paste(readLines(json_in, warn=FALSE), collapse="\n")
ast <- gsub(lat_newp, doc_newp, ast, fixed=TRUE)
write(ast, "")
# Use \newpage in your document to specify page breaks (just like LaTeX!)
# Put this script in the directory you are compiling your R Markdown in.
# Use it in you YAML like this:
#---
#title: "Title
#author: "Author"
#output:
# word_document:
# pandoc_args: [
# "--filter", "pandoc-newpage-filter.R"
# ]
#---
# You will have page breaks in your word doc!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment