From f1d551e8beb5307befc119c19e7a9f1516e9bf82 Mon Sep 17 00:00:00 2001 From: Urs Hofer Date: Fri, 29 Sep 2017 08:13:32 +0200 Subject: [PATCH 1/5] ARGS as option added option args, falling back to default if not passed. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index a4cb590..4fe30a7 100644 --- a/index.js +++ b/index.js @@ -117,7 +117,7 @@ function latex(src, options) { ? `${inputs.join(':')}:` : `${inputs}:` - const args = [ + const args = options.args || [ '-halt-on-error' ] From dd21093eea348d883c4a12d145f3fec151feb181 Mon Sep 17 00:00:00 2001 From: Urs Hofer Date: Fri, 29 Sep 2017 16:37:35 +0200 Subject: [PATCH 2/5] updated readme. --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index e9bc5f9..b3486c1 100644 --- a/readme.md +++ b/readme.md @@ -31,6 +31,8 @@ latex(input).pipe(output) **options.cmd** \[String\] - The command to run for your document (`pdflatex`, `xetex`, etc). `pdflatex` is the default. +**options.args** \[Array\] - Arguments passed to `cmd`. Defaults to `['-halt-on-error']`. + **options.passes** \[Number\] - The number of times to run `options.cmd`. Some documents require multiple passes. Only works when `doc` is a String. Defaults to `1`. **options.errorLogs** \[String] - The path to the file where you want to save the contents of the error log to. From aa38d8408feb3409f940a7fd4e189745a3cb8406 Mon Sep 17 00:00:00 2001 From: Urs Hofer Date: Wed, 8 Nov 2017 21:12:56 +0100 Subject: [PATCH 3/5] null-action on stdout and stderr prevent child process from stalling --- index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.js b/index.js index 4fe30a7..2836910 100644 --- a/index.js +++ b/index.js @@ -146,6 +146,12 @@ function latex(src, options) { handleErrors(new Error(`Error: Unable to run ${cmd} command.`)) }) + tex.stdout.on('data', (data) => {}); + + tex.stderr.on('data', (data) => {}); + + tex.on('close', (code) => {}); + tex.on('exit', (code) => { if (code !== 0) { printErrors(tempPath, userLogPath) From c69721ea27cc486771143039fc8aca1734a91a85 Mon Sep 17 00:00:00 2001 From: urshofer Date: Thu, 14 Dec 2017 11:14:24 +0100 Subject: [PATCH 4/5] Adding makeIndex Feature options.makeindex and options.indexStyle --- index.js | 26 ++++++++++++++++++++++++++ readme.md | 4 ++++ 2 files changed, 30 insertions(+) diff --git a/index.js b/index.js index 2836910..36329df 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ const strToStream = require('string-to-stream') const spawn = require('child_process').spawn +const spawnSync = require('child_process').spawnSync const through = require('through2') const fse = require('fs-extra') const temp = require('temp') @@ -130,6 +131,26 @@ function latex(src, options) { }) } + /** + * Indexing after each LaTeX pass + */ + + const indexCmd = options.makeindex ? 'makeindex' : false + var indexArgs = ['-g']; + + if (options.indexStyle) { + fs.writeFileSync(path.join(tempPath, 'index.ist'), options.indexStyle, 'utf8'); + indexArgs.push('-s texput.ist'); + } + + indexArgs.push('texput.idx'); + + const indexOpts = { + cwd: tempPath, + env: Object.assign({}, process.env) + } + + /** * Runs a LaTeX child process on the document stream * and then decides whether it needs to do it again. @@ -158,6 +179,11 @@ function latex(src, options) { return } + if (indexCmd !== false) { + let _indexResult = spawnSync(indexCmd, indexArgs, indexOpts) + } + + completedPasses++ // Schedule another run if necessary. diff --git a/readme.md b/readme.md index eb40756..4592ea4 100644 --- a/readme.md +++ b/readme.md @@ -41,5 +41,9 @@ latex(input).pipe(output) **options.errorLogs** \[String] - The path to the file where you want to save the contents of the error log to. +**options.makeindex** \[Bool] - if true, makeindex will be run after every pass. + +**options.indexStyle** \[String] - Index style file, will be temporary stored as a file and passed to makeindex as .sty file. + ## License MIT From 858fe5a2f83479e7abec19c7675090db780d0f02 Mon Sep 17 00:00:00 2001 From: urshofer Date: Thu, 14 Dec 2017 16:18:30 +0100 Subject: [PATCH 5/5] fixing args --- index.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/index.js b/index.js index 36329df..c46528b 100644 --- a/index.js +++ b/index.js @@ -136,19 +136,20 @@ function latex(src, options) { */ const indexCmd = options.makeindex ? 'makeindex' : false - var indexArgs = ['-g']; + var indexArgs = []; if (options.indexStyle) { - fs.writeFileSync(path.join(tempPath, 'index.ist'), options.indexStyle, 'utf8'); - indexArgs.push('-s texput.ist'); + fs.writeFileSync(path.join(tempPath, 'texput.ist'), options.indexStyle, 'utf8'); + indexArgs.push('-g'); + indexArgs.push('-s'); + indexArgs.push('texput.ist'); } - + + indexArgs.push('-o'); + indexArgs.push('texput.ind'); indexArgs.push('texput.idx'); - const indexOpts = { - cwd: tempPath, - env: Object.assign({}, process.env) - } + const indexOpts = {cwd: tempPath} /** @@ -212,4 +213,4 @@ function latex(src, options) { return outputStream } -module.exports = latex +module.exports = latex \ No newline at end of file