Skip to content

Commit 815f900

Browse files
committed
latex-math: fix cross-platform rendering (#253)
1 parent a46570b commit 815f900

3 files changed

Lines changed: 43 additions & 24 deletions

File tree

latex-math/CHANGELOG.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Changelog
2+
3+
## 0.0.8 - 2026-08-24
4+
5+
- Launch KLatexFormula directly with cross-platform argument handling and report rendering failures without repeatedly regenerating the preview ([#253](https://github.com/qownnotes/scripts/issues/253)).
6+
7+
## 0.0.7 - 2026-07-30
8+
9+
- Replace the deprecated `Qt.btoa` call with UTF-8-safe Base64 encoding.
10+
11+
## 0.0.6 - 2021-05-19
12+
13+
- Improve Windows support for KLatexFormula execution and local image URLs ([#129](https://github.com/qownnotes/scripts/pull/129)).
14+
15+
## 0.0.5 - 2020-08-02
16+
17+
- Store generated images in the script cache directory ([#103](https://github.com/qownnotes/scripts/pull/103)).
18+
19+
## 0.0.4 - 2020-05-31
20+
21+
- Update formula detection for the current HTML rendering hook ([#99](https://github.com/qownnotes/scripts/pull/99)).
22+
23+
## 0.0.3 - 2020-05-10
24+
25+
- Improve formula rendering and configuration ([#95](https://github.com/qownnotes/scripts/pull/95)).
26+
27+
## 0.0.2 - 2020-05-05
28+
29+
- Initial release ([#93](https://github.com/qownnotes/scripts/pull/93)).

latex-math/info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Latex Math",
33
"identifier": "latex-math",
44
"script": "latex-math.qml",
5-
"version": "0.0.7",
5+
"version": "0.0.8",
66
"platforms": ["linux", "macos", "windows"],
77
"minAppVersion": "20.8.0",
88
"authors": ["@r00tr4v3n", "@Aganel"],

latex-math/latex-math.qml

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ QtObject {
4040
"name": "Executable",
4141
"description": "Please enter a path to KLatexFormula",
4242
"type": "file",
43-
"default": "/usr/bin/klatexformula"
43+
"default": "klatexformula"
4444
},
4545
{
4646
"identifier": "formulaPrefix",
@@ -103,29 +103,17 @@ QtObject {
103103
script.regenerateNotePreview();
104104
}
105105

106-
/**
107-
* This function invokes a bash command
108-
* @param cmdList 0-cmdNumber, 1-path, 2-cmd
109-
* @return the result or [true/false] if detached = true
110-
*/
111-
function execBashList(cmdList) {
112-
const linuxExec = "bash";
106+
function execProcessList(cmdList) {
113107
log("got cmds: " + cmdList.length);
114108
if (cmdList.length > 0) {
115109
const cmd = cmdList.pop();
116-
const exec = script.platformIsWindows() ? cmd[2] : linuxExec;
117-
const param = script.platformIsWindows() ? [] : ["-c", cmd[2]];
118-
log("exec" + cmd[0] + ": " + exec);
119-
script.startDetachedProcess(exec, param, "callback-latex-math", cmdList);
110+
log("exec" + cmd[0] + ": " + cmd[2] + " " + JSON.stringify(cmd[3]));
111+
script.startDetachedProcess(cmd[2], cmd[3], "callback-latex-math", cmdList);
120112
}
121113
}
122-
function getBashCmd(path, latexBase64) {
123-
const exec = executable;
114+
function getProcessParameters(path, latexBase64) {
124115
const preamble = toBase64(getPreamble());
125-
const quiet = " --quiet 1"; // --quiet OFF does not work (klatexformula bug?)
126-
const cmd = `"${exec}" -f "${formulaColor}" -b "${formulaBgColor}" --base64arg --preamble="${preamble}" --base64arg --latexinput="${latexBase64}" --dpi ${settingDPI} ${quiet} --output ${path}`;
127-
//log("cmd: "+cmd)
128-
return cmd;
116+
return ["-f", formulaColor, "-b", formulaBgColor, "--base64arg", "--preamble=" + preamble, "--base64arg", "--latexinput=" + latexBase64, "--dpi", settingDPI, "--quiet", "1", "--output", path];
129117
}
130118
function getPreamble() {
131119
var packages = usepackages.split(',');
@@ -239,9 +227,7 @@ QtObject {
239227
if (!script.fileExists(path)) {
240228
// performance: do not create the same formula twice
241229
count++;
242-
var bashCmd = getBashCmd(path, latexBase64);
243-
//execBashDetached(bashCmd, true)
244-
cmdList.push([count, path, bashCmd]);
230+
cmdList.push([count, path, executable, getProcessParameters(path, latexBase64)]);
245231
}
246232

247233
// we need third slash after file:// if path contains drive letter (e.g. c:) in Windows
@@ -250,7 +236,7 @@ QtObject {
250236
return `<img style='vertical-align: bottom;' height='${imageSize}' src="file://${thirdSlash}${path}" alt="LaTex">`; //style='vertical-align: middle;'
251237
});
252238
if (cmdList.length > 0) {
253-
execBashList(cmdList); // use a 'thread pool'
239+
execProcessList(cmdList);
254240
}
255241
return html;
256242
}
@@ -267,9 +253,13 @@ QtObject {
267253
function onDetachedProcessCallback(callbackIdentifier, resultSet, cmd, thread) {
268254
if (callbackIdentifier == "callback-latex-math") {
269255
log("remaining: " + thread[1]);
256+
if (cmd[2] !== 0) {
257+
script.log("[LaTex] KLatexFormula failed with exit code " + cmd[2] + ": " + resultSet);
258+
return;
259+
}
270260
if (thread[0].length > 0) {
271261
log("more to do");
272-
execBashList(thread[0]);
262+
execProcessList(thread[0]);
273263
} else {
274264
log("done");
275265
script.regenerateNotePreview();

0 commit comments

Comments
 (0)