import { renderLatex } from "@ofb/katex"; import { createMemo, createSignal } from "solid-js"; function formatNum(n: number) { if (Number.isInteger(n)) return String(n); return (Math.round(n * 100) / 100).toString(); } function RatioDemo() { const [partA, setPartA] = createSignal(2); const [partB, setPartB] = createSignal(5); const [total, setTotal] = createSignal(28); const sumParts = createMemo(() => partA() + partB()); const shareA = createMemo(() => (partA() / sumParts()) * total()); const shareB = createMemo(() => (partB() / sumParts()) * total()); const formulaHtml = createMemo(() => renderLatex( `${partA()}:${partB()} \\Rightarrow ${formatNum(shareA())} : ${formatNum(shareB())} \\text{ from total } ${formatNum(total())}` ) ); return (

Split {formatNum(total())} in the ratio{" "} {partA()}:{partB()} . Each of the {sumParts()} equal parts has size{" "} {formatNum(total() / sumParts())}.

); } export default RatioDemo;