#' dissertar
#'
#' Transforma Rmd em tese com os parâmetros especificados. Esse pacote foi feito
#' inicialmente para uso pessoal e não foi devidamente testado. Cuidado.
#'
#' @param Pasta onde está o arquivo main.Rmd
#'
#' - Crie um projeto usando a função \code{\link{criar}}
#'
#' - Coloque as informações iniciais em main.Rmd
#'
#' - Edite os arquivos
#'
#' - Rode \code{dissertar}
#'
#' @export
dissertar <- function(path = '.') {
path <- normalizePath(path)
if(file.exists(sprintf("%s/main.pdf", path))) {
file.remove(sprintf("%s/main.pdf", path))
}
deps <- sprintf('%s/deps', path)
unlink(deps, recursive = TRUE)
dir.create(deps)
tex <- system.file('plainnat-ime/tese-exemplo.tex', package = 'thesis')
bst <- system.file('plainnat-ime/plainnat-ime.bst', package = 'thesis')
file.copy(tex, deps)
file.copy(bst, deps)
rmarkdown::render(input = sprintf('%s/main.Rmd', path),
output_file = sprintf('%s/main.tex', path), quiet = TRUE)
pdflatex <- sprintf('pdflatex --output-directory=deps/ main.tex')
bibtex <- sprintf('bibtex deps/main')
wd <- getwd()
setwd(path)
system(pdflatex, ignore.stdout = TRUE, ignore.stderr = TRUE)
system(bibtex, ignore.stdout = TRUE, ignore.stderr = TRUE)
system(pdflatex, ignore.stdout = TRUE, ignore.stderr = TRUE)
system(pdflatex, ignore.stdout = TRUE, ignore.stderr = TRUE)
file.copy(sprintf('%s/main.pdf', deps), sprintf('%s', path))
setwd(wd)
unlink(deps, recursive = TRUE)
file.remove(sprintf('%s/main.tex', path))
system(sprintf("evince %s/main.pdf", path), wait = FALSE) # opens the pdf
invisible(TRUE)
}
#' Criar esqueleto
#'
#' Cria um esqueleto de projeto de dissertação / tese com estrutura de arquivos.
#'
#' @param path o nome da pasta que você quer criar para guardar o projeto.
#'
#' @export
criar <- function(path) {
if(!dir.create(path, showWarnings = FALSE)) {
stop('pasta já existe!')
}
a <- system.file('esqueleto', package = 'thesis')
system(sprintf('cp -r %s/. %s/', a, path))
message('projeto criado!')
invisible(TRUE)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.