Math & Programming Test

Math

ℒ︀{𝑓(𝑡)}=∫∞0𝑒−𝑠𝑡𝑓(𝑡)d𝑡=∑∞𝑛=0(−1)𝑛𝑛!𝑑𝑛𝑓𝑑𝑠𝑛∇×(1𝜇0∇×𝑨)+𝜀0𝜕2𝑨𝜕𝑡2=𝑱+𝜀0∇(∇⋅𝑨)lim𝑁→∞∑𝑁𝑘=1(−1)𝑘+1𝑘𝑠∏𝑘𝑗=1Γ(𝑗+𝛼)Γ(𝑗+𝛽)=1Γ(𝑠)∫∞0𝑥𝑠−1𝑒−𝑥1−𝑒−𝑥log(Γ(𝑥+𝛼)Γ(𝑥+𝛽))d𝑥

Programming

export function render(
  content: string,
  block: boolean,
  mode: "svg" | "html",
): string {
  const math = block ? `$ ${content} $` : `$${content}$`;
  const doc =
    `#set page(width: auto, height: auto, margin: 0pt)\n` +
    `#set text(size: 18pt)\n${math}`;

  compiler ??= NodeCompiler.create();

  const output =
    mode == "svg"
      ? compiler.svg({ mainFileContent: doc })
      : (compiler.tryHtml({ mainFileContent: doc }).result?.body() ?? "");

  const tag = mode == "svg" ? "svg" : "math";
  return (
    output.match(new RegExp(`<${tag}\\b[^>]*>[\\s\\S]*?<\\/${tag}>`))?.[0] ?? ""
  );
}