-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(new tool): Math Formula format converter
Fix part of #1009
- Loading branch information
Showing
3 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { EqualNot } from '@vicons/tabler'; | ||
import { defineTool } from '../tool'; | ||
|
||
export const tool = defineTool({ | ||
name: 'Math Gormats Converter', | ||
path: '/math-formats-converter', | ||
description: 'Convert mathematical expression between formats', | ||
keywords: ['math', 'formats', 'converter', 'latex', 'mathml', 'asciimath'], | ||
component: () => import('./math-formats-converter.vue'), | ||
icon: EqualNot, | ||
createdAt: new Date('2024-05-11'), | ||
}); |
62 changes: 62 additions & 0 deletions
62
src/tools/math-formats-converter/math-formats-converter.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<script setup lang="ts"> | ||
import Plurimath from '@plurimath/plurimath'; | ||
const formats = [ | ||
{ value: 'asciimath', label: 'AsciiMath' }, | ||
{ value: 'latex', label: 'Latex' }, | ||
{ value: 'mathml', label: 'MathML' }, | ||
{ value: 'html', label: 'Html' }, | ||
{ value: 'omml', label: 'OOML' }, | ||
]; | ||
const source = ref(''); | ||
const sourceFormat = ref(''); | ||
const targetFormat = ref(''); | ||
const target = computed(() => { | ||
if (sourceFormat.value === targetFormat.value) { | ||
return source.value; | ||
} | ||
const formula = new Plurimath(source.value, sourceFormat.value); | ||
switch (targetFormat.value) { | ||
case 'asciimath': | ||
return formula.toAsciimath(); | ||
case 'latex': | ||
return formula.toLatex(); | ||
case 'mathml': | ||
return formula.toMathml(); | ||
case 'html': | ||
return formula.toHtml(); | ||
case 'omml': | ||
return formula.toOmml(); | ||
} | ||
return '# unknown format'; | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<c-input-text | ||
v-model:value="source" | ||
multiline | ||
placeholder="Put your math expression here..." | ||
rows="5" | ||
label="Mathematical expression to convert" | ||
raw-text | ||
mb-5 | ||
/> | ||
<c-select | ||
v-model:value="sourceFormat" | ||
:options="formats" | ||
placeholder="Source format" | ||
/> | ||
|
||
<n-divider /> | ||
|
||
<c-select | ||
v-model:value="targetFormat" | ||
:options="formats" | ||
placeholder="Source format" | ||
/> | ||
<textarea-copyable :value="target" :language="targetFormat" /> | ||
</div> | ||
</template> |