blob: 66ee3be66674ce3c55a65d1bc3bac7afae250830 [file] [log] [blame]
Hao Zhue0a36a82015-11-23 15:35:20 -05001#' Rmarkdown Format
2#'
3#' @description If the export format of the Rmarkdown document exist,
4#'
5#' @importFrom rmarkdown metadata
6#'
7#' @export
8
9rmd_format <- function(){
10 rmd_output_metadata <- metadata$output
Hao Zhuc1f38412017-02-23 12:13:48 -050011 # rmd_fmt <- ifelse(
12 # is.null(rmd_output_metadata),
13 # "markdown", ifelse(
14 # rmd_output_metadata %in% c("html_document", "rmarkdown::html_vignette"),
15 # "html",ifelse(
16 # rmd_output_metadata %in% c("pdf_document", "rmarkdown::tufte_handout"),
17 # "latex", "markdown"
18 # )))
19 return(names(rmd_output_metadata))
20}
21
22#' Load a LaTeX package
23#'
24#' @description Load a LaTeX package using R code. Just like `\\usepackage{}`
25#' in LaTeX
26#'
27#' @param name The LaTeX package name
28#' @param options The LaTeX options for the package
29#' @export
30usepackage_latex <- function(name, options = NULL) {
31 invisible(knit_meta_add(list(latex_dependency(name, options))))
Hao Zhue0a36a82015-11-23 15:35:20 -050032}
Hao Zhu62cdde52017-05-20 22:16:03 -040033
34# Find the right xml section. Since xml_child + search name will result in a
35# crash (at least on my machine), here is a helper function.
36xml_tpart <- function(x, part) {
37 xchildren <- xml_children(x)
38 children_names <- xml_name(xchildren)
Hao Zhufc14c9b2017-05-22 14:03:22 -040039 if(!part %in% children_names) return(NULL)
Hao Zhu62cdde52017-05-20 22:16:03 -040040 return(xchildren[[which(children_names == part)]])
41}
42
43positions_corrector <- function(positions, group_header_rows, n_row) {
44 pc_matrix <- data.frame(row_id = 1:n_row)
45 pc_matrix$group_header <- pc_matrix$row_id %in% group_header_rows
46 pc_matrix$adj <- cumsum(pc_matrix$group_header)
47 pc_matrix$old_id <- cumsum(!pc_matrix$group_header)
48 pc_matrix$old_id[duplicated(pc_matrix$old_id)] <- NA
49 adjust_numbers <- pc_matrix$adj[pc_matrix$old_id %in% positions]
50 return(adjust_numbers + positions)
51}