From 51266861f84029af6e933e3ec3a5aa4d06ce8fb2 Mon Sep 17 00:00:00 2001 From: garrettmills Date: Sat, 9 Apr 2022 10:34:33 -0500 Subject: [PATCH] Finish Katex and Statement components to render statements --- src/components/Katex.vue | 29 +++++++++++++++++++++++++++ src/components/Scratch.vue | 9 +++++++++ src/components/Statement.vue | 39 ++++++++++++++++++++++++++++++++++++ src/support/page.ts | 13 +++++++++--- src/support/parse.ts | 5 +++++ src/types.ts | 2 +- 6 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 src/components/Katex.vue create mode 100644 src/components/Statement.vue diff --git a/src/components/Katex.vue b/src/components/Katex.vue new file mode 100644 index 0000000..420362c --- /dev/null +++ b/src/components/Katex.vue @@ -0,0 +1,29 @@ + + + + + diff --git a/src/components/Scratch.vue b/src/components/Scratch.vue index 9db4e0f..b9e8eb7 100644 --- a/src/components/Scratch.vue +++ b/src/components/Scratch.vue @@ -1,7 +1,16 @@ diff --git a/src/components/Statement.vue b/src/components/Statement.vue new file mode 100644 index 0000000..0a3f606 --- /dev/null +++ b/src/components/Statement.vue @@ -0,0 +1,39 @@ + + + + + diff --git a/src/support/page.ts b/src/support/page.ts index 2cebbbd..3e77930 100644 --- a/src/support/page.ts +++ b/src/support/page.ts @@ -2,7 +2,7 @@ import {MathStatement} from './parse' import * as math from 'mathjs' import {DepGraph} from 'dependency-graph' import { v4 as uuidv4 } from 'uuid' -import {EvaluationResult, StatementID, VariableName} from '../types' +import {EvaluationResult, Maybe, StatementID, VariableName} from '../types' /** * Wrapper for a page containing multiple interrelated mathematical statements. @@ -16,6 +16,11 @@ export class MathPage { public readonly id: string, ) {} + /** Get a statement by ID if it exists. */ + getStatement(id: StatementID): Maybe { + return this.statements[id] + } + /** Add a statement to this page. */ addStatement(statement: MathStatement): this { this.statements[statement.id] = statement @@ -23,8 +28,10 @@ export class MathPage { } /** Parse the math expression and add it to the page as a statement. */ - addRaw(statement: string): this { - return this.addStatement(new MathStatement(uuidv4() as StatementID, statement)) + addRaw(statement: string): StatementID { + const stmt = new MathStatement(uuidv4() as StatementID, statement) + this.addStatement(stmt) + return stmt.id } /** Get all symbols referenced by statements on this page. */ diff --git a/src/support/parse.ts b/src/support/parse.ts index 2c44ce9..f92b28c 100644 --- a/src/support/parse.ts +++ b/src/support/parse.ts @@ -1,6 +1,7 @@ import * as math from 'mathjs' import katex from 'katex' import {HTMLString, LaTeXString, StatementID} from '../types' +import {v4 as uuidv4} from 'uuid' /** Base class for walks over MathNode trees. */ export abstract class MathNodeWalk { @@ -258,6 +259,10 @@ export class LValSymbolWalk extends SymbolWalk { /** A single mathematical statement. */ export class MathStatement { + static temp(raw: string): MathStatement { + return new MathStatement(uuidv4() as StatementID, raw) + } + constructor( /** Unique ID of this statement. */ public readonly id: StatementID, diff --git a/src/types.ts b/src/types.ts index 02db4fd..c0b76d6 100644 --- a/src/types.ts +++ b/src/types.ts @@ -85,7 +85,7 @@ export type LaTeXString = TypeTag<'@app.LaTeXString'> & string export type HTMLString = TypeTag<'@app.HTMLString'> & string export type StatementID = TypeTag<'@app.StatementID'> & string export type VariableName = TypeTag<'@app.VariableName'> & string -export type RoutePath = TypeTag<'@app.RoutePath'> & string +export type EvaluatedValue = TypeTag<'@app.EvaluatedValue'> & string export interface EvaluationResult { variables: Record