MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / tokensToString

Function tokensToString

src/compute-engine/latex-syntax/tokenizer.ts:454–483  ·  view source on GitHub ↗
(
  tokens: Token | Token[] | [Token[] | Token][]
)

Source from the content-addressed store, hash-verified

452 discardedLength: line.length - m[0].length,
453 });
454 }
455 }
456 lineOffset += line.length + separator.length;
457 }
458
459 const tokenizer = new Tokenizer(stream);
460 const result: Token[] = [];
461
462 do result.push(...expand(tokenizer, args));
463 while (!tokenizer.end());
464
465 return result;
466}
467
468export function countTokens(s: string): number {
469 return tokenize(s).length;
470}
471
472export function joinLatex(segments: Iterable<string>): string {
473 let sep = '';
474 let result = '';
475 for (const segment of segments) {
476 if (segment === undefined || segment === null) continue;
477 if (typeof segment === 'string') {
478 // If the segment begins with a char that *could* be in a command
479 // name... insert a separator (if one was needed for the previous segment)
480 if (/[a-zA-Z]/.test(segment[0])) result += sep;
481
482 // If the segment ends in a command add a space before the next segment
483 if (/\\[a-zA-Z]+\*?$/.test(segment)) sep = ' ';
484 else sep = '';
485 }
486 result += segment.toString();

Callers 6

latexMethod · 0.90
parseTabularMethod · 0.90
parseSyntaxErrorMethod · 0.90
makeIndexedEntryFunction · 0.90
makeSerializeHandlerFunction · 0.90
isValidEntryFunction · 0.90

Calls 2

joinLatexFunction · 0.85
mapMethod · 0.65

Tested by

no test coverage detected