diff --git a/embd_res/klite.embd b/embd_res/klite.embd index 37fa4f0d3..a15e93008 100644 --- a/embd_res/klite.embd +++ b/embd_res/klite.embd @@ -7778,22 +7778,60 @@ Current version indicated by LITEVER below. function stashLatex(text) { //this function preserves the contents of multiline latex blocks so they don't get corrupted by markdown const latexBlocks = []; let counter = 0; + + const stash = (match) => { + const key = `%%LATEXBLK${counter++}%%`; + latexBlocks.push({ key, value: match }); + return key; + }; + + // 1. Blockquote-wrapped $$ blocks (existing) text = text.replace(/(^> \$\$\n([\s\S]*?)\n\$\$)/gm, (match) => { const key = `%%LATEXBLK${counter++}%%`; latexBlocks.push({ key, value: match.slice(2) }); return key; }); - text = text.replace(/(^ {0,6}\\\[\n([\s\S]*?)\n {0,6}\\\] {0,2}$|^\$\$\n([\s\S]*?)\n\$\$$|^ {2}\$\$\n {2}([\s\S]*?)\n {2}\$\$$|\$\$([^\n]+?)\$\$|\\\(([^\n]+?)\\\)|\\\[([^\n]+?)\\\])/gm, (match, p1, p2, p3, p4, p5, p6, p7) => { + + // 2. All block-level latex (existing) + text = text.replace(/(^ {0,6}\\\[\n([\s\S]*?)\n {0,6}\\\] {0,2}$|^\$\$\n([\s\S]*?)\n\$\$$|^ {2}\$\$\n {2}([\s\S]*?)\n {2}\$\$$|\$\$([^\n]+?)\$\$|\\\(([^\n]+?)\\\)|\\\[([^\n]+?)\\\])/gm, + (match) => stash(match) + ); + + // 3. Inline: $word$ or $letter$ — mirrors replaceLatex patterns + text = text.replace(/(^|[^\\])\$(\S[^$\n]*?\S)\$(?!\w)/g, (match, prefix, inner) => { + if (inner.startsWith('$')) return match; // buggy match guard + if (inner.replace(/\s+/g, '').match(/^\$+$/)) return match; // only dollar signs const key = `%%LATEXBLK${counter++}%%`; - latexBlocks.push({ key, value: match }); - return key; + latexBlocks.push({ key, value: `$${inner}$` }); + return prefix + key; }); - return { "text":text, "blocks":latexBlocks }; + + // 4. Inline: single letter/number $x$ + text = text.replace(/(^|[^\\])\$([A-Za-z0-9])\$(?!\d)/g, (match, prefix, inner) => { + const key = `%%LATEXBLK${counter++}%%`; + latexBlocks.push({ key, value: `$${inner}$` }); + return prefix + key; + }); + + // 5. Inline: $ content $ (space-padded variant) + text = text.replace(/(^|[^\\])\$ (\S[^$\n]*?) \$(?!\d)/g, (match, prefix, inner) => { + if (inner.replace(/\s+/g, '').match(/^\$+$/)) return match; + const key = `%%LATEXBLK${counter++}%%`; + latexBlocks.push({ key, value: `$ ${inner} $` }); + return prefix + key; + }); + + return { text, blocks: latexBlocks }; } - function unstashLatex(text, latexBlocks) { + function unstashLatex(text, latexBlocks, render) { for(let i=0;i<\/pre\>\n/g, "\n"); if(renderLatex) { - if(stashLatexRes!=null) - { - md = unstashLatex(md,stashLatexRes.blocks); - } //to aid the latex renderer, we temporarily add newlines between some blocks md = md.replace(/<\/li>
  • /gm, "
  • \n
  • "); md = md.replace(/<\/tr>\n\n
  • /gm, "
  • "); md = md.replace(/<\/tr>\n\n/gm, "").replace(/<\/ol>\n/gm, ""); md = md.replace(/\\([`_~\*\+\-\.\^\\\<\>\(\)\[\]])/gm, "$1"); @@ -17169,7 +17207,7 @@ Current version indicated by LITEVER below. switch(themeid) { case "0": return "The classic simple Kobold theme everyone loves."; break; - case "1": return "A compact instant messenger styled chat theme."; break; + case "1": return "A compact instant-messenger-styled chat theme."; break; case "2": return "Customizable aesthetic theme with character portraits."; break; case "3": return "Clean, minimalistic, corporate AI assistant theme."; break; default: return ""; break; @@ -17263,7 +17301,7 @@ Current version indicated by LITEVER below. case "1": document.getElementById("opmodedesc").innerText = "Let the AI co-write a story."; break; case "2": document.getElementById("opmodedesc").innerText = "Participate in turn-based interactive adventures."; break; case "3": document.getElementById("opmodedesc").innerText = "Roleplay with a virtual chatbot AI."; break; - case "4": document.getElementById("opmodedesc").innerText = "Give the AI instructions, questions, or do tasks."; break; + case "4": document.getElementById("opmodedesc").innerText = "Give the AI instructions, questions, or tasks."; break; default: document.getElementById("opmodedesc").innerText = ""; break; } @@ -29537,7 +29575,7 @@ Current version indicated by LITEVER below.

    Usage Mode

    -
    Usage mode ?Story Mode is best for novel style writing. Adventure Mode is best for Interactive Fiction RPGs. Chat Mode is best for chat conversations with the AI. Instruct mode is for giving the AI ChatGPT styled tasks.
    +
    Usage mode ?Story Mode is best for novel-style writing. Adventure Mode is best for Interactive Fiction RPGs. Chat Mode is best for chat conversations with the AI. Instruct mode is for giving the AI ChatGPT-styled tasks.
    @@ -29682,12 +29720,12 @@ Current version indicated by LITEVER below.
    -
    Allow continue user turns ?Allow continuing user turns ?In instruct mode, allows the AI to continue generating the user's turn when pressing Generate More.
    -
    Allow continue AI replies ?Allow continuing AI replies ?Allow the AI to continue incomplete past responses, which can be extended by pressing submit again. Not recommended for newbies.
    @@ -29807,23 +29845,23 @@ Current version indicated by LITEVER below.
    -
    Enable markdown ?Allows the UI to use markdown formatting such as quotes and code blocks.
    +
    Enable Markdown ?Allows the UI to use Markdown formatting, such as quotes and code blocks.
    -
    Render markdown while streaming ?Attempt to render markdown when streaming. May result in wonky output or lag on older devices.
    +
    Render Markdown while streaming ?Attempt to render Markdown when streaming. May result in wonky output or lag on older devices.
    Enable LaTeX ?Allows the UI to render LaTeX within markdown formatting (Needs Markdown).
    + class="helptext">Allows the UI to render LaTeX within Markdown formatting (Needs Markdown).
    Show Nametags ?Controls if user and AI nametags are shown or hidden. Recommended.
    + class="helptext">Controls whether user and AI nametags are shown or hidden. Recommended.
    @@ -29851,7 +29889,7 @@ Current version indicated by LITEVER below.
    Max Displayed Text Characters ?If set above 0, will limit the number of text characters rendered to display (any earlier text will still be submitted but stay hidden).
    + class="helptext">If set above 0, will limit the number of text characters rendered to display. (Any earlier text will still be submitted but stay hidden.)