# character input
Eqn('e=mc^2')
# show only the LaTeX code
Eqn('e=mc^2', preview=FALSE)
# Equation numbers & labels
Eqn('e=mc^2', label = 'eq:einstein')
Eqn("X=U \\lambda V", label='eq:svd')
# html_output and quarto outputs only show code
# (both auto detected in compiled documents)
Eqn('e=mc^2', label = 'eq:einstein', html_output = TRUE)
# Quarto output
Eqn('e=mc^2', label = 'eq-einstein', quarto = TRUE)
if (FALSE) {
# The following requires LaTeX compilers to be pre-installed
# View PDF instead of HTML
Eqn('e=mc^2', preview.pdf=TRUE)
# Add extra LaTeX dependencies for PDF build
Eqn('\\bm{e}=mc^2', preview.pdf=TRUE,
preview.packages=c('amsmath', 'bm'))
}
# Multiple expressions
Eqn("e=mc^2",
Eqn_newline(),
"X=U \\lambda V", label='eq:svd')
# expressions that use cat() within their calls
Eqn('SVD = ',
latexMatrix("u", "n", "k"),
latexMatrix("\\lambda", "k", "k", diag=TRUE),
latexMatrix("v", "k", "p", transpose = TRUE),
label='eq:svd')
# align equations using & operator
Eqn("X &= U \\lambda V", Eqn_newline(),
"& = ", latexMatrix("u", "n", "k"),
latexMatrix("\\lambda", "k", "k", diag=TRUE),
latexMatrix("v", "k", "p", transpose = TRUE),
align=TRUE)
# numeric/character matrix example
A <- matrix(c(2, 1, -1,
-3, -1, 2,
-2, 1, 2), 3, 3, byrow=TRUE)
b <- matrix(c(8, -11, -3))
# numeric matrix wrapped internally
cbind(A,b) |> Eqn()
cbind(A,b) |> latexMatrix() |> Eqn()
# change numeric matrix brackets globally
cbind(A,b) |> Eqn(mat_args=list(matrix='bmatrix'))
# greater flexibility when using latexMatrix()
cbind(A, b) |> latexMatrix() |> partition(columns=3) |> Eqn()
# with showEqn()
showEqn(A, b, latex=TRUE) |> Eqn()
Eqn_newline()
Eqn_newline('10ex')
Eqn_hspace()
Eqn_hspace(3) # smaller
Eqn_hspace(3, times=2)
Eqn_hspace('1cm')
# symmetric spacing around mid
Eqn_hspace(mid='=')
Eqn_hspace(mid='=', times=2)
Eqn_vspace('1.5ex')
Eqn_vspace('1cm')
# set size globally
Eqn_size(size=3)
Eqn_size() # reset
# locally for defined string
string <- 'e = mc^2'
Eqn_size(string, size=1)
# used inside of Eqn() or manually defined labels in the document
Eqn('e = mc^2', label='eq:einstein')
# use within inline block via `r ref()`
ref('eq:einstein')
ref('eq:einstein', parentheses=FALSE)
ref('eq:einstein', html_output=TRUE)
# With Quarto
Eqn('e = mc^2', label='eq-einstein', quarto=TRUE)
ref('eq:einstein', quarto=TRUE)
ref('eq:einstein', quarto=TRUE, parentheses=FALSE)
Run the code above in your browser using DataLab