Returns the raw draw-record table produced by MicroTeX's layout pass together with the bounding-box metadata. Useful for debugging alignment issues, building custom grobs on top of the layout, or counting glyphs/paths/rules in a formula.
Arguments
- tex
Character string of LaTeX math code.
- math_font
Name of the math font to use (e.g.,
"stix"). Use""(default) for Lete Sans Math, which pairs with R's default sans-serif text font. Seeavailable_math_fontsfor loaded fonts.- max_width
Numeric maximum width in big points for automatic line wrapping. Use
0(default) for no wrapping.- tex_style
Character: TeX style override. One of
""(default; let the parser decide),"display","text","script", or"scriptscript". Seelatex_grobfor the semantics of each value.- input_mode
How
texis interpreted before being parsed."mixed"wraps the input in\text{...}so the string reads as ordinary text and$...$(or\(...\)) opens math mode, matching document-level LaTeX semantics. Useful for labels that arrive from external sources mixing prose and math without explicit\text{}markers."math"(default) is the standard MicroTeX behaviour — the whole string is treated as math, so unwrapped prose renders as spaced math italics. The default can be changed globally vialatex_options(input_mode = "mixed"). Seelatex_wrapfor details on the wrapping process.- render_mode
Character string:
"typeface"(default) renders glyphs as native text using the math font, producing selectable/accessible text in PDF and SVG output. Bundled math fonts and any registered viaload_fontare read directly from their OTF files — no system-wide font install is required. Falls back to path mode automatically on devices that lack the R \(\geq\) 4.3 glyph engine (e.g., the basepdf()device). For selectable PDF output, prefercairo_pdf."path"renders math symbols as filled vector paths (works on all devices but text is not selectable in PDF/SVG).- gp
Graphical parameters (see
gpar). Common entries:col(formula foreground),fontfamily/fontface(text font),fontsize/cex(formula size), andlineheight(multi-line spacing). Seelatex_grobfor how each of these flows through MicroTeX.
Value
A list with class "latex_tree" containing:
recordsData frame of draw records (one row per glyph, path, line, rect, or text block). Columns include
type,x,y,glyph,font_size,color,text,codepoint,font_file.bboxNamed numeric vector with
width,height,depth,baseline(all in big points).texThe (macro-expanded) input string.
render_modeRendering mode used for the layout.
Examples
# \donttest{
tree <- latex_tree("\\frac{a}{b}")
print(tree)
#> <latex_tree>
#> tex: \frac{a}{b}
#> render_mode: typeface
#> bbox: width=7.00 height=25.00 depth=9.00 baseline=0.63 (bigpts)
#> records: 3
#> glyph 2
#> line 1
head(tree$records)
#> type x y glyph font_size color x2 y2 width height rx
#> 1 glyph 0.1890002 7.196 3628 14 #000000 NA NA NA NA NA
#> 2 line 0.0000000 10.596 NA NA #000000 7.392 10.596 NA NA NA
#> 3 glyph 0.0000000 25.796 3629 14 #000000 NA NA NA NA NA
#> ry lwd text font_style rotation path codepoint
#> 1 NA NA <NA> NA 0 NULL NA
#> 2 NA 1.32 <NA> NA 0 NULL NA
#> 3 NA NA <NA> NA 0 NULL NA
#> font_file
#> 1 /home/runner/work/_temp/Library/gridmicrotex/fonts/LeteSansMath.otf
#> 2 <NA>
#> 3 /home/runner/work/_temp/Library/gridmicrotex/fonts/LeteSansMath.otf
# }