The goal here is to render labels and units (where present)
in a way that supports subscripts and superscripts
for both plots and tables in either html or latex contexts.
The current implementation writes an 'expression' attribute
to support figure labels and a 'title' attribute to support
tables. print.decorated_ggplot
will attempt
to honor the expression attribute if it exists.
tablet.data.frame
will attempt to honor
the title attribute if it exists (see Details there).
An attempt is made to guess the output format (html or latex).
In addition to the 'title' and 'expression' attributes, enscript() writes
a 'plotmath' attribute to store plotmath versions of factor levels,
where present. By default, factor levels are converted to their
latex or html equivalents. However, print.decorated_ggplot
will use the plotmath versions of factor labels for legends and
facet labels. If a 'plotmath' attribute already exists, it is not
overwritten, preventing
the same variable from being accidentally transformed twice.
To flexibly support latex, html, and plotmath, this function
expects column labels and units to be encoded in "spork" syntax.
See as_spork
for details and examples.
Briefly, "_" precedes a subscript, "^" precedes a superscript,
and "." is used to force the termination of either a
superscript or a subscript where necessary. For best results,
units should be written using *, /, and ^; e.g. "kg*m^2/s^2"
not "kg m2 s-2" (although both are valid:
see is_parseable
). A literal backslash followed by "n"
represents a newline. Greek letters are represented by their names,
except where names are enclosed in backticks.
enscript()
always calls resolve()
for the indicated
columns, to make units present where appropriate.