From 93132b243ed6e6e349fc0fd6dd7869f2668bdbec Mon Sep 17 00:00:00 2001 From: mgreminger Date: Sat, 8 Jul 2023 14:24:18 -0500 Subject: [PATCH] feat: implement latex rendering of matrix results --- src/MathCell.svelte | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/MathCell.svelte b/src/MathCell.svelte index d702fe48..f0fec47a 100644 --- a/src/MathCell.svelte +++ b/src/MathCell.svelte @@ -221,7 +221,22 @@ if (!isMatrixResult(result)) { ({error, resultLatex, resultUnits, resultUnitsLatex} = getLatexResult(statement, result, numberConfig) ); } else { + // assemble latex of matrix result + const latexRows: (string[])[] = []; + const errors = new Set() // matrix result, loop over rows + for (const row of result.results) { + const currentLatexRow: string[] = []; + for (const currentResult of row) { + const currentResultLatex = getLatexResult(statement, currentResult, numberConfig, true); + currentLatexRow.push(currentResultLatex.resultLatex + currentResultLatex.resultUnitsLatex); + errors.add(currentResultLatex.error); + } + latexRows.push(currentLatexRow); + } + error = Array.from(errors).join(", "); + resultUnits = ""; // not used with matrices since each item has its own units + resultLatex = String.raw`\begin{bmatrix} ${latexRows.map(row => row.join(' & ')).join(' \\\\ ')} \end{bmatrix}`; } } }