Skip to content

Commit fd8b975

Browse files
committed
Revert "fix: remove math format converter as not possible right now"
This reverts commit 0e66063.
1 parent f56a39a commit fd8b975

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { tool as phpArrayToJson } from './php-array-to-json';
4545
import { tool as jsonSizeAnalyzer } from './json-size-analyzer';
4646
import { tool as jsonToCsharp } from './json-to-csharp';
4747
import { tool as luhnValidator } from './luhn-validator';
48+
import { tool as mathFormatsConverter } from './math-formats-converter';
4849
import { tool as mathOcr } from './math-ocr';
4950
import { tool as markdownTocGenerator } from './markdown-toc-generator';
5051
import { tool as passphraseGenerator } from './passphrase-generator';
@@ -493,6 +494,7 @@ export const toolsByCategory: ToolCategory[] = [
493494
mathEvaluator,
494495
etaCalculator,
495496
percentageCalculator,
497+
mathFormatsConverter,
496498
mathOcr,
497499
dataTransferRateConverter,
498500
dataStorageUnitConverter,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { EqualNot } from '@vicons/tabler';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'Math Formats Converter',
6+
path: '/math-formats-converter',
7+
description: 'Convert mathematical expression between formats',
8+
keywords: ['math', 'formats', 'converter', 'latex', 'mathml', 'asciimath', 'omml', 'html'],
9+
component: () => import('./math-formats-converter.vue'),
10+
icon: EqualNot,
11+
createdAt: new Date('2024-05-11'),
12+
});
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<script setup lang="ts">
2+
import Plurimath from '@plurimath/plurimath';
3+
import { useQueryParamOrStorage } from '@/composable/queryParams';
4+
5+
const formats = [
6+
{ value: 'asciimath', label: 'AsciiMath' },
7+
{ value: 'latex', label: 'Latex' },
8+
{ value: 'mathml', label: 'MathML' },
9+
{ value: 'html', label: 'Html' },
10+
{ value: 'omml', label: 'OOML' },
11+
];
12+
13+
const source = ref('');
14+
const sourceFormat = useQueryParamOrStorage({ name: 'src', storageName: 'math-fmts-conv:src', defaultValue: 'latex' });
15+
const targetFormat = useQueryParamOrStorage({ name: 'target', storageName: 'math-fmts-conv:target', defaultValue: 'mathml' });
16+
const target = computedAsync(async () => {
17+
const sourceValue = source.value;
18+
const sourceFormatValue = sourceFormat.value;
19+
const targetFormatValue = targetFormat.value;
20+
if (sourceValue === '') {
21+
return '';
22+
}
23+
if (sourceFormatValue === targetFormatValue) {
24+
return sourceValue;
25+
}
26+
return new Promise<string>((resolve, _reject) => {
27+
try {
28+
const formula = new Plurimath(sourceValue, sourceFormatValue);
29+
let result;
30+
switch (targetFormatValue) {
31+
case 'asciimath':
32+
result = formula.toAsciimath();
33+
break;
34+
case 'latex':
35+
result = formula.toLatex();
36+
break;
37+
case 'mathml':
38+
result = formula.toMathml();
39+
break;
40+
case 'html':
41+
result = formula.toHtml();
42+
break;
43+
case 'omml':
44+
result = formula.toOmml();
45+
break;
46+
default:
47+
result = '# unknown format';
48+
break;
49+
}
50+
resolve(result);
51+
}
52+
catch (e: any) {
53+
resolve(`# error converting formula: ${e.toString()}`);
54+
}
55+
});
56+
});
57+
</script>
58+
59+
<template>
60+
<div>
61+
<c-input-text
62+
v-model:value="source"
63+
multiline
64+
placeholder="Put your math expression here..."
65+
rows="5"
66+
label="Mathematical expression to convert"
67+
raw-text
68+
mb-5
69+
/>
70+
<c-select
71+
v-model:value="sourceFormat"
72+
:options="formats"
73+
placeholder="Source format"
74+
/>
75+
76+
<n-divider />
77+
78+
<c-select
79+
v-model:value="targetFormat"
80+
:options="formats"
81+
placeholder="Source format"
82+
/>
83+
<textarea-copyable v-if="target !== ''" :value="target" :language="targetFormat" />
84+
</div>
85+
</template>

0 commit comments

Comments
 (0)