library(matlib)
A <- matrix(1:4, 2, 2)
B <- matrix(4:1, 2, 2)
AB <- A + B
Eqn(overset(A, "A"))
# missing label: uses the name of the object
Eqn(overset(A))
# test just a character LaTeX expression
Eqn('a', overset('=', '?'), 'b')
# a labelled latexMatrix equation
Eqn(overset(A, "A"), "+",
overset(B, "B"), "=",
underset(AB, "A+B"))
# using a LaTeX expression as the label
Lambda <- latexMatrix("\\lambda", nrow=2, ncol=2,
diag=TRUE)
Eqn(overset(Lambda, "\\Lambda"))
# generate LaTeX expression for the Hat matrix, label as "H"
H <- "\\mathbf{X} (\\mathbf{X}^{\\top}\\mathbf{X})^{-1} \\mathbf{X}^{\\top}"
Eqn("\\mathbf{\\hat{y}} =", underbrace(H, "\\mathbf{H}"), "\\mathbf{y}")
# Combine this with overbrace
Eqn(overbrace(underbrace(H, "\\mathbf{H}"), "\\LARGE\\mathbf{\\hat{y}}"))
Eqn_newline()
Eqn_newline('10ex')
# more complete example
Eqn(underset("\\mathbf{X}", "(4 \\times 3)"),
"& = \\mathbf{U} \\mathbf{\\Lambda} \\mathbf{V}^\\top",
Eqn_newline('1ex'),
' & =',
latexMatrix("u", 4, 3),
latexMatrix("\\lambda", 3, 3, diag=TRUE),
latexMatrix("v", 3, 3, transpose = TRUE),
align=TRUE)
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)
Run the code above in your browser using DataLab