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

add mathExpression #127

Merged
merged 1 commit into from
Jun 1, 2023
Merged
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Imports:
svglite,
systemfonts,
withr
RoxygenNote: 7.2.2
RoxygenNote: 7.2.3
Roxygen: list(markdown = TRUE)
Encoding: UTF-8
LinkingTo: Rcpp
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export(jaspResultsCalledFromJasp)
export(logNormDist)
export(logit)
export(makeJaspFormula)
export(mathExpression)
export(negBinomDist)
export(normalDist)
export(poisDist)
Expand Down
28 changes: 28 additions & 0 deletions R/mathExpression.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#' LaTeX Expressions in JASP
#'
#' @description Construct LaTeX expressions for JASP output
#'
#' @param x A string that contains the LaTeX code for the math expression
#' @param inline Should the expression be inline or in display mode?
#'
#' @examples
#' # Escape the backslash character for LaTeX code
#' jaspBase::mathExpression("\\alpha + \\beta")
#' # Alternatively use the raw character constant
#' jaspBase::mathExpression(r"{\alpha + \beta}")
#'
#' # By default expressions are inline, to disable use
#' jaspBase::mathExpression(r"{ \bar{x} = \frac{\sum_i^n x_i}{n} }", inline = FALSE)
#'
#' @export
mathExpression <- function(x, inline = TRUE) {
stopifnot(is.character(x))

if (!inline) {
output <- sprintf("\\[%s\\]", x)
} else {
output <- sprintf("\\(%s\\)", x)
}

return(output)
}
26 changes: 26 additions & 0 deletions man/mathExpression.Rd

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