Skip to content

Commit

Permalink
Output compilation logs to the main form
Browse files Browse the repository at this point in the history
  • Loading branch information
zjkmxy committed Dec 7, 2023
1 parent 61efdf3 commit f5559a8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions public/swiftlatex/swiftlatexpdftex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/components/share-latex/share-latex/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default function ShareLatexComponent(
fullWidth
multiline
rows={props.compilationLog.split('\n').length}
minRows={1}
// minRows={1}
label="Compilation Log"
name="compilation-log"
type="text"
Expand Down
15 changes: 11 additions & 4 deletions src/components/share-latex/share-latex/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,21 @@ export default function ShareLatex(props: {

// Compile main.tex
engine.setEngineMainFile("main.tex")
setCompilationLog('Start compiling ...')
const res = await engine.compileLaTeX()
setCompilationLog(res.log)
let compLog = 'Start compiling ...\n'
setCompilationLog(compLog)
const res = await engine.compileLaTeX(async log => {
console.log(log)
compLog += log + '\n'
setCompilationLog(compLog)
})
compLog += '=============================================\n'
compLog += res.log
setCompilationLog(compLog)

// Check if PDF is generated
if (!res.pdf) {
alert('Failed to compile PDF file')
setCompilationLog(res.log)
// setCompilationLog(res.log)
return
}

Expand Down
14 changes: 8 additions & 6 deletions src/vendor/swiftlatex/PdfTeXEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class CompileResult {
}

type CommandString = 'compile' | 'compilelatex' | 'compileformat' | "settexliveurl" | "mkdir" |
"writefile" | "setmainfile" | "grace" | "flushcache";
"writefile" | "setmainfile" | "grace" | "flushcache" | "log";

type MsgType = {
result: string;
Expand Down Expand Up @@ -76,15 +76,18 @@ export class PdfTeXEngine {
}
}

public async compileLaTeX() {
public async compileLaTeX(logger: (log: string) => void) {
this.checkEngineStatus();
this.latexWorkerStatus = EngineStatus.Busy;
const start_compile_time = performance.now();
const res: CompileResult = await new Promise(resolve => {
this.latexWorker!.onmessage = (ev: MessageEvent<MsgType>) => {
if (ev.data.cmd !== "compile") return;
if (ev.data.cmd === "log") {
logger(ev.data.log ?? "");
return;
} else if (ev.data.cmd !== "compile") return;
this.latexWorkerStatus = EngineStatus.Ready;
console.log('Engine compilation finish ' + (performance.now() - start_compile_time));
logger('Engine compilation finish ' + (performance.now() - start_compile_time));
const nice_report = new CompileResult();
nice_report.status = ev.data.status!;
nice_report.log = ev.data.log ?? '';
Expand All @@ -95,7 +98,7 @@ export class PdfTeXEngine {
resolve(nice_report);
};
this.latexWorker!.postMessage({ 'cmd': 'compilelatex' });
console.log('Engine compilation start');
logger('Engine compilation start');
});
this.latexWorker!.onmessage = () => { };

Expand Down Expand Up @@ -157,7 +160,6 @@ export class PdfTeXEngine {
// console.warn('Flushing');
this.latexWorker.postMessage({ 'cmd': 'flushcache' });
}

}

public setTexliveEndpoint(url: string) {
Expand Down

0 comments on commit f5559a8

Please sign in to comment.