Skip to content

Commit

Permalink
feat(new tool): Math Formula format converter
Browse files Browse the repository at this point in the history
Fix part of #1009
  • Loading branch information
sharevb committed May 18, 2024
1 parent e876d03 commit 2ed7f01
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/tools/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { tool as base64FileConverter } from './base64-file-converter';
import { tool as base64StringConverter } from './base64-string-converter';
import { tool as basicAuthGenerator } from './basic-auth-generator';
import { tool as mathFormatsConverter } from './math-formats-converter';

import { tool as asciiTextDrawer } from './ascii-text-drawer';

Expand Down Expand Up @@ -156,7 +157,12 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Math',
components: [mathEvaluator, etaCalculator, percentageCalculator],
components: [
mathEvaluator,
etaCalculator,
percentageCalculator,
mathFormatsConverter,
],
},
{
name: 'Measurement',
Expand Down
12 changes: 12 additions & 0 deletions src/tools/math-formats-converter/index.ts
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 src/tools/math-formats-converter/math-formats-converter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<script setup lang="ts">
import Plurimath from '@plurimath/plurimath';

Check failure on line 2 in src/tools/math-formats-converter/math-formats-converter.vue

View workflow job for this annotation

GitHub Actions / ci

Cannot find module '@plurimath/plurimath' or its corresponding type declarations.
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>

0 comments on commit 2ed7f01

Please sign in to comment.