tufte/0000755000176200001440000000000014445075672011417 5ustar liggesuserstufte/NAMESPACE0000644000176200001440000000045514211406136012622 0ustar liggesusers# Generated by roxygen2: do not edit by hand export(margin_note) export(newthought) export(quote_footer) export(sans_serif) export(tufte_book) export(tufte_handout) export(tufte_html) importFrom(htmltools,htmlDependency) importFrom(knitr,is_html_output) importFrom(knitr,is_latex_output) tufte/tools/0000755000176200001440000000000013733360541012546 5ustar liggesuserstufte/tools/copy-tufte-css.sh0000644000176200001440000000061013733360541015764 0ustar liggesusers#!/bin/bash cd inst/rmarkdown/templates/tufte_html/resources/ cp ../../../../../../tufte-css/{tufte.css,LICENSE} ./ [ ! -d et-book ] && mkdir et-book find ../../../../../../tufte-css/et-book -type f -name \*.ttf -exec cp {} et-book/ \; cd et-book for i in `ls *.ttf`; do mv $i ${i#et-book-} done sed -e 's@et-book/et-book-.*/@@' -e 's@\(url."et-book\)-@\1/@' -i '' ../tufte.css tufte/README.md0000644000176200001440000000443614445043665012702 0ustar liggesusers # tufte [![CRAN status](https://www.r-pkg.org/badges/version/tufte)](https://CRAN.R-project.org/package=tufte) [![Downloads from the RStudio CRAN mirror](https://cranlogs.r-pkg.org/badges/tufte)](https://cran.r-project.org/package=tufte) [![R-CMD-check](https://github.com/rstudio/tufte/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rstudio/tufte/actions/workflows/R-CMD-check.yaml) [![Codecov test coverage](https://codecov.io/gh/rstudio/tufte/branch/main/graph/badge.svg)](https://app.codecov.io/gh/rstudio/tufte?branch=main) This R package provides a few R Markdown output formats that use the Tufte style. See for a comprehensive example. ## Books R Markdown: The Definitive Guide See about the Tufte Handouts format in R Markdown Definitive Guide ## Installation You can install the last available released version from [CRAN](https://cran.r-project.org/package=tufte) ``` r install.packages('tufte') ``` You can also install the development version of **tufte** from [GitHub](https://github.com/) with: ``` r # install.packages("pak") pak::pak("rstudio/tufte") ``` ## Usage The easiest way to make a new R Markdown document using Tufte style is from within RStudio. Go to *File \> New File \> R Markdown \> From template \> Tufte Handout*. This can also be created from the command line using ``` r rmarkdown::draft("tufte.Rmd", "tufte_html", "tufte") ``` ## Getting help There are two main places to get help: 1. The [RStudio community](https://community.rstudio.com/c/r-markdown/10) is a friendly place to ask any questions about rmarkdown and the R Markdown family of packages. Use tag **tufte** in your post. 2. [Stack Overflow](https://stackoverflow.com/questions/tagged/r-markdown+tufte) is a great source of answers to common rmarkdown questions. It is also a great place to get help, once you have created a reproducible example that illustrates your problem. tufte/man/0000755000176200001440000000000014211405254012152 5ustar liggesuserstufte/man/tufte-package.Rd0000644000176200001440000000174214404617053015173 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/tufte-package.R \docType{package} \name{tufte-package} \alias{tufte} \alias{tufte-package} \title{tufte: Tufte's Styles for R Markdown Documents} \description{ Provides R Markdown output formats to use Tufte styles for PDF and HTML output. } \seealso{ Useful links: \itemize{ \item \url{https://github.com/rstudio/tufte} \item Report bugs at \url{https://github.com/rstudio/tufte/issues} } } \author{ \strong{Maintainer}: Christophe Dervieux \email{cderv@posit.co} (\href{https://orcid.org/0000-0003-4474-2498}{ORCID}) [contributor] Authors: \itemize{ \item Yihui Xie \email{xie@yihui.name} (\href{https://orcid.org/0000-0003-0645-5666}{ORCID}) \item JJ Allaire } Other contributors: \itemize{ \item Andrzej Oles [contributor] \item Dave Liepmann (Tufte CSS in inst/rmarkdown/templates/tufte_html/resources) [contributor] \item Posit Software, PBC [copyright holder, funder] } } \keyword{internal} tufte/man/tufte_handout.Rd0000644000176200001440000001106014404616732015321 0ustar liggesusers% Generated by roxygen2: do not edit by hand % Please edit documentation in R/handout.R, R/html.R, R/utils.R \name{tufte_handout} \alias{tufte_handout} \alias{tufte_book} \alias{tufte_html} \alias{newthought} \alias{margin_note} \alias{quote_footer} \alias{sans_serif} \title{Tufte handout formats (PDF and HTML)} \usage{ tufte_handout( fig_width = 4, fig_height = 2.5, fig_crop = TRUE, dev = "pdf", highlight = "default", ... ) tufte_book( fig_width = 4, fig_height = 2.5, fig_crop = TRUE, dev = "pdf", highlight = "default", ... ) tufte_html( ..., tufte_features = c("fonts", "background", "italics"), tufte_variant = c("default", "envisioned"), margin_references = TRUE ) newthought(text) margin_note(text, icon = "⊕") quote_footer(text) sans_serif(text) } \arguments{ \item{fig_width}{Default width (in inches) for figures} \item{fig_height}{Default height (in inches) for figures} \item{fig_crop}{Whether to crop PDF figures with the command \command{pdfcrop}. This requires the tools \command{pdfcrop} and \command{ghostscript} to be installed. By default, \code{fig_crop = TRUE} if these two tools are available.} \item{dev}{Graphics device to use for figure output (defaults to pdf)} \item{highlight}{Syntax highlighting style passed to Pandoc. Supported built-in styles include "default", "tango", "pygments", "kate", "monochrome", "espresso", "zenburn", "haddock", and "breezedark". Two custom styles are also included, "arrow", an accessible color scheme, and "rstudio", which mimics the default IDE theme. Alternatively, supply a path to a \samp{.theme} file to use \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{a custom Pandoc style}. Note that custom theme requires Pandoc 2.0+. Pass \code{NULL} to prevent syntax highlighting.} \item{...}{Other arguments to be passed to \code{\link[=pdf_document]{pdf_document()}} or \code{\link[=html_document]{html_document()}} (note you cannot use the \code{template} argument in \code{tufte_handout} or the \code{theme} argument in \code{tufte_html()}; these arguments have been set internally)} \item{tufte_features}{A character vector of style features to enable: \code{fonts} stands for the \code{et-book} fonts in the \code{tufte-css} project, \code{background} means the lightyellow background color of the page, and \code{italics} means whether to use italics for the headers. You can enable a subset of these features, or just disable all of them by \code{NULL}. When this argument is not used and the \code{tufte_variant} argument is not \code{default}, no features are enabled.} \item{tufte_variant}{A variant of the Tufte style. Currently supported styles are \code{default} (from the \code{tufte-css} project), and \code{envisioned} (inspired by the project \verb{Envisioned CSS} \url{https://github.com/nogginfuel/envisioned-css} but essentially just sets the font family to \verb{Roboto Condensed}, and changed the background/foreground colors).} \item{margin_references}{Whether to place citations in margin notes.} \item{text}{A character string to be presented as a \dQuote{new thought} (using small caps), or a margin note, or a footer of a quote} \item{icon}{A character string to indicate there is a hidden margin note when the page width is too narrow (by default it is a circled plus sign)} } \description{ Templates for creating handouts according to the style of Edward R. Tufte and Richard Feynman. } \details{ \code{tufte_handout()} provides the PDF format based on the Tufte-LaTeX class: \url{https://tufte-latex.github.io/tufte-latex/}. \code{tufte_html()} provides the HTML format based on the Tufte CSS: \url{https://edwardtufte.github.io/tufte-css/}. \code{newthought()} can be used in inline R expressions in R Markdown \if{html}{\out{
}}\preformatted{`r newthought(Some text)` }\if{html}{\out{
}} and it works for both HTML (\samp{text}) and PDF (\samp{\\newthought{text}}) output. \code{margin_note()} can be used in inline R expressions to write a margin note (like a sidenote but not numbered). \code{quote_footer()} formats text as the footer of a quote. It puts \code{text} in \samp{} for HTML output, and after \samp{\\hfill} for LaTeX output (to right-align text). \code{sans_serif()} applies sans-serif fonts to \code{text}. } \examples{ library(tufte) newthought("In this section") } \references{ See \url{https://rstudio.github.io/tufte/} for an example. } tufte/DESCRIPTION0000644000176200001440000000273714445075672013136 0ustar liggesusersType: Package Package: tufte Title: Tufte's Styles for R Markdown Documents Version: 0.13 Authors@R: c( person("Yihui", "Xie", role = "aut", email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")), person("Christophe", "Dervieux", role = c("ctb", "cre"), email = "cderv@posit.co", comment = c(ORCID = "0000-0003-4474-2498")), person("JJ", "Allaire", role = "aut"), person("Andrzej", "Oles", role = "ctb"), person("Dave", "Liepmann", role = "ctb", comment = "Tufte CSS in inst/rmarkdown/templates/tufte_html/resources"), person(given = "Posit Software, PBC", role = c("cph", "fnd")) ) Description: Provides R Markdown output formats to use Tufte styles for PDF and HTML output. License: GPL-3 URL: https://github.com/rstudio/tufte BugReports: https://github.com/rstudio/tufte/issues Imports: htmltools, knitr (>= 1.28), rmarkdown (>= 2.11), xfun (>= 0.13) Suggests: covr, testthat (>= 3.1.0), withr (>= 2.3.0) Config/testthat/edition: 3 Encoding: UTF-8 RoxygenNote: 7.2.3 NeedsCompilation: no Packaged: 2023-06-22 15:15:18 UTC; chris Author: Yihui Xie [aut] (), Christophe Dervieux [ctb, cre] (), JJ Allaire [aut], Andrzej Oles [ctb], Dave Liepmann [ctb] (Tufte CSS in inst/rmarkdown/templates/tufte_html/resources), Posit Software, PBC [cph, fnd] Maintainer: Christophe Dervieux Repository: CRAN Date/Publication: 2023-06-22 16:50:02 UTC tufte/tests/0000755000176200001440000000000014174473530012553 5ustar liggesuserstufte/tests/testthat/0000755000176200001440000000000014445075672014421 5ustar liggesuserstufte/tests/testthat/helpers.R0000644000176200001440000000274214211403146016171 0ustar liggesusers# Use to test pandoc availability or version lower than skip_if_not_pandoc <- function(ver = NULL) { if (!rmarkdown::pandoc_available(ver)) { msg <- if (is.null(ver)) { "Pandoc is not available" } else { sprintf("Version of Pandoc is lower than %s.", ver) } skip(msg) } } # Use to test version greater than skip_if_pandoc <- function(ver = NULL) { if (rmarkdown::pandoc_available(ver)) { msg <- if (is.null(ver)) { "Pandoc is available" } else { sprintf("Version of Pandoc is greater than %s.", ver) } skip(msg) } } local_rmd_file <- function(..., .env = parent.frame()) { path <- withr::local_tempfile(.local_envir = .env, fileext = ".Rmd") xfun::write_utf8(c(...), path) path } local_render <- function(input, ..., .env = parent.frame()) { skip_if_not_pandoc() output_file <- withr::local_tempfile(.local_envir = .env) rmarkdown::render(input, output_file = output_file, quiet = TRUE, ...) } local_pandoc_convert <- function(text, from = "markdown", options = NULL, ..., .env = parent.frame()) { skip_if_not_pandoc() rmd <- local_rmd_file(text) out <- withr::local_tempfile(.local_envir = .env) rmarkdown::pandoc_convert(rmd, from = from, output = out, options = c("--wrap", "preserve", options), ... ) xfun::read_utf8(out) } .render_and_read <- function(input, ...) { skip_if_not_pandoc() res <- local_render(input, ...) xfun::read_utf8(res) } tufte/tests/testthat/resources/0000755000176200001440000000000014211406724016416 5ustar liggesuserstufte/tests/testthat/resources/margins_references.Rmd0000644000176200001440000000224514174473530022735 0ustar liggesusers--- title: "Test margin references" link-citations: {{linked}} references: - author: - family: Xie given: Yihui id: R-knitr issued: year: 2020 note: R package version 1.30 title: "Knitr: A general-purpose package for dynamic report generation in r" title-short: Knitr type: book url: "https://yihui.org/knitr/" - author: - family: Xie given: Yihui id: R-knitr2 issued: year: 2020 note: R package version 1.29 title: "Knitr: A general-purpose package for dynamic report generation in r - duplicate" title-short: Knitr type: book url: "https://yihui.org/knitr/" - author: - family: Xie given: Yihui - family: Allaire given: J. J. - family: Grolemund given: Garrett id: rmarkdown2018 issued: year: 2018 note: ISBN 9781138359338 publisher: Chapman; Hall/CRC publisher-place: Boca Raton, Florida title: "R markdown: The definitive guide" title-short: R markdown type: book url: "https://bookdown.org/yihui/rmarkdown" output: tufte::tufte_html --- See [@R-knitr]. See @R-knitr2 See @R-knitr and @rmarkdown2018 See [@R-knitr] and [@rmarkdown2018] tufte/tests/testthat/_snaps/0000755000176200001440000000000014174473530015676 5ustar liggesuserstufte/tests/testthat/_snaps/pandoc-citeproc/0000755000176200001440000000000014174473530020750 5ustar liggesuserstufte/tests/testthat/_snaps/pandoc-citeproc/html.md0000644000176200001440000001240014174473530022233 0ustar liggesusers# put references in margin when link-citations: yes Code margin_references(x) Output [1] "

See (Xie 2020a)Xie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in R..

" [2] "

See Xie (2020b)Xie, Yihui. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in R - Duplicate.

" [3] "

See Xie (2020a)Xie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in R. and Xie, Allaire, and Grolemund (2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC.)

" [4] "

See (Xie 2020a)Xie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in R. and (Xie, Allaire, and Grolemund 2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC.)

" --- Code margin_references(x) Output [1] "

See (Xie 2020a).

" [2] "

See Xie (2020b)

" [3] "

See Xie (2020a) and Xie, Allaire, and Grolemund (2018)

" [4] "

See (Xie 2020a) and (Xie, Allaire, and Grolemund 2018)

" [5] "
" [6] "
" [7] "

Xie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in R.

" [8] "
" [9] "
" [10] "

———. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in R - Duplicate.

" [11] "
" [12] "
" [13] "

Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC.

" [14] "
" [15] "
" tufte/tests/testthat/_snaps/new-citeproc-post-2.14.1/0000755000176200001440000000000014211406654021774 5ustar liggesuserstufte/tests/testthat/_snaps/new-citeproc-post-2.14.1/html.md0000644000176200001440000003403514445043572023274 0ustar liggesusers# put references in margin when link-citations: yes Code margin_references(x) Output [1] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.).

" [2] "

See Xie (2020bXie, Yihui. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in r - Duplicate. https://yihui.org/knitr/.)

" [3] "

See Xie (2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.) and Xie, Allaire, and Grolemund (2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.)

" [4] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.) and (Xie, Allaire, and Grolemund 2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.)

" --- Code margin_references(x) Output [1] "

See (Xie 2020a).

" [2] "

See Xie (2020b)

" [3] "

See Xie (2020a) and Xie, Allaire, and Grolemund (2018)

" [4] "

See (Xie 2020a) and (Xie, Allaire, and Grolemund 2018)

" [5] "
" [6] "
" [7] "Xie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/." [8] "
" [9] "
" [10] "———. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in r - Duplicate. https://yihui.org/knitr/." [11] "
" [12] "
" [13] "Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown." [14] "
" [15] "
" # put references in margin when link-citations: yes using csl Code margin_references(x) Output [1] "

See (Xie, 2020aXie, Y. (2020a). Knitr: A general-purpose package for dynamic report generation in r. Retrieved from https://yihui.org/knitr/).

" [2] "

See Xie (2020bXie, Y. (2020b). Knitr: A general-purpose package for dynamic report generation in r - duplicate. Retrieved from https://yihui.org/knitr/)

" [3] "

See Xie (2020aXie, Y. (2020a). Knitr: A general-purpose package for dynamic report generation in r. Retrieved from https://yihui.org/knitr/) and Xie, Allaire, & Grolemund (2018Xie, Y., Allaire, J. J., & Grolemund, G. (2018). R markdown: The definitive guide. Boca Raton, Florida: Chapman; Hall/CRC. Retrieved from https://bookdown.org/yihui/rmarkdown)

" [4] "

See (Xie, 2020aXie, Y. (2020a). Knitr: A general-purpose package for dynamic report generation in r. Retrieved from https://yihui.org/knitr/) and (Xie et al., 2018Xie, Y., Allaire, J. J., & Grolemund, G. (2018). R markdown: The definitive guide. Boca Raton, Florida: Chapman; Hall/CRC. Retrieved from https://bookdown.org/yihui/rmarkdown)

" --- Code margin_references(x) Output [1] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.).

" [2] "

See Xie (2020bXie, Yihui. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in r - Duplicate. https://yihui.org/knitr/.)

" [3] "

See Xie (2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.) and Xie, Allaire, and Grolemund (2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.)

" [4] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.) and (Xie, Allaire, and Grolemund 2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.)

" tufte/tests/testthat/_snaps/html.md0000644000176200001440000000064214445043572017166 0ustar liggesusers# add marginnote Code marginnote_html("text") Output [1] "text" --- Code marginnote_html("text", "#") Output [1] "text" tufte/tests/testthat/_snaps/new-citeproc-post-2.14.0.2/0000755000176200001440000000000014174473530022140 5ustar liggesuserstufte/tests/testthat/_snaps/new-citeproc-post-2.14.0.2/html.md0000644000176200001440000003413014174473530023427 0ustar liggesusers# put references in margin when link-citations: yes Code margin_references(x) Output [1] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.).

" [2] "

See Xie (2020b)Xie, Yihui. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in r - Duplicate. https://yihui.org/knitr/.

" [3] "

See Xie (2020a)Xie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/. and Xie, Allaire, and Grolemund (2018)Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.

" [4] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.) and (Xie, Allaire, and Grolemund 2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.)

" --- Code margin_references(x) Output [1] "

See (Xie 2020a).

" [2] "

See Xie (2020b)

" [3] "

See Xie (2020a) and Xie, Allaire, and Grolemund (2018)

" [4] "

See (Xie 2020a) and (Xie, Allaire, and Grolemund 2018)

" [5] "
" [6] "
" [7] "Xie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/." [8] "
" [9] "
" [10] "———. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in r - Duplicate. https://yihui.org/knitr/." [11] "
" [12] "
" [13] "Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown." [14] "
" [15] "
" # put references in margin when link-citations: yes using csl Code margin_references(x) Output [1] "

See (Xie, 2020aXie, Y. (2020a). Knitr: A general-purpose package for dynamic report generation in r. Retrieved from https://yihui.org/knitr/).

" [2] "

See Xie (2020b)Xie, Y. (2020b). Knitr: A general-purpose package for dynamic report generation in r - duplicate. Retrieved from https://yihui.org/knitr/

" [3] "

See Xie (2020a)Xie, Y. (2020a). Knitr: A general-purpose package for dynamic report generation in r. Retrieved from https://yihui.org/knitr/ and Xie, Allaire, & Grolemund (2018)Xie, Y., Allaire, J. J., & Grolemund, G. (2018). R markdown: The definitive guide. Boca Raton, Florida: Chapman; Hall/CRC. Retrieved from https://bookdown.org/yihui/rmarkdown

" [4] "

See (Xie, 2020aXie, Y. (2020a). Knitr: A general-purpose package for dynamic report generation in r. Retrieved from https://yihui.org/knitr/) and (Xie, Allaire, & Grolemund, 2018Xie, Y., Allaire, J. J., & Grolemund, G. (2018). R markdown: The definitive guide. Boca Raton, Florida: Chapman; Hall/CRC. Retrieved from https://bookdown.org/yihui/rmarkdown)

" --- Code margin_references(x) Output [1] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.).

" [2] "

See Xie (2020b)Xie, Yihui. 2020b. Knitr: A General-Purpose Package for Dynamic Report Generation in r - Duplicate. https://yihui.org/knitr/.

" [3] "

See Xie (2020a)Xie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/. and Xie, Allaire, and Grolemund (2018)Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.

" [4] "

See (Xie 2020aXie, Yihui. 2020a. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.) and (Xie, Allaire, and Grolemund 2018Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.)

" tufte/tests/testthat/test-html.R0000644000176200001440000000416014211403147016445 0ustar liggesuserstest_that("add marginnote", { expect_snapshot(marginnote_html("text")) expect_snapshot(marginnote_html("text", "#")) }) expect_refs_margin <- function(moved = FALSE, options = NULL, ..., variant = NULL) { rmd <- test_path("resources/margins_references.Rmd") out <- withr::local_tempfile(fileext = ".html") rmd_temp <- withr::local_tempfile(fileext = ".Rmd") xfun::write_utf8( knitr::knit_expand(rmd, linked = if (moved) "yes" else "no"), rmd_temp ) rmarkdown::pandoc_convert(basename(rmd_temp), "html4", "markdown", output = out, citeproc = TRUE, verbose = FALSE, wd = dirname(rmd_temp), options = c("--wrap", "preserve", options), ... ) x <- xfun::read_utf8(out) expect_snapshot(margin_references(x), variant = variant) } citeproc_variant <- function() { if (!rmarkdown::pandoc_available("2.11")) { "pandoc-citeproc" } else if (!rmarkdown::pandoc_available("2.14.1")) { # new citeproc creates links on author "new-citeproc-post-2.14.0.2" } else { # Pandoc 2.14.1 fixed that "new-citeproc-post-2.14.1" } } pandoc_variant <- citeproc_variant() test_that("put references in margin when link-citations: yes", { skip_on_cran() skip_if_not_pandoc() expect_refs_margin(moved = TRUE, variant = pandoc_variant) expect_refs_margin(moved = FALSE, variant = pandoc_variant) }) test_that("put references in margin when link-citations: yes using csl", { skip_on_cran() # requires recent Pandoc skip_if_not_pandoc("2.11") skip_if_offline("zotero.org") expect_refs_margin(moved = TRUE, variant = pandoc_variant, c("--csl", "https://www.zotero.org/styles/apa-6th-edition")) expect_refs_margin(moved = TRUE, variant = pandoc_variant, c("--csl", "https://www.zotero.org/styles/chicago-author-date-16th-edition")) }) test_that("footnotes are correctly parsed", { skip_on_cran() skip_if_not_pandoc() pandoc_html <- local_pandoc_convert("Here is some text^[This should be a sidenote].", to = "html4" ) expect_identical( parse_footnotes(pandoc_html), list(items = "This should be a sidenote", range = 2:7) ) }) tufte/tests/testthat.R0000644000176200001440000000007214174473530014535 0ustar liggesuserslibrary(testthat) library(tufte) test_check("tufte") tufte/R/0000755000176200001440000000000014404616351011606 5ustar liggesuserstufte/R/utils.R0000644000176200001440000000623514404616351013077 0ustar liggesusers.onLoad <- function(lib, pkg) { # this engine will be overridden in tufte_html/tufte_handout formats knitr::knit_engines$set(marginfigure = function(options) { 'Placeholder (you should not see this)' }) } #' @details `newthought()` can be used in inline R expressions in R #' Markdown #' ```r #' `r newthought(Some text)` #' ``` #' and it works for both #' HTML (\samp{text}) and PDF #' (\samp{\\newthought{text}}) output. #' @param text A character string to be presented as a \dQuote{new thought} #' (using small caps), or a margin note, or a footer of a quote #' @rdname tufte_handout #' @export #' @examples newthought("In this section") newthought <- function(text) { if (is_html_output()) { sprintf('%s', text) } else if (is_latex_output()) { sprintf("\\newthought{%s}", text) } else { sprintf('%s', text) } } #' @details `margin_note()` can be used in inline R expressions to write a #' margin note (like a sidenote but not numbered). #' @param icon A character string to indicate there is a hidden margin note when #' the page width is too narrow (by default it is a circled plus sign) #' @rdname tufte_handout #' @importFrom knitr is_html_output is_latex_output #' @export margin_note <- function(text, icon = "⊕") { if (is_html_output()) { marginnote_html(sprintf('%s', text), icon) } else if (is_latex_output()) { sprintf("\\marginnote{%s}", text) } else { warning("marginnote() only works for HTML and LaTeX output", call. = FALSE) text } } #' @details `quote_footer()` formats text as the footer of a quote. It puts #' `text` in \samp{
} for HTML output, and #' after \samp{\\hfill} for LaTeX output (to right-align text). #' @rdname tufte_handout #' @export quote_footer <- function(text) { if (is_html_output()) { sprintf("
%s
", text) } else if (is_latex_output()) { sprintf("\\hfill %s", text) } else { warning("quote_footer() only works for HTML and LaTeX output", call. = FALSE) text } } #' @details `sans_serif()` applies sans-serif fonts to `text`. #' @rdname tufte_handout #' @export sans_serif <- function(text) { if (is_html_output()) { sprintf('%s', text) } else if (is_latex_output()) { sprintf("\\textsf{%s}", text) } else { warning("sans_serif() only works for HTML and LaTeX output", call. = FALSE) text } } template_resources <- function(name, ...) { system.file("rmarkdown", "templates", name, "resources", ..., package = "tufte") } gsub_fixed <- function(...) gsub(..., fixed = TRUE) pandoc2.0 <- function() rmarkdown::pandoc_available("2.0") # add --wrap=preserve to pandoc args for pandoc 2.0: # https://github.com/rstudio/bookdown/issues/504 # https://github.com/rstudio/tufte/issues/115 add_wrap_preserve <- function(args, pandoc2 = pandoc2.0) { if (pandoc2 && !length(grep("--wrap", args))) { c("--wrap", "preserve", args) } else { args } } tufte/R/tufte-package.R0000644000176200001440000000014314211405250014435 0ustar liggesusers#' @keywords internal "_PACKAGE" ## usethis namespace: start ## usethis namespace: end NULL tufte/R/handout.R0000644000176200001440000000633514211403140013364 0ustar liggesusers#' Tufte handout formats (PDF and HTML) #' #' Templates for creating handouts according to the style of Edward R. Tufte and #' Richard Feynman. #' #' `tufte_handout()` provides the PDF format based on the Tufte-LaTeX #' class: . #' @inheritParams rmarkdown::pdf_document #' @param ... Other arguments to be passed to [pdf_document()] or #' [html_document()] (note you cannot use the `template` #' argument in `tufte_handout` or the `theme` argument in #' `tufte_html()`; these arguments have been set internally) #' @references See for an example. #' @export #' @examples library(tufte) tufte_handout <- function(fig_width = 4, fig_height = 2.5, fig_crop = TRUE, dev = "pdf", highlight = "default", ...) { tufte_pdf("tufte-handout", fig_width, fig_height, fig_crop, dev, highlight, ...) } #' @rdname tufte_handout #' @export tufte_book <- function(fig_width = 4, fig_height = 2.5, fig_crop = TRUE, dev = "pdf", highlight = "default", ...) { tufte_pdf("tufte-book", fig_width, fig_height, fig_crop, dev, highlight, ...) } tufte_pdf <- function(documentclass = c("tufte-handout", "tufte-book"), fig_width = 4, fig_height = 2.5, fig_crop = TRUE, dev = "pdf", highlight = "default", template = template_resources("tufte_handout", "tufte-handout.tex"), ...) { # resolve default highlight if (identical(highlight, "default")) highlight <- "pygments" # call the base pdf_document format with the appropriate options format <- rmarkdown::pdf_document( fig_width = fig_width, fig_height = fig_height, fig_crop = fig_crop, dev = dev, highlight = highlight, template = template, ... ) # LaTeX document class documentclass <- match.arg(documentclass) format$pandoc$args <- c( format$pandoc$args, "--variable", paste0("documentclass:", documentclass), if (documentclass == "tufte-book") { if (pandoc2.0()) "--top-level-division=chapter" else "--chapters" } ) knitr::knit_engines$set(marginfigure = function(options) { options$type <- "marginfigure" eng_block <- knitr::knit_engines$get("block") eng_block(options) }) # create knitr options (ensure opts and hooks are non-null) knitr_options <- rmarkdown::knitr_options_pdf(fig_width, fig_height, fig_crop, dev) if (is.null(knitr_options$opts_knit)) knitr_options$opts_knit <- list() if (is.null(knitr_options$knit_hooks)) knitr_options$knit_hooks <- list() # set options knitr_options$opts_knit$width <- 45 # set hooks for special plot output knitr_options$knit_hooks$plot <- function(x, options) { # determine figure type if (isTRUE(options$fig.margin)) { options$fig.env <- "marginfigure" if (is.null(options$fig.cap)) options$fig.cap <- "" } else if (isTRUE(options$fig.fullwidth)) { options$fig.env <- "figure*" if (is.null(options$fig.cap)) options$fig.cap <- "" } knitr::hook_plot_tex(x, options) } # override the knitr settings of the base format and return the format format$knitr <- knitr_options format$inherits <- "pdf_document" format } tufte/R/html.R0000644000176200001440000002272114313060264012674 0ustar liggesusers#' @details `tufte_html()` provides the HTML format based on the Tufte CSS: #' . #' @param tufte_features A character vector of style features to enable: #' `fonts` stands for the `et-book` fonts in the `tufte-css` #' project, `background` means the lightyellow background color of the #' page, and `italics` means whether to use italics for the headers. You #' can enable a subset of these features, or just disable all of them by #' `NULL`. When this argument is not used and the `tufte_variant` #' argument is not `default`, no features are enabled. #' @param tufte_variant A variant of the Tufte style. Currently supported styles #' are `default` (from the `tufte-css` project), and #' `envisioned` (inspired by the project `Envisioned CSS` #' but essentially just #' sets the font family to `Roboto Condensed`, and changed the #' background/foreground colors). #' @param margin_references Whether to place citations in margin notes. #' @rdname tufte_handout #' @export tufte_html <- function(..., tufte_features = c("fonts", "background", "italics"), tufte_variant = c("default", "envisioned"), margin_references = TRUE) { tufte_variant <- match.arg(tufte_variant) if (missing(tufte_features) && tufte_variant != "default") { tufte_features <- character() } html_document2 <- function(..., extra_dependencies = list()) { rmarkdown::html_document( ..., extra_dependencies = c( extra_dependencies, tufte_html_dependency(tufte_features, tufte_variant) ) ) } format <- html_document2(theme = NULL, ...) pandoc2 <- pandoc2.0() # add --wrap=preserve to pandoc args for pandoc 2.0: format$pandoc$args <- add_wrap_preserve(format$pandoc$args, pandoc2) # when fig.margin = TRUE, set fig.beforecode = TRUE so plots are moved before # code blocks, and they can be top-aligned ohooks <- knitr::opts_hooks$set(fig.margin = function(options) { if (isTRUE(options$fig.margin)) { options$fig.beforecode <- TRUE } options }) # make sure the existing post processor is called first in our new processor post_processor <- format$post_processor format$post_processor <- function(metadata, input, output, clean, verbose) { if (is.function(post_processor)) { output <- post_processor(metadata, input, output, clean, verbose) } knitr::opts_hooks$restore(ohooks) x <- xfun::read_utf8(output) fn_label <- paste0(knitr::opts_knit$get("rmarkdown.pandoc.id_prefix"), "fn") footnotes <- parse_footnotes(x, fn_label) notes <- footnotes$items # replace footnotes with sidenotes for (i in seq_along(notes)) { num <- sprintf( '%d', fn_label, i, if (pandoc2) "footnote-ref" else "footnoteRef", fn_label, i, i ) con <- sprintf(paste0( '', '', '%d %s' ), i, i, i, i, notes[i]) x <- gsub_fixed(num, con, x) } # remove footnotes at the bottom if (length(footnotes$range)) x <- x[-footnotes$range] # replace citations with margin notes if (margin_references) x <- margin_references(x) # place figure captions in margin notes x[x == '

'] <- '

' # move to the same line as ; the previous line should # start with ", x), grep("^$", x[i])) { j <- j + 1 x[i] <- paste0(x[i], x[i + j]) x[i + j] <- "" } } # place table captions in the margin r <- "^$" for (i in grep(r, x)) { # the previous line should be
(.+)
or
if (!grepl("^$", x[i - 1])) next cap <- gsub(r, "\\1", x[i]) x[i] <- x[i - 1] x[i - 1] <- paste0( "

", '', cap, "

" ) } # add an incremental number to the id of