Settings

Struct Settings 

Source
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

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

Source

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
§Error Handling

Errors include the error code and message, with optional location information from the token for precise error reporting.

Source

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.

Source

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: A TrustContext 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.

Source

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 map
  • min_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

Trait Implementations§

Source§

impl Clone for Settings

Source§

fn clone(&self) -> Settings

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Settings

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Settings

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.