Skip to content

Commit

Permalink
Normalize paths for bibtex include directory
Browse files Browse the repository at this point in the history
  • Loading branch information
PHPirates committed Feb 22, 2025
1 parent 0d6392f commit d0668e6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.intellij.execution.process.ProcessHandler
import com.intellij.execution.process.ProcessTerminatedListener
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.util.execution.ParametersListUtil
import nl.hannahsten.texifyidea.run.compiler.LatexCompiler.Companion.toWslPath
import nl.hannahsten.texifyidea.run.compiler.LatexCompiler.Companion.toWslPathIfNeeded
import nl.hannahsten.texifyidea.run.latex.LatexDistributionType

/**
Expand All @@ -34,7 +34,7 @@ open class BibtexCommandLineState(
.forEach { wslCommand += " $it" }
}

wslCommand += " ${runConfig.bibWorkingDir?.path?.toWslPath(runConfig.getLatexDistributionType())}"
wslCommand += " ${runConfig.bibWorkingDir?.path?.toWslPathIfNeeded(runConfig.getLatexDistributionType())}"

mutableListOf("bash", "-ic", wslCommand)
}
Expand Down
5 changes: 4 additions & 1 deletion src/nl/hannahsten/texifyidea/run/compiler/BiberCompiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package nl.hannahsten.texifyidea.run.compiler
import com.intellij.openapi.project.Project
import com.intellij.util.execution.ParametersListUtil
import nl.hannahsten.texifyidea.run.bibtex.BibtexRunConfiguration
import nl.hannahsten.texifyidea.run.compiler.LatexCompiler.Companion.toWslPathIfNeeded
import nl.hannahsten.texifyidea.run.latex.LatexDistributionType

/**
* @author Thomas Schouten
Expand All @@ -18,7 +20,8 @@ internal object BiberCompiler : Compiler<BibtexRunConfiguration> {
// Biber can find auxiliary files, but the flag is different from bibtex.
// The following flag assumes the command is executed in the directory where the .bcf control file is.
// The extra directory added is the directory from which the path to the .bib resource file is searched as specified in the .bcf file.
add("--input-directory=${runConfig.mainFile?.parent?.path ?: ""}")
val mainPath = runConfig.mainFile?.parent?.path?.toWslPathIfNeeded(runConfig.getLatexDistributionType()) ?: ""
add("--input-directory=$mainPath")

runConfig.compilerArguments?.let { addAll(ParametersListUtil.parse(it)) }

Expand Down
6 changes: 4 additions & 2 deletions src/nl/hannahsten/texifyidea/run/compiler/BibtexCompiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.util.execution.ParametersListUtil
import nl.hannahsten.texifyidea.run.bibtex.BibtexRunConfiguration
import nl.hannahsten.texifyidea.run.compiler.LatexCompiler.Companion.toWslPathIfNeeded
import nl.hannahsten.texifyidea.run.latex.LatexDistributionType
import nl.hannahsten.texifyidea.settings.sdk.LatexSdkUtil

Expand All @@ -28,8 +29,9 @@ internal object BibtexCompiler : Compiler<BibtexRunConfiguration> {
// Include files from auxiliary directory on Windows
// We (mis)use project SDK as default setting for backwards compatibility
if ((runConfig.getLatexDistributionType() == LatexDistributionType.PROJECT_SDK && LatexSdkUtil.isMiktexAvailable) || runConfig.getLatexDistributionType().isMiktex(project)) {
add("-include-directory=${runConfig.mainFile?.parent?.path ?: ""}")
addAll(moduleRoots.map { "-include-directory=${it.path}" })
val mainPath = runConfig.mainFile?.parent?.path?.toWslPathIfNeeded(runConfig.getLatexDistributionType()) ?: ""
add("-include-directory=${mainPath}")
addAll(moduleRoots.map { "-include-directory=${it.path.toWslPathIfNeeded(runConfig.getLatexDistributionType())}" })
}

add(runConfig.mainFile?.nameWithoutExtension ?: return null)
Expand Down
8 changes: 4 additions & 4 deletions src/nl/hannahsten/texifyidea/run/compiler/LatexCompiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ enum class LatexCompiler(private val displayName: String, val executableName: St
"/out"
}
else {
runConfig.outputPath.getAndCreatePath()?.path?.toWslPath(runConfig.getLatexDistributionType())
runConfig.outputPath.getAndCreatePath()?.path?.toWslPathIfNeeded(runConfig.getLatexDistributionType())
}

val auxilPath = if (runConfig.getLatexDistributionType() == LatexDistributionType.DOCKER_MIKTEX) {
Expand All @@ -316,7 +316,7 @@ enum class LatexCompiler(private val displayName: String, val executableName: St
null
}
else {
runConfig.auxilPath.getAndCreatePath()?.path?.toWslPath(runConfig.getLatexDistributionType())
runConfig.auxilPath.getAndCreatePath()?.path?.toWslPathIfNeeded(runConfig.getLatexDistributionType())
}

val command = createCommand(
Expand All @@ -336,7 +336,7 @@ enum class LatexCompiler(private val displayName: String, val executableName: St
.forEach { wslCommand += " $it" }
}

wslCommand += " ${mainFile.path.toWslPath(runConfig.getLatexDistributionType())}"
wslCommand += " ${mainFile.path.toWslPathIfNeeded(runConfig.getLatexDistributionType())}"

return mutableListOf("bash", "-ic", wslCommand)
}
Expand Down Expand Up @@ -476,7 +476,7 @@ enum class LatexCompiler(private val displayName: String, val executableName: St
/**
* Convert Windows paths to WSL paths.
*/
fun String.toWslPath(distributionType: LatexDistributionType): String =
fun String.toWslPathIfNeeded(distributionType: LatexDistributionType): String =
if (distributionType == LatexDistributionType.WSL_TEXLIVE) {
runCommand("wsl", "wslpath", "-a", this) ?: this
}
Expand Down

0 comments on commit d0668e6

Please sign in to comment.