pub struct Settings {Show 16 fields
pub display_mode: bool,
pub output: OutputFormat,
pub leqno: bool,
pub fleqn: bool,
pub throw_on_error: bool,
pub error_color: String,
pub macros: RefCell<MacroMap>,
pub min_rule_thickness: f64,
pub color_is_text_color: bool,
pub strict: StrictSetting,
pub trust: TrustSetting,
pub max_size: f64,
pub max_expand: usize,
pub global_group: bool,
pub size_multiplier: f64,
pub color: Option<String>,
}
Expand description
Core settings structure for KaTeX rendering configuration.
This struct contains all resolved configuration options that control KaTeX’s behavior during mathematical expression parsing and rendering. Unlike the builder inputs, all fields have concrete values with no options.
§LaTeX/KaTeX Context
These settings correspond to LaTeX document and package options that affect mathematical typesetting. KaTeX uses this structure to maintain consistent rendering behavior across different expressions and contexts.
§Cross-references
- See
Settings::builder
for ergonomic construction of settings. - Related to
OutputFormat
,StrictSetting
, andTrustSetting
. - Methods provide validation and utility functions.
Fields§
§display_mode: bool
Whether mathematical expressions are rendered in display (block) mode.
When true
, equations are centered and displayed on separate lines
with larger fonts. When false
, equations are rendered inline.
output: OutputFormat
The output format for rendered mathematical expressions.
Determines the markup format (HTML, MathML, or both) of the output.
leqno: bool
Whether equation numbers are placed on the left side.
Controls the positioning of equation numbers in numbered environments.
fleqn: bool
Whether equations are flushed to the left margin.
When true
, equations are left-aligned instead of centered.
throw_on_error: bool
Whether parsing/rendering errors should throw exceptions.
When true
, errors cause panics. When false
, errors are rendered
as colored text in the output.
error_color: String
CSS color value used for rendering error messages.
Applied to error text when throw_on_error
is false
.
macros: RefCell<MacroMap>
Map of custom macro definitions.
Contains user-defined LaTeX macros for extending functionality. Keys are macro names, values are their LaTeX definitions.
min_rule_thickness: f64
Minimum thickness for rendered rules (lines).
Prevents lines from becoming too thin to be visible. In points.
color_is_text_color: bool
Whether \color
commands affect surrounding text color.
When true
, color commands modify text color. When false
,
they only affect mathematical content.
strict: StrictSetting
Configuration for strict LaTeX compatibility checking.
Controls how KaTeX handles non-standard LaTeX input.
trust: TrustSetting
Configuration for trust validation of dangerous content.
Controls validation of URLs, styles, and other potentially unsafe inputs.
max_size: f64
Maximum allowed size for rendered expressions.
Prevents excessive memory usage from very large expressions. In points.
max_expand: usize
Maximum limit for macro expansion iterations.
Prevents infinite loops in macro expansion.
global_group: bool
Whether settings persist globally across render calls.
When true
, settings remain active for subsequent expressions.
size_multiplier: f64
Size multiplier for scaling rendered expressions.
Controls the overall size scaling factor for mathematical expressions.
color: Option<String>
Color value for mathematical content.
CSS color value used for rendering mathematical expressions.
Implementations§
Source§impl Settings
impl Settings
Sourcepub fn report_nonstrict(
&self,
error_code: &str,
error_msg: &str,
token: Option<&dyn ErrorLocationProvider>,
) -> Result<(), ParseError>
pub fn report_nonstrict( &self, error_code: &str, error_msg: &str, token: Option<&dyn ErrorLocationProvider>, ) -> Result<(), ParseError>
Reports non-standard LaTeX input according to the current strict settings.
This method handles non-LaTeX-compatible input based on the configured strictness level. It may ignore the input, log a warning, or return an error.
§Parameters
error_code
: A string identifier for the type of strict violation.error_msg
: A human-readable description of the issue.token
: Optional location information for error reporting.
§Returns
Ok(())
if the input is accepted (ignore or warn modes).Err(ParseError)
if the input is rejected (error mode).
§Behavior by Strict Mode
StrictMode::Ignore
: Silently accepts the input.StrictMode::Warn
: Logs a warning and accepts the input.StrictMode::Error
: Returns an error rejecting the input.
§Error Handling
Errors include the error code and message, with optional location information from the token for precise error reporting.
Sourcepub fn use_strict_behavior(
&self,
error_code: &str,
error_msg: &str,
token: Option<&dyn ErrorLocationProvider>,
) -> bool
pub fn use_strict_behavior( &self, error_code: &str, error_msg: &str, token: Option<&dyn ErrorLocationProvider>, ) -> bool
Determines whether strict (LaTeX-adhering) behavior should be enforced.
This method checks if the given input should trigger strict error handling based on the current strict settings. Unlike report_nonstrict, this method only returns a boolean without performing any actions.
§Parameters
error_code
: A string identifier for the type of strict violation.error_msg
: A human-readable description of the issue.token
: Optional location information for error reporting.
§Returns
true
if strict behavior should be enforced (error mode).false
if the input should be accepted (ignore or warn modes).
§Notes
In warn mode, this method logs the warning but returns false
to
indicate that processing should continue rather than fail.
Sourcepub fn is_trusted(&self, context: &mut TrustContext) -> bool
pub fn is_trusted(&self, context: &mut TrustContext) -> bool
Evaluates whether potentially dangerous input should be trusted.
This method validates potentially unsafe content (such as URLs in
\href
commands) according to the current trust settings. It
automatically infers protocols from URLs when possible.
§Parameters
context
: ATrustContext
containing details about the potentially dangerous content, including the command, URL, styles, etc.
§Returns
true
if the content should be trusted and rendered.false
if the content should be rejected as unsafe.
§Protocol Inference
If context.url
is provided but context.protocol
is None
, this
method attempts to infer the protocol from the URL. If the URL is
malformed or has an invalid protocol, it returns false
immediately.
§Security Considerations
This method is critical for preventing XSS attacks and other security vulnerabilities. Trust functions should carefully validate all aspects of the context before granting trust.
Sourcepub fn builder() -> SettingsBuilder
pub fn builder() -> SettingsBuilder
Creates a new Settings
instance from optional configuration values.
This constructor applies default values for any None
options in the
provided builder inputs, ensuring all settings have concrete
values.
§Parameters
options
: Configuration options with optional values.
§Returns
A fully configured Settings
instance with all fields set to concrete
values.
§Default Values
display_mode
:false
(inline mode)output
:OutputFormat::HtmlAndMathml
leqno
:false
(right-side numbering)fleqn
:false
(centered equations)throw_on_error
:true
(throw on errors)error_color
:"#cc0000"
(red)macros
: Empty mapmin_rule_thickness
:0.0
color_is_text_color
:false
strict
: StrictSetting::Mode(StrictMode::Ignore)trust
: TrustSetting::Bool(false)max_size
:f64::INFINITY
max_expand
:1000
global_group
:false