% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/latex-tree.R
\name{latex_tree}
\alias{latex_tree}
\title{Inspect the parsed layout of a LaTeX expression}
\usage{
latex_tree(
  tex,
  math_font = "",
  max_width = 0,
  tex_style = "",
  input_mode = c("mixed", "math"),
  render_mode = c("typeface", "path"),
  gp = grid::gpar()
)
}
\arguments{
\item{tex}{Character string of LaTeX math code.}

\item{math_font}{Name of the math font to use (e.g., \code{"stix"}).
Use \code{""} (default) for Lete Sans Math, which pairs with R's
default sans-serif text font.
See \code{\link{available_math_fonts}} for loaded fonts.}

\item{max_width}{Numeric maximum width in big points for automatic
line wrapping.  Use \code{0} (default) for no wrapping.}

\item{tex_style}{Character: TeX style override. One of \code{""}
(default; let the parser decide), \code{"display"}, \code{"text"},
\code{"script"}, or \code{"scriptscript"}. See
\code{\link{latex_grob}} for the semantics of each value.}

\item{input_mode}{How \code{tex} is interpreted before being parsed.
\code{"mixed"} (default) wraps the input in \code{\\text{...}} so the
string reads as ordinary text and \code{$...$} (or \code{\\(...\\)})
opens math mode, matching document-level LaTeX semantics. Useful for
labels that arrive from external sources mixing prose and math without
explicit \code{\\text{}} markers. \code{"math"} is the classic
MicroTeX behaviour --- the whole string is treated as math, so unwrapped
prose renders as spaced math italics. The default can be changed globally via
\code{\link{latex_options}(input_mode = "math")}. See \code{\link{latex_wrap}}
for details on the wrapping process.}

\item{render_mode}{Character string: \code{"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 via \code{\link{load_math_font}}
are 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 \eqn{\geq} 4.3 glyph engine (e.g., the base \code{pdf()} device).
For selectable PDF output, prefer \code{\link[grDevices]{cairo_pdf}}.
\code{"path"} renders math symbols as filled vector paths (works on
all devices but text is not selectable in PDF/SVG).}

\item{gp}{Graphical parameters (see \code{\link[grid]{gpar}}).
Common entries: \code{col} (formula foreground), \code{fontfamily}
(text font), \code{fontsize} / \code{cex}
(formula size), and \code{lineheight} (multi-line spacing). See
\code{\link{latex_grob}} for how each of these flows through
MicroTeX.}
}
\value{
A list with class \code{"latex_tree"} containing:
\describe{
\item{\code{records}}{Data frame of draw records (one row per
glyph, path, line, rect, or text block). Columns include
\code{type}, \code{x}, \code{y}, \code{glyph}, \code{font_size},
\code{color}, \code{text}, \code{codepoint}, \code{font_file}.}
\item{\code{bbox}}{Named numeric vector with \code{width},
\code{height}, \code{depth}, \code{baseline} (all in big points).}
\item{\code{tex}}{The (macro-expanded) input string.}
\item{\code{render_mode}}{Rendering mode used for the layout.}
}
}
\description{
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.
}
\examples{
\donttest{
  tree <- latex_tree("\\\\frac{a}{b}")
  print(tree)
  head(tree$records)
}
}
\seealso{
\code{\link{latex_grob}}, \code{\link{latex_dims}}
}
