This function is used to insert equations into flextable.
It is used to add it to the content of a cell of the
flextable with the functions compose(), append_chunks()
or prepend_chunks().
To use this function, package 'equatags' is required.
Arguments
- x
values containing the 'MathJax' equations
- width, height
size of the resulting equation. When they are not provided (
NULL, the default), the size is computed from the equation and the font size of the chunk withequatags::equation_size()(equatags >= 0.4.0), so thatautofit(),dim_pretty()andgen_grob()know the size of the equation; with an older version of 'equatags', 1 x 0.2 inch.- unit
unit for width and height, one of "in", "cm", "mm".
- props
an
fp_text_default()orofficer::fp_text()object to be used to format the text. If not specified, it will be the default value corresponding to the cell.
Size and drawing of equations
The style of equations follows the rule of Word, in every output: an
equation is in display style (large fractions, limits above and below
sums and products) when its paragraph only contains equations, and in
inline style as soon as the paragraph contains something else, even a
space. HTML and LaTeX outputs use \displaystyle for the display style,
and the size and gen_grob() use the same style.
The size computed by equatags::equation_size() is the one of the
equation laid out with the math font 'STIX Two Math'. Word and browsers
display equations with their own math font, so the displayed size may
differ slightly. With gen_grob() (R >= 4.3), equations are drawn with
equatags::equation_grob(), at their computed size.
In RTF documents, equations are images placed on the baseline of the
text (R >= 4.3). 'Word' does not leave room for the part of these images
below the baseline: in a cell with several lines, an equation larger than
the text, or with a fraction, can touch the next line. A larger line
spacing avoids it (line_spacing(), for example space = 1.3).
See also
Other chunk elements for paragraph:
as_b(),
as_bracket(),
as_chunk(),
as_highlight(),
as_i(),
as_image(),
as_qmd(),
as_strike(),
as_sub(),
as_sup(),
as_word_field(),
colorize(),
gg_chunk(),
grid_chunk(),
hyperlink_text(),
linerange(),
minibar(),
plot_chunk()
Examples
library(flextable)
if (require("equatags")) {
eqs <- c(
"(ax^2 + bx + c = 0)",
"a \\ne 0",
"x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}"
)
df <- data.frame(formula = eqs)
df
ft <- flextable(df)
ft <- mk_par(
x = ft, j = "formula",
value = as_paragraph(as_equation(formula))
)
ft <- align(ft, align = "center", part = "all")
ft <- autofit(ft)
ft
}
#> Loading required package: equatags
formula
