big stuff
diff --git a/R/iflatex.R b/R/iflatex.R
deleted file mode 100644
index 35b1bef..0000000
--- a/R/iflatex.R
+++ /dev/null
@@ -1,19 +0,0 @@
-#' Return latex control text if rendering latex
-#'
-#' @param txt
-#'
-#' @return a string
-#' @export
-#'
-#' @examples
-#' \dontrun{
-#' iflatex("\\vspace*{\\fill}")
-#' }
-#'
-iflatex <- function(txt){
-  if (knitr::opts_knit$get("rmarkdown.pandoc.to") == "latex"){
-    return(txt)
-  } else {
-    return("")
-  }
-}
\ No newline at end of file
diff --git a/R/posterdown.R b/R/posterdown.R
index 4799c3c..3942f6e 100644
--- a/R/posterdown.R
+++ b/R/posterdown.R
@@ -1,11 +1,13 @@
-#' posterdown: A package for creating Rmarkdown based PDF Latex Posters
+#' posterdown package
 #'
 #' This package creates posters for conferences
 #'
+#' @author Brent Thorne
+#'
 #' @section poster_pdf:
 #' Creates an R Markdown template fo a PDF poster document
 #' @docType package
-#' @name posterndown
+#' @name posterdown
 #' @import rmarkdown
 #' @import devtools
 #' @import dplyr
diff --git a/R/posterdown_generic.R b/R/posterdown_generic.R
new file mode 100644
index 0000000..72efa01
--- /dev/null
+++ b/R/posterdown_generic.R
@@ -0,0 +1,26 @@
+#' Posterdown PDF format
+#'
+#' Format for creating submissions to Multidisciplinary Digital Publishing
+#' Institute (MDPI) journals. Adapted from
+#' \href{http://www.mdpi.com/authors/latex}{http://www.mdpi.com/authors/latex}.
+#'
+#' @inheritParams rmarkdown::pdf_document
+#' @param ... Additional arguments to \code{rmarkdown::pdf_document}
+#'
+#' @return R Markdown output format to pass to
+#'   \code{\link[rmarkdown:render]{render}}
+#'
+#' @examples
+#'
+#' \dontrun{
+#' library(rmarkdown)
+#' draft("MyArticle.Rmd", template = "posterdown_generic", package = "posterdown")
+#' }
+#'
+#' @export
+posterdown_generic <- function(..., keep_tex = TRUE) {
+  inherit_pdf_document(...,
+                       keep_tex = keep_tex,
+                       template = find_resource("posterdown_generic", "template.tex"),
+                       citation_package = "natbib")
+}
diff --git a/R/posterdown_render.R b/R/posterdown_render.R
deleted file mode 100644
index 826348c..0000000
--- a/R/posterdown_render.R
+++ /dev/null
@@ -1,38 +0,0 @@
-#' Creates an R Markdown PDF Thesis document
-#'
-#' This is a function called in output in the YAML of the driver Rmd file
-#' to specify using the Brock University LaTeX template and cls files.
-#'
-#' @export
-#'
-#' @param toc A Boolean (TRUE or FALSE) specifying where table of contents should be created
-#' @param toc_depth A positive integer
-#' @param ... arguments to be passed to \code{rmarkdown::\link[rmarkdown]{pdf_document}}
-#'
-#' @return A modified \code{pdf_document} based on the Jacobs Landscape Poster Latex template
-#' @note The arguments highlight, keep_tex, and pandoc_args, are already set.
-#' @examples
-#' \dontrun{
-#'  output: posterdown::poster_pdf
-#' }
-poster_pdf <- function(toc = TRUE, toc_depth = 3, ...){
-
-  base <- rmarkdown::pdf_document(template = "template.tex",
-                             toc = toc,
-                             toc_depth = toc_depth,
-                             highlight = "default",
-                             keep_tex = TRUE,
-                             pandoc_args = "--top-level-division=default",
-                             ...)
-
-  # Mostly copied from knitr::render_sweave
-  base$knitr$opts_chunk$comment   <- NA
-  base$knitr$opts_chunk$fig.align <- "center"
-  base$knitr$opts_chunk$out.width <- "80%"
-  base$knitr$opts_knit$root.dir   <- getwd()
-  # Not sure if needed?
-  base$knitr$knit_hooks$plot <- knitr:::hook_plot_tex
-
-  base
-
-}
diff --git a/R/utils.R b/R/utils.R
new file mode 100644
index 0000000..2aa1fa3
--- /dev/null
+++ b/R/utils.R
@@ -0,0 +1,82 @@
+find_file <- function(template, file) {
+  template <- system.file("rmarkdown", "templates", template, file,
+                          package = "posterdown")
+  if (template == "") {
+    stop("Couldn't find template file ", template, "/", file, call. = FALSE)
+  }
+
+  template
+}
+
+find_resource <- function(template, file) {
+  find_file(template, file.path("resources", file))
+}
+
+knitr_fun <- function(name) utils::getFromNamespace(name, 'knitr')
+
+output_asis <- knitr_fun('output_asis')
+
+merge_list <- function(x, y) {
+  fun <- knitr_fun('merge_list')
+  fun(as.list(x), y)
+}
+
+#' Render a pandoc template.
+#'
+#' This is a hacky way to access the pandoc templating engine.
+#'
+#' @param metadata A named list containing metadata to pass to template.
+#' @param template Path to a pandoc template.
+#' @param output Path to save output.
+#' @return (Invisibly) The path of the generate file.
+#' @examples
+#' x <- posterdown:::template_pandoc(
+#'   list(preamble = "%abc", filename = "wickham"),
+#'   posterdown:::find_resource("posterdown_generic", "template.tex"),
+#'   tempfile()
+#' )
+#' if (interactive()) file.show(x)
+#' @noRd
+template_pandoc <- function(metadata, template, output, verbose = FALSE) {
+  tmp <- tempfile(fileext = ".md")
+  on.exit(unlink(tmp))
+
+  cat("---\n", file = tmp)
+  cat(yaml::as.yaml(metadata), file = tmp, append = TRUE)
+  cat("---\n", file = tmp, append = TRUE)
+  cat("\n", file = tmp, append = TRUE)
+
+  rmarkdown::pandoc_convert(tmp, "markdown", output = output,
+                            options = paste0("--template=", template), verbose = verbose)
+
+  invisible(output)
+}
+
+
+# Call rmarkdown::pdf_document and mark the return value as inheriting pdf_document
+inherit_pdf_document <- function(...) {
+  fmt <- rmarkdown::pdf_document(...)
+  fmt$inherits <- "pdf_document"
+  fmt
+}
+
+# Helper function to create a custom format derived from pdf_document
+# that includes a custom LaTeX template and custom CSL definition
+pdf_document_format <- function(..., format, template, csl) {
+
+  # base format
+  fmt <- inherit_pdf_document(..., template = find_resource(format, template))
+
+  # add csl to pandoc_args
+  fmt$pandoc$args <- c(fmt$pandoc$args,
+                       "--csl",
+                       rmarkdown::pandoc_path_arg(find_resource(format, csl)))
+
+
+  # return format
+  fmt
+}
+
+
+
+