Skip to content

Main content

LaTeX as Document Source Code

Browse the implementation files for LaTeX as Document.
tool.ts typescript
import { createToolDocument, type ToolDocument } from '../tool';

export const latexAsDocument = (
	input: unknown
): ToolDocument | null =>
	typeof input === 'string' && input.trim() !== ''
		? createToolDocument([
				{ display: true, kind: 'equation', latex: input.trim() }
			])
		: null;

export const formatLatexAsDocument = (
	input: unknown
): string => {
	const document = latexAsDocument(input);
	return document === null
		? ''
		: JSON.stringify(document, null, 2);
};

export const Tool: TypeTool = {
	name: 'LaTeX as Document',
	slug: 'document/from-latex',
	intro:
		'Wrap LaTeX equation markup in a structured Tool.io document.',
	tool: formatLatexAsDocument,
	i: [
		{
			example: 'E = mc^2',
			label: 'LaTeX',
			placeholder: 'Enter LaTeX',
			render: 'textarea',
			type: 'text'
		}
	],
	o: [
		{
			example:
				'{\n  "blocks": [{ "kind": "equation", ... }],\n  "kind": "document",\n  "version": 1\n}',
			label: 'Document',
			placeholder: 'Document will appear here...',
			render: 'textarea',
			type: 'text'
		}
	]
};

export default Tool;

Description

Browse the implementation files for LaTeX as Document.

References

  1. Tool.io on GitHub
  2. Tool.io TypeScript tools library

Similar or alternative tools