Top Description Fields Constructors Methods
org.jabref.latexconv.internal

public abstract Class TokenWalker

extends Object
Class Inheritance
Known Direct Subclasses
org.jabref.latexconv.internal.UnicodeEmitter, org.jabref.latexconv.internal.HtmlEmitter
Imports
java.util.List, .Map, .Optional, java.util.concurrent.ConcurrentHashMap, org.jabref.latexconv.ConversionOptions, org.jspecify.annotations.Nullable, uk.ac.ed.ph.snuggletex.InputError, .SnuggleSession, uk.ac.ed.ph.snuggletex.definitions.ComputedStyle, .CoreErrorCode, .LaTeXMode, uk.ac.ed.ph.snuggletex.internal.FrozenSlice, .WorkingDocument, uk.ac.ed.ph.snuggletex.tokens.BraceContainerToken, .CommandToken, .EnvironmentToken, .ErrorToken, .FlowToken, .MathCharacterToken, .TokenType

Walks a parsed SnuggleTeX token tree and renders it through the output hooks implemented by UnicodeEmitter and HtmlEmitter, driven by ConversionTable.

Recoverable parse errors are handled inline: unknown commands (TTEC00) are reproduced from the source per ConversionOptions.UnknownCommandPolicy, and stray _/^ in text mode (TTEM03) render as _(...)/^(...). Any other parse error aborts via UnsupportedLatexException, which the public API translates into returning the normalized input.

Field Summary

Modifier and TypeField and Description
private static final Map<String, String>
MATH_ACCENT_ALIASES

Math-mode accent commands expressed as the table's short accent spellings.

protected final ConversionOptions
private static final Map<String, Map<Integer, Integer>>

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
private static Optional<String>
accentCombining(String commandName)

protected abstract void
appendEmphasized(StringBuilder out, String renderedContent)

\mkbibemph{..} content, already rendered.

protected abstract void
appendMathPassthrough(StringBuilder out, String source)

A math span emitted verbatim under ConversionOptions.MathMode#PASSTHROUGH, delimiters included.

protected abstract void
appendPlain(StringBuilder out, String text)

Literal output text (converted characters, preserved commands, math characters).

protected abstract void
appendQuoted(StringBuilder out, String renderedContent)

\enquote{..}/\mkbibquote{..} content, already rendered.

protected abstract void
appendScript(StringBuilder out, String renderedContent, boolean superscript)

A super-/subscript whose content was already rendered by a nested walk.

protected abstract void
appendText(StringBuilder out, String text, @Nullable ComputedStyle style)

A text run from the source, with the style SnuggleTeX computed for it (\textit{..} and friends survive only here).

private static String
applyCombining(String base, String combining)

Inserts the combining mark after the base's first codepoint: the accent belongs to the first letter even when the tokenizer hands over a longer run (\'nski -> ński).

public String
private int
emitCommand(List<FlowToken> tokens, int index, StringBuilder out)

private void
private int
emitError(List<FlowToken> tokens, int index, StringBuilder out)

private int
emitGenericCommand(List<FlowToken> tokens, int index, CommandToken command, String name, StringBuilder out)

private int
emitToken(List<FlowToken> tokens, int index, StringBuilder out)

Emits the token at index (possibly consuming look-ahead siblings, e.g. an accent's operand) and returns the index of the next unconsumed token.

private static String
fenceText(CharSequence source)

Normalizes a fence's source text ((, [, but also \left( or \{) to the bare bracket character.

private static int
findBalancedClose(WorkingDocument document, int openIndex)

private static boolean
hasArgument(CommandToken command, int argumentIndex)

private static boolean
protected static String
mapThroughStyle(String text, String styleCommandName)

protected abstract boolean
scriptsAsSource()

Whether scripts should be emitted as their verbatim source instead of converted (the convertScripts=false round-trip mode; meaningless for HTML output).

private static int
skipTokensBefore(List<FlowToken> tokens, int index, int documentEnd)

protected static Map<Integer, Integer>
styleMap(String styleCommandName)

protected String
walk(List<FlowToken> tokens)

private String
walkArgument(CommandToken command, int argumentIndex)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

MATH_ACCENT_ALIASESback to summary
private static final Map<String, String> MATH_ACCENT_ALIASES

Math-mode accent commands expressed as the table's short accent spellings.

optionsback to summary
protected final ConversionOptions options
STYLE_MAP_CACHEback to summary
private static final Map<String, Map<Integer, Integer>> STYLE_MAP_CACHE

Constructor Detail

TokenWalkerback to summary
protected TokenWalker(ConversionOptions options)

Method Detail

accentCombiningback to summary
private static Optional<String> accentCombining(String commandName)
appendEmphasizedback to summary
protected abstract void appendEmphasized(StringBuilder out, String renderedContent)

\mkbibemph{..} content, already rendered.

appendMathPassthroughback to summary
protected abstract void appendMathPassthrough(StringBuilder out, String source)

A math span emitted verbatim under ConversionOptions.MathMode#PASSTHROUGH, delimiters included.

appendPlainback to summary
protected abstract void appendPlain(StringBuilder out, String text)

Literal output text (converted characters, preserved commands, math characters).

appendQuotedback to summary
protected abstract void appendQuoted(StringBuilder out, String renderedContent)

\enquote{..}/\mkbibquote{..} content, already rendered.

appendScriptback to summary
protected abstract void appendScript(StringBuilder out, String renderedContent, boolean superscript)

A super-/subscript whose content was already rendered by a nested walk.

appendTextback to summary
protected abstract void appendText(StringBuilder out, String text, @Nullable ComputedStyle style)

A text run from the source, with the style SnuggleTeX computed for it (\textit{..} and friends survive only here). text already has ~ resolved to no-break space.

applyCombiningback to summary
private static String applyCombining(String base, String combining)

Inserts the combining mark after the base's first codepoint: the accent belongs to the first letter even when the tokenizer hands over a longer run (\'nski -> ński).

emitback to summary
public String emit(SnuggleSession session)
emitCommandback to summary
private int emitCommand(List<FlowToken> tokens, int index, StringBuilder out)
emitEnvironmentback to summary
private void emitEnvironment(EnvironmentToken environment, StringBuilder out)
emitErrorback to summary
private int emitError(List<FlowToken> tokens, int index, StringBuilder out)
emitGenericCommandback to summary
private int emitGenericCommand(List<FlowToken> tokens, int index, CommandToken command, String name, StringBuilder out)
emitTokenback to summary
private int emitToken(List<FlowToken> tokens, int index, StringBuilder out)

Emits the token at index (possibly consuming look-ahead siblings, e.g. an accent's operand) and returns the index of the next unconsumed token.

fenceTextback to summary
private static String fenceText(CharSequence source)

Normalizes a fence's source text ((, [, but also \left( or \{) to the bare bracket character.

findBalancedCloseback to summary
private static int findBalancedClose(WorkingDocument document, int openIndex)
hasArgumentback to summary
private static boolean hasArgument(CommandToken command, int argumentIndex)
hasWhitespaceGapback to summary
private static boolean hasWhitespaceGap(FlowToken previous, FlowToken current)
mapThroughStyleback to summary
protected static String mapThroughStyle(String text, String styleCommandName)
scriptsAsSourceback to summary
protected abstract boolean scriptsAsSource()

Whether scripts should be emitted as their verbatim source instead of converted (the convertScripts=false round-trip mode; meaningless for HTML output).

skipTokensBeforeback to summary
private static int skipTokensBefore(List<FlowToken> tokens, int index, int documentEnd)
styleMapback to summary
protected static Map<Integer, Integer> styleMap(String styleCommandName)
walkback to summary
protected String walk(List<FlowToken> tokens)
walkArgumentback to summary
private String walkArgument(CommandToken command, int argumentIndex)