Skip to content

Commit 506a40b

Browse files
committed
proper working
1 parent 85ed48e commit 506a40b

File tree

6 files changed

+62
-17
lines changed

6 files changed

+62
-17
lines changed

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
# mdTeX
22

3-
A markdown/LaTeX editor that compiles via pandoc.
3+
<p align="center">
4+
<img src="https://raw.githubusercontent.com/slashinfty/mdTeX/refs/heads/main/src-tauri/icons/128x128.png">
5+
</p>
46

5-
Requires both pandoc and texlive to be installed.
7+
A markdown/LaTeX editor that compiles PDFs via Pandoc.
8+
9+
Requires both [pandoc](https://pandoc.org/) and [texlive](https://www.tug.org/texlive/) to be installed.
10+
11+
Built with [Tauri](https://v2.tauri.app/) and [Vite](https://vite.dev/). Code editor powered by [Codemirror](https://codemirror.net/).
12+
13+
## Features
14+
15+
![screenshot of mdTeX](screenshot.png)
16+
17+
- Markdown language highlighting for body, LaTeX for preamble
18+
- [Pandoc extensions](https://pandoc.org/MANUAL.html#pandocs-markdown) for converting from Markdown
19+
- Save default preamble, body, and extensions
20+
- Convert to PDF normally or via beamer
21+
- Save PDF to the same folder as the Markdown file and embeds the PDF
22+
23+
## Behind the Scenes
24+
25+
The app creates a temporary .yaml file with `header-includes:` to add LaTeX preamble, then runs the following pandoc command:
26+
27+
```js
28+
pandoc --from markdown${extensions} --to ${format} --output ${pdf} ${yaml} ${markdown}
29+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mdtex",
3-
"version": "0.1.4",
3+
"version": "0.2.0",
44
"type": "module",
55
"scripts": {
66
"dev": "vite",

screenshot.png

258 KB
Loading

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://schema.tauri.app/config/2",
33
"productName": "mdTeX",
4-
"version": "0.1.4",
4+
"version": "0.2.0",
55
"identifier": "com.matt.mdTeX",
66
"build": {
77
"beforeDevCommand": "npm run dev",

src/index.css

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,20 @@ textarea, input {
4848
height: 100%;
4949
}
5050

51+
.side {
52+
overflow-x: scroll;
53+
}
54+
5155
.right {
5256
justify-content: center;
5357
}
5458

59+
.input {
60+
anchor-name: --input;
61+
}
62+
5563
.buttons {
64+
anchor-name: --buttons;
5665
justify-content: space-between;
5766
flex-basis: content;
5867
}
@@ -75,6 +84,7 @@ textarea, input {
7584

7685
.cm-editor {
7786
height: 100%;
87+
width: 100%;
7888
border: var(--pico-border-width) solid var(--pico-form-element-border-color);
7989
border-radius: var(--pico-border-radius);
8090
}
@@ -88,14 +98,18 @@ textarea, input {
8898
}
8999

90100
.cm-scroller {
91-
overflow: auto;
101+
overflow: scroll;
92102
}
93103

94104
/* IDs */
95105
#textarea, #extensions {
96106
flex: 1;
97107
}
98108

109+
#textarea {
110+
max-height: 79vh;
111+
}
112+
99113
#export {
100114
flex-basis: content;
101115
}

src/index.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function newButton() {
6464
}
6565
});
6666
document.querySelector('#extensions').value = defaults.extensions;
67+
document.querySelector('#pdf').innerHTML = '';
6768
}
6869

6970
async function saveButton() {
@@ -115,6 +116,7 @@ async function loadButton() {
115116
}
116117
});
117118
document.querySelector('#extensions').value = text.extensions;
119+
document.querySelector('#pdf').innerHTML = '';
118120
}
119121

120122
function settingsButton() {
@@ -172,15 +174,6 @@ function bodyButton() {
172174
});
173175
}
174176

175-
function textarea() {
176-
const mainText = editor.state.doc.text.reduce((str, line) => `${str}\n${line}`, '').replace(/\n/, '');
177-
if (document.querySelector('#body-button').classList.contains('secondary')) {
178-
text.preamble = mainText;
179-
} else {
180-
text.body = mainText;
181-
}
182-
}
183-
184177
async function extensionsLink() {
185178
await openUrl('https://pandoc.org/MANUAL.html#extensions');
186179
}
@@ -218,12 +211,12 @@ async function compile() {
218211
const pdfFile = await resolve(path, `${fileName}.pdf`);
219212
const pandoc = Command.create('pandoc', ['--from', `markdown${text.extensions}`, '--to', document.querySelector('#export').value, '--output', pdfFile, yamlFile, markdownPath]);
220213
const result = await pandoc.execute();
214+
document.querySelector('#pdf').innerHTML = '';
221215
if (result.stderr !== '') {
222216
console.error(result.stderr);
223217
document.querySelector('#error-text').innerHTML = result.stderr;
224218
document.querySelector('#error').setAttribute('open', '');
225219
} else {
226-
document.querySelector('#pdf').innerHTML = '';
227220
const pdfArr = await readFile(pdfFile);
228221
const el = document.createElement('embed');
229222
el.src = URL.createObjectURL(new Blob([pdfArr], { type: 'application/pdf' }));
@@ -260,7 +253,22 @@ window.addEventListener('DOMContentLoaded', async () => {
260253
...closeBracketsKeymap,
261254
...defaultKeymap,
262255
...historyKeymap
263-
])
256+
]),
257+
EditorView.updateListener.of(v => {
258+
let newText;
259+
if (v.state.doc.hasOwnProperty('text') && (!v.startState.doc.hasOwnProperty('text') || v.state.doc.text.toString() !== v.startState.doc.text.toString())) {
260+
newText = v.state.doc.text.join(`\n`);
261+
}
262+
if (v.state.doc.hasOwnProperty('children') && (!v.startState.doc.hasOwnProperty('children') || v.state.doc.children.reduce((str, child) => str + child.text.toString(), '') !== v.startState.doc.children.reduce((str, child) => str + child.text.toString(), ''))) {
263+
newText = v.state.doc.children.map(child => child.text).flat().join(`\n`);
264+
}
265+
if (newText === undefined) return;
266+
if (document.querySelector('#body-button').classList.contains('secondary')) {
267+
text.preamble = newText;
268+
} else {
269+
text.body = newText;
270+
}
271+
})
264272
]
265273
});
266274
editor = new EditorView({
@@ -280,7 +288,6 @@ window.addEventListener('DOMContentLoaded', async () => {
280288
document.querySelector('#source-code-button').addEventListener('click', sourceCodeButton);
281289
document.querySelector('#preamble-button').addEventListener('click', preambleButton);
282290
document.querySelector('#body-button').addEventListener('click', bodyButton);
283-
document.querySelector('.cm-content').addEventListener('input', textarea);
284291
document.querySelector('#extensions-link').addEventListener('click', extensionsLink);
285292
document.querySelector('#extensions').addEventListener('input', extensions);
286293
document.querySelector('#compile-button').addEventListener('click', compile);

0 commit comments

Comments
 (0)