diff --git a/index.js b/index.js index 2836910..c46528b 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,27 @@ function latex(src, options) { }) } + /** + * Indexing after each LaTeX pass + */ + + const indexCmd = options.makeindex ? 'makeindex' : false + var indexArgs = []; + + if (options.indexStyle) { + 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} + + /** * Runs a LaTeX child process on the document stream * and then decides whether it needs to do it again. @@ -158,6 +180,11 @@ function latex(src, options) { return } + if (indexCmd !== false) { + let _indexResult = spawnSync(indexCmd, indexArgs, indexOpts) + } + + completedPasses++ // Schedule another run if necessary. @@ -186,4 +213,4 @@ function latex(src, options) { return outputStream } -module.exports = latex +module.exports = latex \ No newline at end of file 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