Skip to content

Commit

Permalink
Merge pull request #3151 from Hannah-Sten/latexmkrc-parsing
Browse files Browse the repository at this point in the history
Use TEXINPUTS properly (direct and via .latexmkrc)
  • Loading branch information
PHPirates committed Jul 13, 2023
2 parents e3129dd + 3c7f8aa commit 9733e7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/nl/hannahsten/texifyidea/reference/InputFileReference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ import nl.hannahsten.texifyidea.psi.LatexCommands
import nl.hannahsten.texifyidea.psi.LatexPsiHelper
import nl.hannahsten.texifyidea.run.latex.LatexRunConfiguration
import nl.hannahsten.texifyidea.settings.sdk.LatexSdkUtil
import nl.hannahsten.texifyidea.util.LatexmkRcFileFinder
import nl.hannahsten.texifyidea.util.expandCommandsOnce
import nl.hannahsten.texifyidea.util.*
import nl.hannahsten.texifyidea.util.files.*
import nl.hannahsten.texifyidea.util.includedPackages
import nl.hannahsten.texifyidea.util.isTestProject
import nl.hannahsten.texifyidea.util.magic.CommandMagic

/**
Expand Down Expand Up @@ -122,15 +119,17 @@ class InputFileReference(

// Check environment variables
val runManager = RunManagerImpl.getInstanceImpl(element.project) as RunManager
val texInputPath = runManager.allConfigurationsList
val texinputsVariable = runManager.allConfigurationsList
.filterIsInstance<LatexRunConfiguration>()
.firstOrNull { it.mainFile in rootFiles }
?.environmentVariables
?.envs
?.getOrDefault("TEXINPUTS", null)
// Not sure which of these takes precedence, or if they are joined together
?: LatexmkRcFileFinder.getTexinputsVariable(element.containingFile, null)
?: runCommand("kpsewhich", "--expand-var", "'\$TEXINPUTS'")

if (texInputPath != null) {
for (texInputPath in texinputsVariable?.split(":")?.filter { it.isNotBlank() } ?: emptyList()) {
val path = texInputPath.trimEnd(':')
searchPaths.add(path.trimEnd('/'))
// See the kpathsea manual, // expands to subdirs
Expand Down
2 changes: 1 addition & 1 deletion src/nl/hannahsten/texifyidea/util/LatexmkRcFileFinder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ object LatexmkRcFileFinder {
* Get TEXINPUTS from latexmkrc.
*/
private fun getTexinputs(file: VirtualFile): String? {
return """ensure_path\('TEXINPUTS',\s*'(?<path>[^']+)'\)""".toRegex().find(file.inputStream.reader().readText())?.groups?.get("path")?.value
return """ensure_path\(\s*'TEXINPUTS',\s*'(?<path>[^']+)'\s*\)""".toRegex().find(file.inputStream.reader().readText())?.groups?.get("path")?.value
}

private var usesLatexmkrc: Boolean? = null
Expand Down

0 comments on commit 9733e7f

Please sign in to comment.