From c352987645294838b7ea1eaa3cbcaf0994bf9dd0 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Mon, 22 Jan 2024 10:18:35 +0100 Subject: Sync from main --- server-katex/math.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 server-katex/math.ts (limited to 'server-katex/math.ts') diff --git a/server-katex/math.ts b/server-katex/math.ts new file mode 100644 index 0000000..7a5b891 --- /dev/null +++ b/server-katex/math.ts @@ -0,0 +1,18 @@ +import { readLines } from "https://deno.land/std@0.134.0/io/mod.ts"; +import katex from "https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.mjs"; + +const macros = []; +for await (const line of readLines(Deno.stdin)) { + try { + const output = katex.renderToString(line.slice(1), { + displayMode: line[0] == 'd', + throwOnError: false, + macros: macros, + strict: false, + fleqn: false + }).replace(/(\r\n|\n|\r)/gm, ""); + console.log(output); + } catch (error) { + throw new Error(`Input: ${line}\n\nError: ${error}`); + } +} -- cgit v1.2.3