Skip to content

Commit

Permalink
feat: implement latex rendering of matrix results
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreminger committed Jul 8, 2023
1 parent d584f61 commit 93132b2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/MathCell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>()
// 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}`;
}
}
}
Expand Down

0 comments on commit 93132b2

Please sign in to comment.