Skip to content

LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。

TypeScript

feat: comprehensive LaTeX → Unicode conversion (100+ symbols)

nash_su2a248535b1c6
diff --git a/src/components/chat/chat-message.tsx b/src/components/chat/chat-message.tsx
index 441acf85..4a092697 100644
--- a/src/components/chat/chat-message.tsx
+++ b/src/components/chat/chat-message.tsx
@@ -11,6 +11,59 @@ import { lastQueryPages } from "@/components/chat/chat-panel"
import type { DisplayMessage } from "@/stores/chat-store"
import type { FileNode } from "@/types/wiki"
+// Comprehensive LaTeX command → Unicode mapping
+const LATEX_TO_UNICODE: Record<string, string> = {
+ // Arrows
+ rightarrow: "→", Rightarrow: "⇒", longrightarrow: "⟶",
+ leftarrow: "←", Leftarrow: "⇐", longleftarrow: "⟵",
+ leftrightarrow: "↔", Leftrightarrow: "⇔",
+ uparrow: "↑", Uparrow: "⇑", downarrow: "↓", Downarrow: "⇓",
+ mapsto: "↦", hookrightarrow: "↪", hookleftarrow: "↩",
+ nearrow: "↗", nwarrow: "↖", searrow: "↘", swarrow: "↙",
+ // Math operators
+ times: "×", div: "÷", pm: "±", mp: "∓", cdot: "·", ast: "∗",
+ star: "⋆", circ: "∘", bullet: "•", oplus: "⊕", otimes: "⊗",
+ // Relations
+ leq: "≤", le: "≤", geq: "≥", ge: "≥", neq: "≠", ne: "≠",
+ approx: "≈", sim: "∼", simeq: "≃", equiv: "≡", cong: "≅",
+ propto: "∝", ll: "≪", gg: "≫", prec: "≺", succ: "≻",
+ subset: "⊂", supset: "⊃", subseteq: "⊆", supseteq: "⊇",
+ in: "∈", notin: "∉", ni: "∋", cap: "∩", cup: "∪",
+ vee: "∨", wedge: "∧", neg: "¬", lnot: "¬",
+ // Greek lowercase
+ alpha: "α", beta: "β", gamma: "γ", delta: "δ", epsilon: "ε",
+ varepsilon: "ε", zeta: "ζ", eta: "η", theta: "θ", vartheta: "ϑ",
+ iota: "ι", kappa: "κ", lambda: "λ", mu: "μ", nu: "ν",
+ xi: "ξ", pi: "π", varpi: "ϖ", rho: "ρ", varrho: "ϱ",
+ sigma: "σ", varsigma: "ς", tau: "τ", upsilon: "υ", phi: "φ",
+ varphi: "ϕ", chi: "χ", psi: "ψ", omega: "ω",
+ // Greek uppercase
+ Gamma: "Γ", Delta: "Δ", Theta: "Θ", Lambda: "Λ", Xi: "Ξ",
+ Pi: "Π", Sigma: "Σ", Upsilon: "Υ", Phi: "Φ", Psi: "Ψ", Omega: "Ω",
+ // Misc symbols
+ infty: "∞", partial: "∂", nabla: "∇", forall: "∀", exists: "∃",
+ emptyset: "∅", varnothing: "∅", wp: "℘", Re: "ℜ", Im: "ℑ",
+ aleph: "ℵ", hbar: "ℏ", ell: "ℓ", sharp: "♯", flat: "♭",
+ natural: "♮", clubsuit: "♣", diamondsuit: "♢", heartsuit: "♡", spadesuit: "♠",
+ // Big operators
+ sum: "∑", prod: "∏", coprod: "∐", int: "∫", oint: "∮",
+ bigcup: "⋃", bigcap: "⋂", bigoplus: "⨁", bigotimes: "⨂",
+ // Dots
+ ldots: "…", cdots: "⋯", vdots: "⋮", ddots: "⋱",
+ // Formatting
+ quad: " ", qquad: " ", text: "", mathrm: "", mathbf: "", mathit: "",
+ textbf: "", textit: "", textrm: "",
+ // Delimiters
+ langle: "⟨", rangle: "⟩", lfloor: "⌊", rfloor: "⌋",
+ lceil: "⌈", rceil: "⌉", lvert: "|", rvert: "|",
+ // Accents (just show the base)
+ hat: "^", tilde: "~", bar: "‾", vec: "→", dot: "·", ddot: "¨",
+ // Common functions (keep as text)
+ log: "log", ln: "ln", exp: "exp", sin: "sin", cos: "cos", tan: "tan",
+ min: "min", max: "max", sup: "sup", inf: "inf", lim: "lim",
+ sqrt: "√", frac: "/",
+}
+
// Module-level cache of source file names
let cachedSourceFiles: string[] = []
@@ -546,25 +599,18 @@ function ThinkingBlock({ content }: { content: string }) {
function processContent(text: string): string {
let result = text
- // Clean up LaTeX notation → readable text
- result = result
- .replace(/\$\\rightarrow\$/g, "→")
- .replace(/\$\\leftarrow\$/g, "←")
- .replace(/\$\\leftrightarrow\$/g, "↔")
- .replace(/\$\\times\$/g, "×")
- .replace(/\$\\div\$/g, "÷")
- .replace(/\$\\pm\$/g, "±")
- .replace(/\$\\geq?\$/g, "≥")
- .replace(/\$\\leq?\$/g, "≤")
- .replace(/\$\\neq\$/g, "≠")
- .replace(/\$\\approx\$/g, "≈")
- .replace(/\$\\infty\$/g, "∞")
- .replace(/\$\\alpha\$/g, "α")
- .replace(/\$\\beta\$/g, "β")
- .replace(/\$\\gamma\$/g, "γ")
- .replace(/\$\\delta\$/g, "δ")
- // Generic: strip remaining $...$ inline math (display the inner text without $ delimiters)
- .replace(/\$([^$]+)\$/g, "$1")
+ // Clean up LaTeX notation → readable Unicode
+ // First handle $\command$ patterns, then strip remaining $...$
+ result = result.replace(/\$\\([a-zA-Z]+)\$/g, (_match, cmd: string) => {
+ return LATEX_TO_UNICODE[cmd] ?? `\\${cmd}`
+ })
+ // Handle $$...$$ display math (keep inner content, strip delimiters)
+ result = result.replace(/\$\$([^$]+)\$\$/g, "\n$1\n")
+ // Handle remaining $...$ inline math with potential LaTeX inside
+ result = result.replace(/\$([^$]+)\$/g, (_match, inner: string) => {
+ // Replace LaTeX commands inside the math expression
+ return inner.replace(/\\([a-zA-Z]+)/g, (_m, cmd: string) => LATEX_TO_UNICODE[cmd] ?? `\\${cmd}`)
+ })
// Fix malformed wikilinks like [[name] (missing closing bracket)
result = result.replace(/\[\[([^\]]+)\](?!\])/g, "[[$1]]")