Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use only already included latex envs in latex reprs #74

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion R/options.r
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
#' \item{\code{repr.function.highlight}}{
#' Use the \code{highr} package to insert highlighting instructions into the code? Needs that package to be installed. (default: FALSE)
#' }
#' \item{\code{repr.function.highlightlatex}}{
#' Use the the latex package \code{minted} to higlight functions if \code{repr.function.highlight} is \code{FALSE}? Needs that latex package to be loaded in the tex file (default: FALSE)
#' }
#'
#' }
#'
Expand All @@ -64,7 +67,8 @@ class_defaults <- list(
repr.matrix.max.rows = 60,
repr.matrix.max.cols = 20,
repr.matrix.latex.colspec = list(row.head = 'r|', col = 'l', end = ''),
repr.function.highlight = FALSE)
repr.function.highlight = FALSE,
repr.function.highlightlatex = FALSE)

#' @name repr-options
#' @export
Expand Down
4 changes: 1 addition & 3 deletions R/package.r
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#' The repr package
#'
#' @details
#' The LaTeX repr of vectors needs \code{\\usepackage[inline]{enumitem}}
#'
#' The LaTeX repr of functions with the \code{repr.function.highlight} option set to FALSE needs \code{\\usepackage{minted}}
#' The LaTeX repr of functions with the \code{repr.function.highlight} option set to \code{FALSE} and the \code{repr.function.highlightlatex} option set to \code{TRUE} needs \code{\\usepackage{minted}}
#'
#' @seealso \link{repr}, \link{repr-options}, \link{repr-generics}, \link{repr_text}
#'
Expand Down
6 changes: 5 additions & 1 deletion R/repr_function.r
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ repr_html.function <- function(obj, highlight = getOption('repr.function.highlig
#' @name repr_*.function
#' @export
repr_latex.function <- function(obj, highlight = getOption('repr.function.highlight'), ...) {
minted.wrap <- '\\begin{minted}{r}\n%s\n\\end{minted}'
if (getOption('repr.function.highlightlatex')) {
minted.wrap <- '\\begin{minted}{r}\n%s\n\\end{minted}'
} else {
minted.wrap <- '\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n%s\n\\end{Verbatim}'
}
repr_function_generic(obj, 'latex', latex.escape, '%s', minted.wrap, highlight, ...)
}

Expand Down
4 changes: 2 additions & 2 deletions R/repr_vector.r
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ repr_latex.logical <- function(obj, ...) repr_vector_generic(
'\\item %s\n',
'\\item[%s] %s\n',
'\\textbf{%s:} %s',
enum.wrap = '\\begin{enumerate*}\n%s\\end{enumerate*}\n',
named.wrap = '\\begin{description*}\n%s\\end{description*}\n',
enum.wrap = '\\begin{enumerate}\n%s\\end{enumerate}\n',
named.wrap = '\\begin{description}\n%s\\end{description}\n',
only.named.item = '\\textbf{%s:} %s',
escape.FUN = latex.escape)

Expand Down
5 changes: 4 additions & 1 deletion man/repr-options.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/repr-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test_escaping.r
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ test_that('simple HTML escaping works', {
test_that('LaTeX escaping in vectors works', {
expect_equivalent_string(repr_latex('['), "'{[}'")
expect_equivalent_string(repr_latex(c('[', '|')),
"\\begin{enumerate*}
"\\begin{enumerate}
\\item '{[}'
\\item '\\textbar{}'
\\end{enumerate*}
\\end{enumerate}
")
})

Expand Down