render_pdf: Auto-edit Rmd to make it more suitable for LaTeX, and create...

View source: R/render_pdf.R

render_pdfR Documentation

Auto-edit Rmd to make it more suitable for LaTeX, and create PDF

Description

Auto-edit Rmd to make it more suitable for LaTeX, and create PDF

Usage

render_pdf(
  infile,
  herePath = "Rmd/",
  keep = FALSE,
  render = TRUE,
  output_file = NULL,
  keep_tex = FALSE,
  custom_removal = NULL,
  include = includes(in_header = "parahdr.tex"),
  toc = TRUE,
  toc_depth = 3,
  number_sections = TRUE,
  cleanup_ask = FALSE
)

Arguments

infile

String giving the name of the input file, without the path and (optionally) without the file extension.

herePath

String to pass to here::here to get the correct path to the directory containing the Rmd file.

keep

Whether to keep the temporary Rmd file produced. Defaults to keep = FALSE.

render

Whether to render the PDF. Defaults to render = TRUE.

output_file

String, giving the name of the output file. If not given, the default behaviour of render should occur.

keep_tex

Passed to pdf_document.

custom_removal

Optional string to be replaced with an empty string.

include

Defaults to include = includes(in_header = "parahdr.tex"6) and file "parahdr.tex" is written by the function itself. If parahdr.tex is not in include, figures might not be properly placed.

toc, toc_depth, number_sections

Passed to rmarkdown::pdf_document.

cleanup_ask

Whether to ask before removing temporary files. Defaults to cleanup_ask = TRUE, but this is intended to be temporary.

Details

The function assumes your deepest heading is 5 or lower, and that the level 1 heading is abused by being used to create a top level tabset in the HTML output. The code is simple and will likely break at times.

Value

Invisibly, a character vector containing hte modified Rmd.

Note

The function replaces all instances of "# " with " ", the idea being that for section headings, or those that are written by cat statements, one hash is removed. This also means that any comments will need to be started with more than one hash or they will be uncommented. In principle we should be able to use rmarkdown::render(..., output_format = "all"). However, accurately picking up the output format seems to not always work or be picked up by some of the other functions, such as output_table.

Examples

theFormat <- "html"; render("doc")
         theFormat <- "pdf"; render("doc")
         theFormat <- "word"; render("doc")

harrysouthworth/render documentation built on May 31, 2024, 11:18 a.m.