Skip to content

Commit

Permalink
Merge pull request #228 from mgreminger/export-fixes
Browse files Browse the repository at this point in the history
fix: don't include blank expressions in table markdown
  • Loading branch information
mgreminger authored Jan 14, 2024
2 parents 1acc32a + 0c5b1b4 commit 4ef6fea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@
statements.push(mathField.statement);
}
} else if (cell instanceof TableCell) {
const newStatements = cell.parseTableStatements(cellNum);
const newStatements = cell.parseTableStatements();
for (const statement of newStatements) {
endStatements.push(statement);
}
Expand Down
35 changes: 23 additions & 12 deletions src/TableCell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import IconButton from "./IconButton.svelte";
import { deltaToMarkdown } from "quill-delta-to-markdown";
import { column } from "mathjs";
export let index: number;
export let tableCell: TableCell;
Expand All @@ -43,23 +44,33 @@
result += deltaToMarkdown((tableCell.rowJsons[row] as any)?.ops ?? "") + "\n";
}
result += `$$ \\text{${tableCell.rowLabels[row].label}} \\quad `;
const columnExpressions = [];
if (tableCell.parameterFields.length > 1) {
result += ` \\begin{cases} `;
for (const [col, parameter] of tableCell.parameterFields.entries()) {
if (tableCell.rhsFields[row][col].latex.replaceAll(/\\:?/g,'').trim() !== "") {
columnExpressions.push(`${parameter.latex} & = \\quad ${tableCell.rhsFields[row][col].latex} ${tableCell.parameterUnitFields[col].latex}`);
}
}
if (columnExpressions.length > 0) {
result += `$$ \\text{${tableCell.rowLabels[row].label}} \\quad `;
if (columnExpressions.length > 1) {
result += ` \\begin{cases} `;
for (const [col, parameter] of tableCell.parameterFields.entries()) {
result += `${parameter.latex} & = \\quad ${tableCell.rhsFields[row][col].latex} ${tableCell.parameterUnitFields[col].latex}`;
if (col < tableCell.parameterFields.length - 1) {
result += " \\\\ ";
for (const [col, expression] of columnExpressions.entries()) {
result += expression;
if (col < columnExpressions.length - 1) {
result += " \\\\ ";
}
}
result += " \\end{cases}";
} else {
result += columnExpressions[0].replace('& = \\quad', '=');
}
result += " \\end{cases}";
} else {
result += `${tableCell.parameterFields[0].latex} = ${tableCell.rhsFields[row][0].latex} ${tableCell.parameterUnitFields[0].latex}`;
result += " $$ \n\n";
}
result += " $$ \n\n";
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cells/TableCell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default class TableCell extends BaseCell {
}


parseTableStatements(cellNum: number): Statement[] {
parseTableStatements(): Statement[] {
const rowIndex = this.selectedRow;
const statements = [];

Expand Down

0 comments on commit 4ef6fea

Please sign in to comment.