UNPKG

tex2typst

Version:

JavaScript library for converting TeX code to Typst

106 lines (105 loc) 3.42 kB
export declare enum TexTokenType { ELEMENT = 0, COMMAND = 1, TEXT = 2, COMMENT = 3, SPACE = 4, NEWLINE = 5, CONTROL = 6, UNKNOWN = 7 } export declare class TexToken { type: TexTokenType; value: string; constructor(type: TexTokenType, value: string); eq(token: TexToken): boolean; toString(): string; } export interface TexSupsubData { base: TexNode; sup?: TexNode; sub?: TexNode; } export type TexSqrtData = TexNode; export type TexArrayData = TexNode[][]; /** * element: 0-9, a-z, A-Z, punctuations such as +-/*,:; etc. * symbol: LaTeX macro with no parameter. e.g. \sin \cos \int \sum * unaryFunc: LaTeX macro with 1 parameter. e.g. \sqrt{3} \log{x} \exp{x} * binaryFunc: LaTeX macro with 2 parameters. e.g. \frac{1}{2} * text: text enclosed by braces. e.g. \text{hello world} * empty: special type when something is empty. e.g. the base of _{a} or ^{a} * whitespace: space, tab, newline */ type TexNodeType = 'element' | 'text' | 'comment' | 'whitespace' | 'control' | 'ordgroup' | 'supsub' | 'unaryFunc' | 'binaryFunc' | 'leftright' | 'beginend' | 'symbol' | 'empty' | 'unknownMacro'; export declare class TexNode { type: TexNodeType; content: string; args?: TexNode[]; data?: TexSqrtData | TexSupsubData | TexArrayData; constructor(type: TexNodeType, content: string, args?: TexNode[], data?: TexSqrtData | TexSupsubData | TexArrayData); eq(other: TexNode): boolean; toString(): string; serialize(): TexToken[]; } export declare enum TypstTokenType { NONE = 0, SYMBOL = 1, ELEMENT = 2, TEXT = 3, COMMENT = 4, SPACE = 5, CONTROL = 6, NEWLINE = 7 } export declare class TypstToken { type: TypstTokenType; value: string; constructor(type: TypstTokenType, content: string); eq(other: TypstToken): boolean; isOneOf(tokens: TypstToken[]): boolean; toNode(): TypstNode; toString(): string; } export interface TypstSupsubData { base: TypstNode; sup?: TypstNode; sub?: TypstNode; } export type TypstArrayData = TypstNode[][]; export interface TypstLrData { leftDelim: string | null; rightDelim: string | null; } type TypstNodeType = 'atom' | 'symbol' | 'text' | 'control' | 'comment' | 'whitespace' | 'none' | 'group' | 'supsub' | 'funcCall' | 'fraction' | 'align' | 'matrix' | 'cases' | 'unknown'; export type TypstPrimitiveValue = string | boolean | TypstNode; export type TypstNamedParams = { [key: string]: TypstPrimitiveValue; }; export declare class TypstNode { type: TypstNodeType; content: string; args?: TypstNode[]; data?: TypstSupsubData | TypstArrayData | TypstLrData; options?: TypstNamedParams; constructor(type: TypstNodeType, content: string, args?: TypstNode[], data?: TypstSupsubData | TypstArrayData | TypstLrData); setOptions(options: TypstNamedParams): void; eq(other: TypstNode): boolean; isOverHigh(): boolean; } export declare const TYPST_NONE: TypstNode; export declare const TYPST_TRUE: TypstPrimitiveValue; export declare const TYPST_FALSE: TypstPrimitiveValue; export interface Tex2TypstOptions { nonStrict?: boolean; preferTypstIntrinsic?: boolean; preferShorthands?: boolean; keepSpaces?: boolean; fracToSlash?: boolean; inftyToOo?: boolean; nonAsciiWrapper?: string; customTexMacros?: { [key: string]: string; }; } export {};