From 3794e79955d95ccef0da00ef01e03d7f75945713 Mon Sep 17 00:00:00 2001 From: Jan Philipp Dietrich Date: Fri, 7 Sep 2018 15:14:51 +0200 Subject: [PATCH] added TOC in PDFs bugfix in buildHTML --- DESCRIPTION | 4 +-- R/buildHTML.R | 2 +- R/buildPDF.R | 74 +++++++++++++++++++++++++-------------------------- 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index acb1ddb..44e1299 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: goxygen Type: Package Title: Documentation package for modular GAMS code -Version: 0.11.0 +Version: 0.11.1 Date: 2018-09-07 Authors@R: c(person("Jan Philipp", "Dietrich", email = "dietrich@pik-potsdam.de", role = c("aut","cre"))) Description: A collection of tools which allow to manipulate and analyze code. @@ -12,4 +12,4 @@ License: BSD_2_clause + file LICENSE Encoding: UTF-8 LazyData: no RoxygenNote: 6.1.0 -ValidationKey: 1955910 +ValidationKey: 1973691 diff --git a/R/buildHTML.R b/R/buildHTML.R index 0f6ce51..385b2fe 100644 --- a/R/buildHTML.R +++ b/R/buildHTML.R @@ -76,7 +76,7 @@ buildHTML <- function(folder="html", mdfolder="markdown", literature="literature if(!is.null(addHTML)) { html <- readLines(ofile) cut <- which(html=="") - html <- c(html[1:cut],addHTML,html[cut+1:(length(html))]) + html <- c(html[1:cut],addHTML,html[(cut+1):length(html)]) writeLines(html,ofile) } } diff --git a/R/buildPDF.R b/R/buildPDF.R index 2ef240f..151c035 100644 --- a/R/buildPDF.R +++ b/R/buildPDF.R @@ -1,37 +1,37 @@ -#' buildPDF -#' -#' Converts a folder with markdown files and a corresponding literature library -#' (if available) to a single PDF and creates page breaks and cross-links between -#' topics. -#' -#' Pandoc (https://pandoc.org/) together with pandoc-citeproc need to be installed -#' on the system. -#' -#' @param file name of the PDF to be written -#' @param mdfolder path to the markdown folder to be used as source -#' @param literature path to a bibliography, if available (will be ignored -#' if file does not exist) -#' @param supplementary a vector of files and/or folders required for the conversion -#' (e.g. an images subdirectory with figures to be shown in the documents) -#' @author Jan Philipp Dietrich -#' @seealso \code{\link{goxygen}}, \code{\link{buildHTML}} -#' @export - -buildPDF <- function(file="documentation.pdf", mdfolder="markdown", literature="literature.bib", supplementary=NULL) { - message("Start PDF creation...") - check_pandoc() - for(elem in supplementary) file.copy(elem,".",recursive = TRUE, overwrite = TRUE) - sep <- tempfile() - writeLines("\\pagebreak",sep) - ref <- tempfile() - files <- list.files(mdfolder,pattern="*.md",full.names = TRUE) - moduleNames <- sub("\\.[^.]*$","",basename(files)) - returnReferences(moduleNames,paste0("#id-",moduleNames),ref,level=1) - files <- paste(paste(files,collapse=paste0(" ",sep," ")),ref) - if(is.null(literature)) bib <- "" - else bib <- ifelse(file.exists(literature),paste0(" --metadata link-citations --bibliography=",literature),"") - system(paste0("pandoc ",files," -o ",file," --template ", - system.file("templates","template.latex",package="goxygen"), - " -V colorlinks --listings",bib)) - message("...finished PDF creation!") -} +#' buildPDF +#' +#' Converts a folder with markdown files and a corresponding literature library +#' (if available) to a single PDF and creates page breaks and cross-links between +#' topics. +#' +#' Pandoc (https://pandoc.org/) together with pandoc-citeproc need to be installed +#' on the system. +#' +#' @param file name of the PDF to be written +#' @param mdfolder path to the markdown folder to be used as source +#' @param literature path to a bibliography, if available (will be ignored +#' if file does not exist) +#' @param supplementary a vector of files and/or folders required for the conversion +#' (e.g. an images subdirectory with figures to be shown in the documents) +#' @author Jan Philipp Dietrich +#' @seealso \code{\link{goxygen}}, \code{\link{buildHTML}} +#' @export + +buildPDF <- function(file="documentation.pdf", mdfolder="markdown", literature="literature.bib", supplementary=NULL) { + message("Start PDF creation...") + check_pandoc() + for(elem in supplementary) file.copy(elem,".",recursive = TRUE, overwrite = TRUE) + sep <- tempfile() + writeLines("\\pagebreak",sep) + ref <- tempfile() + files <- list.files(mdfolder,pattern="*.md",full.names = TRUE) + moduleNames <- sub("\\.[^.]*$","",basename(files)) + returnReferences(moduleNames,paste0("#id-",moduleNames),ref,level=1) + files <- paste(paste(files,collapse=paste0(" ",sep," ")),ref) + if(is.null(literature)) bib <- "" + else bib <- ifelse(file.exists(literature),paste0(" --metadata link-citations --bibliography=",literature),"") + system(paste0("pandoc ",files," -o ",file," --toc --template ", + system.file("templates","template.latex",package="goxygen"), + " -V colorlinks --listings",bib)) + message("...finished PDF creation!") +}