Skip to content

Commit

Permalink
added TOC in PDFs
Browse files Browse the repository at this point in the history
bugfix in buildHTML
  • Loading branch information
tscheypidi committed Sep 7, 2018
1 parent 22ed142 commit 3794e79
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", role = c("aut","cre")))
Description: A collection of tools which allow to manipulate and analyze code.
Expand All @@ -12,4 +12,4 @@ License: BSD_2_clause + file LICENSE
Encoding: UTF-8
LazyData: no
RoxygenNote: 6.1.0
ValidationKey: 1955910
ValidationKey: 1973691
2 changes: 1 addition & 1 deletion R/buildHTML.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ buildHTML <- function(folder="html", mdfolder="markdown", literature="literature
if(!is.null(addHTML)) {
html <- readLines(ofile)
cut <- which(html=="<body>")
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)
}
}
Expand Down
74 changes: 37 additions & 37 deletions R/buildPDF.R
Original file line number Diff line number Diff line change
@@ -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!")
}

0 comments on commit 3794e79

Please sign in to comment.