4

I can compile all the LaTeX files in a directory sequentially as follows:

Get-ChildItem -include *.tex -name | ForEach-Object {
    lualatex --interaction=nonstopmode --output-directory=$pwd $_ } }

I would like to compile in parallel, two files at a time. I'm very new to Windows PowerShell, unfortunately, and I can't seem to find a good way to do this. Any ideas?

Adam Khan
  • 61
  • 1
  • 5
  • Take a look at this answer - http://stackoverflow.com/a/21520735/323582 - it suggests two ready to use solutions, both do processing in parallel and let you to specify the number of parallel jobs. – Roman Kuzmin Apr 11 '14 at 04:46
  • @RomanKuzmin, Using SplitPipeline, I now have something like this: ` Get-ChildItem -Path $PWD -Include *.tex -Name | Split-Pipeline -Count 2 -Order { process { lualatex --interaction=nonstopmode --output-directory=$PWD $_ } }` But the LaTeX compiler is complaining, "End of file on terminal...why?" Probably the LaTeX file name isn't being passed along properly. Any ideas what's going on? – Adam Khan Apr 11 '14 at 20:25
  • It's because of `-Name` in `Get-ChildItem`. Remove `-Name` and use `$_.FullName` inside `process{...}`. – Roman Kuzmin Apr 12 '14 at 04:14
  • That works. Thanks! I've ended up answering my own question with thanks to you. – Adam Khan Apr 13 '14 at 19:05

2 Answers2

2

This answer comes thanks to @RomanKuzmin and the SplitPipeline module.

Get-ChildItem -Include *.tex | SplitPipeline -Count 2 {
    process {
        lualatex --interaction=nonstopmode --output-directory=$( $_.DirectoryName ) $_.FullName } }
Adam Khan
  • 61
  • 1
  • 5
1

You can kick off a new process asynchronously using the Start-Process cmdlet. If you do not specify the -Wait parameter, then the process will execute asynchronously.

Get-ChildItem -Path $PSScriptRoot\* -Include *.tex | `
ForEach-Object -Process { `
    Start-Process -FilePath lualatex -ArgumentList ('lualatex --interaction=nonstopmode --output-directory={1} "{0}"' -f $PSItem.FullName, $pwd); `
    };

I have not tested this code, since I don't have the lualatex executable, but this should give you an idea of how it would work.