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

public final Class ConversionTable

extends Object
Class Inheritance
Imports
java.io.BufferedReader, .IOException, .InputStream, .InputStreamReader, .UncheckedIOException, java.nio.charset.StandardCharsets, java.util.ArrayList, .LinkedHashMap, .List, .Map, .Optional, .OptionalInt, java.util.regex.Matcher, .Pattern

In-memory view of conversion-table.tsv, the generated LaTeX <-> Unicode conversion table bundled as a module resource. See tools/GenerateTable.java and tools/CONFLICTS.md in the source tree for how the table is generated and merged from its upstream sources.

The table is loaded lazily and exactly once, on first access to any lookup method.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static record

Field Summary

Modifier and TypeField and Description
private final Map<Integer, String>
private final Map<String, ConversionTable.Row>
private static final Pattern
private final Map<String, ConversionTable.Row>
private final Map<Integer, ConversionTable.Row>
private static final String
private final List<ConversionTable.Row>
private static final Pattern
private final Map<Integer, Integer>
private final Map<Integer, Integer>
private final Map<Integer, Integer>
private final Map<Integer, Integer>
private static final Pattern

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Optional<String>
accentForCombining(int codePoint)

Reverse of combiningForAccent(String): the bare accent command producing a combining mark, for the encode direction.

public static OptionalInt
baseForSubscript(int codePoint)

Reverse of subscriptFor(int): returns the base codepoint for a styled subscript codepoint.

public static OptionalInt
baseForSuperscript(int codePoint)

Reverse of superscriptFor(int): returns the base codepoint for a styled superscript codepoint.

public static Optional<String>
combiningForAccent(String accentCommand)

Looks up the combining Unicode mark produced by a bare LaTeX accent command (e.g. \", \`, \'), for composing it onto a base character.

public static Map<String, Integer>
commandArities()

Distinct alphabetic LaTeX command names appearing anywhere in the table, mapped to the argument count implied by the row's latex text: bare \name implies 0, \name{...} implies 1.

public static Optional<String>
commandToUnicode(String latex)

Decodes a LaTeX command/spelling to its Unicode replacement text.

public static boolean
encodeNeedsMathMode(int codePoint)

Whether the encode-preferred spelling for codePoint is only valid in math mode (\pi and friends), so encoders must wrap it in $...$.

private static ConversionTable
public static Optional<String>
latexForCodePoint(int codePoint)

Encodes a Unicode codepoint back to LaTeX.

private static List<ConversionTable.Row>
load()

public static int
size()

Total number of rows loaded from the table, for test sanity checks.

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

Builds the base-codepoint -> styled-codepoint map for a math alphabet style command, e.g. styleMap("mathbb") maps 'A' to the codepoint of 𝔸.

public static OptionalInt
subscriptFor(int codePoint)

Returns the styled subscript codepoint for a base codepoint, if this table has one.

public static OptionalInt
superscriptFor(int codePoint)

Returns the styled superscript codepoint for a base codepoint (e.g. 't' -> 'ᵗ'), if this table has one.

private static String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

accentByCombiningback to summary
private final Map<Integer, String> accentByCombining
combiningByAccentback to summary
private final Map<String, ConversionTable.Row> combiningByAccent
COMMAND_SPELLINGback to summary
private static final Pattern COMMAND_SPELLING
decodableback to summary
private final Map<String, ConversionTable.Row> decodable
encodePreferredback to summary
private final Map<Integer, ConversionTable.Row> encodePreferred
RESOURCE_PATHback to summary
private static final String RESOURCE_PATH
rowsback to summary
private final List<ConversionTable.Row> rows
SCRIPT_LATEXback to summary
private static final Pattern SCRIPT_LATEX
subscriptBaseToStyledback to summary
private final Map<Integer, Integer> subscriptBaseToStyled
subscriptStyledToBaseback to summary
private final Map<Integer, Integer> subscriptStyledToBase
superscriptBaseToStyledback to summary
private final Map<Integer, Integer> superscriptBaseToStyled
superscriptStyledToBaseback to summary
private final Map<Integer, Integer> superscriptStyledToBase
UNICODE_ESCAPEback to summary
private static final Pattern UNICODE_ESCAPE

Constructor Detail

ConversionTableback to summary
private ConversionTable()

Method Detail

accentForCombiningback to summary
public static Optional<String> accentForCombining(int codePoint)

Reverse of combiningForAccent(String): the bare accent command producing a combining mark, for the encode direction.

baseForSubscriptback to summary
public static OptionalInt baseForSubscript(int codePoint)

Reverse of subscriptFor(int): returns the base codepoint for a styled subscript codepoint.

baseForSuperscriptback to summary
public static OptionalInt baseForSuperscript(int codePoint)

Reverse of superscriptFor(int): returns the base codepoint for a styled superscript codepoint.

combiningForAccentback to summary
public static Optional<String> combiningForAccent(String accentCommand)

Looks up the combining Unicode mark produced by a bare LaTeX accent command (e.g. \", \`, \'), for composing it onto a base character. Only considers diacritics rows flagged combining.

commandAritiesback to summary
public static Map<String, Integer> commandArities()

Distinct alphabetic LaTeX command names appearing anywhere in the table, mapped to the argument count implied by the row's latex text: bare \name implies 0, \name{...} implies 1. When a name occurs with both arities the higher one wins — an argument-taking registration still surfaces bare occurrences (as a recoverable parse error), while a zero-argument registration would silently detach the braces from \name{x}.

Used to register the table's vocabulary with the parser; single-character command names (\", \$, ...) are the parser's own business and excluded here.

commandToUnicodeback to summary
public static Optional<String> commandToUnicode(String latex)

Decodes a LaTeX command/spelling to its Unicode replacement text.

Decode direction only: rows flagged encode-only are never returned here, even though they're valid latex spellings recognized during encoding. Returns an empty Optional when latex has no decode row (not merely "unknown" - it may be a spelling this table deliberately excludes from decode, e.g. an ambiguous shared spelling resolved in favor of a different codepoint; see tools/CONFLICTS.md).

encodeNeedsMathModeback to summary
public static boolean encodeNeedsMathMode(int codePoint)

Whether the encode-preferred spelling for codePoint is only valid in math mode (\pi and friends), so encoders must wrap it in $...$.

instanceback to summary
private static ConversionTable instance()
latexForCodePointback to summary
public static Optional<String> latexForCodePoint(int codePoint)

Encodes a Unicode codepoint back to LaTeX.

Encode direction only: returns the table's encode-preferred row for codePoint - the one row (per the generator's invariant, there is at most one) that is neither alt nor decode-only. Returns an empty Optional when no source offers an encode-preferred spelling for this codepoint (e.g. it was deliberately excluded via Biber's encode_exclude, or the codepoint simply isn't in any of the three sources).

loadback to summary
private static List<ConversionTable.Row> load()
sizeback to summary
public static int size()

Total number of rows loaded from the table, for test sanity checks.

styleMapback to summary
public static Map<Integer, Integer> styleMap(String styleCommandName)

Builds the base-codepoint -> styled-codepoint map for a math alphabet style command, e.g. styleMap("mathbb") maps 'A' to the codepoint of 𝔸.

Only styles rows whose latex matches \<styleCommandName>{X} for a single-codepoint X are considered (see tools/CONFLICTS.md for why \text* alias spellings are skipped entirely rather than merged in here). The returned map is unmodifiable.

subscriptForback to summary
public static OptionalInt subscriptFor(int codePoint)

Returns the styled subscript codepoint for a base codepoint, if this table has one.

superscriptForback to summary
public static OptionalInt superscriptFor(int codePoint)

Returns the styled superscript codepoint for a base codepoint (e.g. 't' -> 'ᵗ'), if this table has one.

unescapeUnicodeback to summary
private static String unescapeUnicode(String value)
org.jabref.latexconv.internal back to summary

private final Class ConversionTable.Holder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final ConversionTable

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
private static final ConversionTable INSTANCE

Constructor Detail

Holderback to summary
private Holder()
org.jabref.latexconv.internal back to summary

private final Record ConversionTable.Row

extends Record
Class Inheritance
Record Components
category:String 
unicode:String 
latex:String 
flags:List<String> 

Field Summary

Modifier and TypeField and Description
private final String
category

Record Component accessed by category().

private final List<String>
flags

Record Component accessed by flags().

private final String
latex

Record Component accessed by latex().

private final String
unicode

Record Component accessed by unicode().

Constructor Summary

AccessConstructor and Description
private
Row(String category, String unicode, String latex, List<String> flags)

Method Summary

Modifier and TypeMethod and Description
public String
category()

Record Component getter of category.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public List<String>
flags()

Record Component getter of flags.

pack-priv boolean
public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public String
latex()

Record Component getter of latex.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

public String
unicode()

Record Component getter of unicode.

Field Detail

categoryback to summary
private final String category

Record Component accessed by category().

flagsback to summary
private final List<String> flags

Record Component accessed by flags().

latexback to summary
private final String latex

Record Component accessed by latex().

unicodeback to summary
private final String unicode

Record Component accessed by unicode().

Constructor Detail

Rowback to summary
private Row(String category, String unicode, String latex, List<String> flags)

Method Detail

categoryback to summary
public String category()

Record Component getter of category.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
flagsback to summary
public List<String> flags()

Record Component getter of flags.

hasFlagback to summary
pack-priv boolean hasFlag(String flag)
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

latexback to summary
public String latex()

Record Component getter of latex.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

unicodeback to summary
public String unicode()

Record Component getter of unicode.