@mdgate/latex 0.6.8 → 0.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +146 -8
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,26 +1,164 @@
|
|
|
1
1
|
# @mdgate/latex
|
|
2
2
|
|
|
3
|
-
Convert LaTeX source to Markdown
|
|
4
|
-
browsers. No native addons.
|
|
3
|
+
**Convert LaTeX source to Markdown in TypeScript.**
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
[`@mdgate/latex`](https://github.com/mdgate/converters/tree/main/packages/latex) reads `.tex`, `.latex`, and `.ltx` files directly in JavaScript and converts them into GitHub-Flavored Markdown, without Python, native addons, WASM, or a TeX engine.
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
Works in **Node.js, Cloudflare Workers, Edge runtimes, and browsers**.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @mdgate/latex
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { toMarkdown } from '@mdgate/latex';
|
|
15
|
+
|
|
16
|
+
const markdown = await toMarkdown(bytes);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`bytes` is a `Uint8Array`, so the source can come from a file upload, a git checkout, an HTTP request, a browser file picker, or anywhere else your application gets bytes.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Why [`@mdgate/latex`](https://github.com/mdgate/converters/tree/main/packages/latex)
|
|
24
|
+
|
|
25
|
+
LaTeX is source, not a rendered PDF. An agent that needs the paper's structure can read the `.tex` without running TeX.
|
|
26
|
+
|
|
27
|
+
[`@mdgate/latex`](https://github.com/mdgate/converters/tree/main/packages/latex) is a LaTeX reader written for the same runtime as your application:
|
|
28
|
+
|
|
29
|
+
* **Pure TypeScript**
|
|
30
|
+
* **LaTeX → Markdown locally**
|
|
31
|
+
* **No Python runtime**
|
|
32
|
+
* **No native addons**
|
|
33
|
+
* **No WASM runtime**
|
|
34
|
+
* **Zero third-party runtime dependencies**
|
|
35
|
+
* **Works with raw `Uint8Array` input**
|
|
36
|
+
|
|
37
|
+
This is not a full TeX engine. It does not typeset, resolve `\input` trees from disk, or run packages.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## What it extracts
|
|
42
|
+
|
|
43
|
+
[`@mdgate/latex`](https://github.com/mdgate/converters/tree/main/packages/latex) walks common LaTeX commands and environments and rebuilds a shared document model.
|
|
44
|
+
|
|
45
|
+
The converter handles LaTeX-specific concerns including:
|
|
46
|
+
|
|
47
|
+
* `\section` and related headings
|
|
48
|
+
* paragraphs
|
|
49
|
+
* bold, italic, and inline code
|
|
50
|
+
* lists
|
|
51
|
+
* tables from common tabular markup
|
|
52
|
+
* footnotes when present
|
|
53
|
+
* dropping preamble commands such as `\documentclass` and `\usepackage`
|
|
54
|
+
|
|
55
|
+
The output is Markdown that can be searched, indexed, chunked, cached, or passed directly to an AI agent.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Node.js
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { readFile } from 'node:fs/promises';
|
|
63
|
+
import { toMarkdown } from '@mdgate/latex';
|
|
64
|
+
|
|
65
|
+
const bytes = new Uint8Array(await readFile('paper.tex'));
|
|
66
|
+
const markdown = await toMarkdown(bytes);
|
|
67
|
+
|
|
68
|
+
console.log(markdown);
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Browser
|
|
9
74
|
|
|
10
75
|
```ts
|
|
11
76
|
import { toMarkdown } from '@mdgate/latex';
|
|
12
77
|
|
|
78
|
+
const file = input.files![0];
|
|
79
|
+
const bytes = new Uint8Array(await file.arrayBuffer());
|
|
80
|
+
|
|
13
81
|
const markdown = await toMarkdown(bytes);
|
|
14
82
|
```
|
|
15
83
|
|
|
16
|
-
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Cloudflare Workers and Edge runtimes
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { toMarkdown } from '@mdgate/latex';
|
|
90
|
+
|
|
91
|
+
export default {
|
|
92
|
+
async fetch(request: Request) {
|
|
93
|
+
const bytes = new Uint8Array(await request.arrayBuffer());
|
|
94
|
+
const markdown = await toMarkdown(bytes);
|
|
95
|
+
|
|
96
|
+
return new Response(markdown, {
|
|
97
|
+
headers: {
|
|
98
|
+
'content-type': 'text/markdown; charset=utf-8',
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Format detection
|
|
108
|
+
|
|
109
|
+
Common LaTeX source can be recognized from its contents. A path hint still helps when the file is composed with other text converters:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
const markdown = await toMarkdown(bytes, {
|
|
113
|
+
path: 'paper.tex',
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The path is never used to read a file from disk.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Compose it with other file readers
|
|
122
|
+
|
|
123
|
+
[`@mdgate/latex`](https://github.com/mdgate/converters/tree/main/packages/latex) implements the converter interface from [`@mdgate/core`](https://github.com/mdgate/converters/tree/main/packages/core).
|
|
17
124
|
|
|
18
125
|
```ts
|
|
19
126
|
import { create } from '@mdgate/core';
|
|
20
127
|
import { latex } from '@mdgate/latex';
|
|
128
|
+
import { pdf } from '@mdgate/pdf';
|
|
129
|
+
|
|
130
|
+
const read = create([
|
|
131
|
+
latex(),
|
|
132
|
+
pdf(),
|
|
133
|
+
]);
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The application still uses one reading interface while each format remains independently installable.
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Need more than LaTeX?
|
|
141
|
+
|
|
142
|
+
If your application needs to read many different file types, use the complete converter set:
|
|
21
143
|
|
|
22
|
-
|
|
144
|
+
```bash
|
|
145
|
+
npm install @mdgate/converters
|
|
23
146
|
```
|
|
24
147
|
|
|
25
|
-
|
|
26
|
-
|
|
148
|
+
```ts
|
|
149
|
+
import { toMarkdown } from '@mdgate/converters';
|
|
150
|
+
|
|
151
|
+
const markdown = await toMarkdown(bytes, {
|
|
152
|
+
path: filename,
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
[`@mdgate/latex`](https://github.com/mdgate/converters/tree/main/packages/latex) is one of the single-format packages in the open-source [`mdgate/converters`](https://github.com/mdgate/converters) project.
|
|
157
|
+
|
|
158
|
+
For AI agents, the same converter architecture can be used to extend `read_file` from text files to real-world document formats.
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdgate/latex",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.10",
|
|
4
4
|
"description": "mdgate LaTeX converter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"homepage": "https://
|
|
7
|
+
"homepage": "https://convert.mdgate.dev",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/mdgate/converters.git",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"prepublishOnly": "bun run build"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@mdgate/core": "0.6.
|
|
32
|
-
"@mdgate/document": "0.6.
|
|
33
|
-
"@mdgate/utils": "0.6.
|
|
31
|
+
"@mdgate/core": "0.6.10",
|
|
32
|
+
"@mdgate/document": "0.6.10",
|
|
33
|
+
"@mdgate/utils": "0.6.10"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|