Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -158,6 +180,11 @@ function latex(src, options) {
return
}

if (indexCmd !== false) {
let _indexResult = spawnSync(indexCmd, indexArgs, indexOpts)
}


completedPasses++

// Schedule another run if necessary.
Expand Down Expand Up @@ -186,4 +213,4 @@ function latex(src, options) {
return outputStream
}

module.exports = latex
module.exports = latex
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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