Nothing
# Render the actual Rd topics as HTML and a styled reference PDF.
# Usage: Rscript tools/render-reference.R /path/to/IJSE output_dir
args <- commandArgs(trailingOnly = TRUE)
stopifnot(length(args) == 2L)
root <- normalizePath(args[1L], mustWork = TRUE)
dir.create(args[2L], recursive = TRUE, showWarnings = FALSE)
output <- normalizePath(args[2L], mustWork = TRUE)
stage <- file.path(output, "reference-source")
dir.create(stage, recursive = TRUE, showWarnings = FALSE)
topics <- c("IJSE-package", "ijse", "ijse_draws", "summary.ijse")
version <- read.dcf(file.path(root, "DESCRIPTION"))[1L, "Version"]
style <- file.path(stage, "Rd.sty")
if (file.exists(style)) Sys.chmod(style, mode = "0644")
invisible(file.copy(file.path(R.home("share"), "texmf", "tex", "latex", "Rd.sty"),
style, overwrite = TRUE, copy.mode = FALSE))
css <- c('body {font-family:"Times New Roman",Times,serif;font-size:12pt;color:#000000;background:#ffffff;max-width:950px;margin:2em auto;line-height:1.4;}',
'h1,h2,h3,h4,p,a,li,td,th {color:#000000;} h1{font-size:16pt;} h2{font-size:13pt;} h3{font-size:12pt;}',
'a{text-decoration:underline;} pre,code{font-family:"Courier New",monospace;font-size:10pt;} pre{white-space:pre-wrap;overflow-wrap:anywhere;} table{border-collapse:collapse;} td,th{padding:0.2em 0.5em;}')
writeLines(css, file.path(output, "manual.css"))
contents <- c(paste0('<!doctype html><html lang="en"><meta charset="utf-8"><title>IJSE ', version,
' Reference Manual</title><link rel="stylesheet" href="manual.css"><body>'),
paste0('<h1>IJSE ', version, ' Reference Manual</h1>'),
'<p>Choose a help topic. The PDF is a complete, self-contained reference; HTML mathematical rendering may require network access.</p><ul>')
tex <- c('\\documentclass[12pt,letterpaper]{article}',
'\\usepackage{Rd}', '\\usepackage{fontspec}',
'\\setmainfont{Times New Roman}', '\\setsansfont{Times New Roman}',
'\\setmonofont{Courier New}', '\\usepackage{unicode-math}',
'\\setmathfont{latinmodern-math.otf}',
'\\usepackage[margin=1in]{geometry}', '\\usepackage{titlesec}',
'\\titleformat{\\section}{\\normalfont\\fontsize{14}{16}\\bfseries}{\\thesection}{0.6em}{}',
'\\titleformat{\\subsubsection}{\\normalfont\\fontsize{12}{14}\\bfseries}{\\thesubsubsection}{0.6em}{}',
'\\renewcommand{\\code}[1]{{\\ttfamily\\fontsize{10}{12}\\selectfont #1}}',
'\\renewenvironment{ExampleCode}{\\fontsize{10}{12}\\selectfont\\verbatim}{\\endverbatim}',
'\\sloppy',
paste0('\\hypersetup{colorlinks=true,allcolors=black,pdftitle={IJSE ', version, ' Reference Manual}}'),
'\\begin{document}',
paste0('\\begin{center}{\\fontsize{16}{18}\\selectfont\\bfseries IJSE ', version,
' Reference Manual\\par}\\end{center}'),
'\\noindent Function reference generated from the package help sources.',
'\\Rdcontents{Topics}')
links <- character()
for (topic in topics) {
rd <- tools::parse_Rd(file.path(root, "man", paste0(topic, ".Rd")))
aliases <- vapply(rd[vapply(rd, function(x) identical(attr(x, "Rd_tag"), "\\alias"), logical(1))],
paste, collapse = "", character(1))
links[aliases] <- paste0(topic, ".html")
}
for (topic in topics) {
rd <- file.path(root, "man", paste0(topic, ".Rd"))
html <- paste0(topic, ".html")
tools::Rd2HTML(rd, out = file.path(output, html), package = root,
Links = links, no_links = FALSE,
stylesheet = "manual.css", texmath = "katex",
stages = c("build", "install", "render"))
contents <- c(contents, paste0('<li><a href="', html, '">', topic, '</a></li>'))
fragment <- file.path(stage, paste0(topic, ".tex"))
tools::Rd2latex(rd, out = fragment, outputEncoding = "UTF-8", stages = c("build", "install", "render"))
tex <- c(tex, paste0('\\input{', basename(fragment), '}'))
}
tex <- c(tex, '\\end{document}')
writeLines(c(contents, '</ul></body></html>'), file.path(output, "index.html"))
file.copy(file.path(output, "index.html"), file.path(output, "00Index.html"), overwrite = TRUE)
input <- file.path(stage, "IJSE-reference-manual.tex")
writeLines(tex, input)
previous <- setwd(stage)
tryCatch(tinytex::xelatex(basename(input), clean = FALSE),
finally = setwd(previous))
file.copy(sub("\\.tex$", ".pdf", input),
file.path(output, "IJSE-reference-manual.pdf"), overwrite = TRUE)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.