Repository: hannah-sten/texify-idea
Issue: Incorrect invocation when using custom compiler arguments (-shell-escape) in WSL

#### Type of JetBrains IDE (IntelliJ, PyCharm, etc.) and version
IntelliJ IDEA 2021.2.3 (Community Edition)
Build #IC-212.5457.46, built on October 12, 2021
Runtime version: 11.0.12+7-b1504.40 amd64

#### Operating System 
Windows + WSL (Ubuntu 20.04)

#### TeXiFy IDEA version
0.7.14

#### What I did (steps to reproduce)

1. Create an empty latex project.
2. Select "Tex Live using WSL" in your run configuration -> Latex Distribution.
3. Compile; this works fine.
  This invokes
  `bash -ic "pdflatex -file-line-error -interaction=nonstopmode -synctex=1 -output-format=pdf -output-directory=<my-project-dir>/out <my-project-dir>/src/main.tex"`
4. Then add "-shell-escape" to the custom compiler arguments in the run configuration.
  This invokes
  `bash -ic "pdflatex -file-line-error -interaction=nonstopmode -synctex=1 -output-format=pdf -output-directory=<my-project-dir>/out" "-shell-escape <my-project-dir>/src/main.tex"`
  Notice the additional quotation marks.

#### Minimal example to reproduce the problem

Create an empty project with -shell-escape custom compiler arguments and select "Tex Live using WSL" in the Latex Distributions.

#### Expected behavior

I believe the problem would be solved if the compiler arguments are appended to the first argument of the bash command, i.e.
`bash -ic "pdflatex -file-line-error -interaction=nonstopmode -synctex=1 -output-format=pdf -output-directory=<my-project-dir>/out -shell-escape <my-project-dir>/src/main.tex"`
This works as expected when I run the command manually in a WSL prompt.

#### Actual behavior

I get the following output when I compile with "-shell-escape" in the custom compiler arguments field:
```
bash -ic "pdflatex -file-line-error -interaction=nonstopmode -synctex=1 -output-format=pdf -output-directory=<truncated>/out" "-shell-escape <truncated>/src/main.tex"
This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022) (preloaded format=pdflatex)
 restricted \\write18 enabled.
**
```
which leaves pdflatex waiting for input (I believe?).

Changed files:
src/nl/hannahsten/texifyidea/run/compiler/LatexCompiler.kt

diff --git a/src/nl/hannahsten/texifyidea/run/compiler/LatexCompiler.kt b/src/nl/hannahsten/texifyidea/run/compiler/LatexCompiler.kt
index 5fecb1f3c..5ebc72314 100644
--- a/src/nl/hannahsten/texifyidea/run/compiler/LatexCompiler.kt
+++ b/src/nl/hannahsten/texifyidea/run/compiler/LatexCompiler.kt
@@ -319,7 +319,17 @@ enum class LatexCompiler(private val displayName: String, val executableName: St
         )
 
         if (runConfig.getLatexDistributionType() == LatexDistributionType.WSL_TEXLIVE) {
-            command = mutableListOf("bash", "-ic", GeneralCommandLine(command).commandLineString)
+            var wslCommand = GeneralCommandLine(command).commandLineString
+
+            // Custom compiler arguments specified by the user
+            runConfig.compilerArguments?.let { arguments ->
+                ParametersListUtil.parse(arguments)
+                        .forEach { wslCommand += " $it" }
+            }
+
+            wslCommand += " ${mainFile.path.toPath(runConfig)}"
+
+            return mutableListOf("bash", "-ic", wslCommand)
         }
 
         if (runConfig.getLatexDistributionType() == LatexDistributionType.DOCKER_MIKTEX) {
@@ -329,15 +339,10 @@ enum class LatexCompiler(private val displayName: String, val executableName: St
         // Custom compiler arguments specified by the user
         runConfig.compilerArguments?.let { arguments ->
             ParametersListUtil.parse(arguments)
-                .forEach { command.add(it) }
+                    .forEach { command.add(it) }
         }
 
-        if (runConfig.getLatexDistributionType() == LatexDistributionType.WSL_TEXLIVE) {
-            command[command.size - 1] = command.last() + " ${mainFile.path.toPath(runConfig)}"
-        }
-        else {
-            command.add(mainFile.name)
-        }
+        command.add(mainFile.name)
 
         return command
     }