INNER CODE UNIT · TypeScript
estimatedHalf
RyanYipeng/SyncCaster · apps/extension/src/content-scripts/index.ts:384
const estimatedHalf = Math.floor(len / 2);
for (let offset = 0; offset <= Math.min(10, estimatedHalf); offset++) {
for (const delta of [0, -offset, offset]) {
const candidateStart = estimatedHalf + delta;
if (candidateStart > 0 && candidateStart < firstSpecialIdx) {
const candidateLatex = text.substring(candidateStart);
const renderText = text.substring(0, candidateStart);
if (candidateLatex.length > 0 && renderText.length > 0) {
const matchLen = Math.min(3, renderText.length, candidateLatex.length);
if (renderText.substring(0, matchLen) === candidateLatex.substring(0, matchLen)) {
latexStart = candidateStart;
console.log('[math] Found LaTeX start via half-point search:', latexStart);
break;
}
}
}
}
if (latexStart >= 0) break;