( tokens: Token | Token[] | [Token[] | Token][] )
| 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 | |
| 468 | export function countTokens(s: string): number { |
| 469 | return tokenize(s).length; |
| 470 | } |
| 471 | |
| 472 | export 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(); |
no test coverage detected