Skip to content

Commit

Permalink
Merge pull request #3487 from Hannah-Sten/nomencl
Browse files Browse the repository at this point in the history
Add support for nomencl package
  • Loading branch information
PHPirates authored Mar 9, 2024
2 parents fa5549a + 664f482 commit 725c9e4
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 12 deletions.
28 changes: 28 additions & 0 deletions Writerside/topics/External-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,34 @@ TeXiFy also supports using xindy (instead of makeindex) and a custom index name,
See the imakeidx documentation at [https://ctan.org/pkg/imakeidx](https://ctan.org/pkg/imakeidx) for more details.
Note that in order to use xindy to need to install Perl.

### nomencl

Also the nomencl package is supported in the same way, as it uses makeindex.
Example from the nomencl documentation:

<!-- ```latex -->
```
\documentclass{article}
\usepackage[nocfg]{nomencl}
\makenomenclature
\begin{document}
\section*{Main equations}
\begin{equation}
a=\frac{N}{A}
\end{equation}%
\nomenclature{$a$}{The number of angels per unit area\nomrefeq}%
\nomenclature{$N$}{The number of angels per needle point\nomrefpage}%
\nomenclature{$A$}{The area of the needle point}%
The equation $\sigma = m a$%
\nomenclature{$\sigma$}{The total mass of angels per unit area\nomrefeqpage}%
\nomenclature{$m$}{The mass of one angel}
follows easily.
\eqdeclaration{32}
\printnomenclature
\end{document}
```

## Input index file filename.idx not found.
If you use an auxiliary directory (auxil/ or out/) then you may get an error message from imakeidx saying
`Input index file filename.idx not found.`.
Expand Down
1 change: 1 addition & 0 deletions src/nl/hannahsten/texifyidea/lang/LatexPackage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ open class LatexPackage @JvmOverloads constructor(
val NATBIB = LatexPackage("natbib")
val NEWTXMATH = LatexPackage("newtxmath")
val NTHEOREM = LatexPackage("ntheorem")
val NOMENCL = LatexPackage("nomencl")
val PDFCOMMENT = LatexPackage("pdfcomment")
val PYTHONTEX = LatexPackage("pythontex")
val REPEATINDEX = LatexPackage("repeatindex")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ class LatexRunConfiguration(
*/
fun getAuxilDirectory(): VirtualFile? {
return if (latexDistribution.isMiktex(project)) {
auxilPath.getAndCreatePath()
// If we are using MiKTeX it might still be we are not using an auxil directory, so then fall back to the out directory
auxilPath.getAndCreatePath() ?: outputPath.getAndCreatePath()
}
else {
outputPath.getAndCreatePath()
Expand Down
7 changes: 1 addition & 6 deletions src/nl/hannahsten/texifyidea/run/latex/MakeindexUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,17 @@ import nl.hannahsten.texifyidea.util.parser.toStringMap
import nl.hannahsten.texifyidea.run.compiler.MakeindexProgram
import nl.hannahsten.texifyidea.util.SystemEnvironment
import nl.hannahsten.texifyidea.util.files.psiFile
import nl.hannahsten.texifyidea.util.includedPackages
import nl.hannahsten.texifyidea.util.magic.CommandMagic
import nl.hannahsten.texifyidea.util.magic.PackageMagic

/**
* Try to find out which index program the user wants to use, based on the given options.
* This can be multiple, if the user for example uses an index and a glossary.
*/
fun getDefaultMakeindexPrograms(mainFile: VirtualFile?, project: Project): Set<MakeindexProgram> {
fun getDefaultMakeindexPrograms(mainFile: VirtualFile?, project: Project, usedPackages: Collection<LatexPackage>): Set<MakeindexProgram> {
val indexPackageOptions = getIndexPackageOptions(mainFile, project)
val makeindexOptions = getMakeindexOptions(mainFile, project)

val usedPackages = runReadAction {
mainFile?.psiFile(project)?.includedPackages() ?: emptySet()
}

val indexPrograms = mutableSetOf<MakeindexProgram>()

if (usedPackages.intersect(PackageMagic.index).isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ class MakeindexCommandLineState(

val command = ParametersListUtil.parse(commandLineArguments ?: "").apply {
add(0, indexProgram.executableName)
add(indexFilename)
// The -o parameter overrides the output file name, so then we shouldn't append it a second time
if (commandLineArguments == null || commandLineArguments.contains("-o").not()) {
add(indexFilename)
}
}
val commandLine = GeneralCommandLine(command).withWorkDirectory(workingDirectory?.path)

Expand Down
17 changes: 15 additions & 2 deletions src/nl/hannahsten/texifyidea/run/makeindex/RunMakeindexListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import com.intellij.execution.impl.RunManagerImpl
import com.intellij.execution.process.ProcessEvent
import com.intellij.execution.process.ProcessListener
import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.openapi.application.runReadAction
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.io.FileUtil
import nl.hannahsten.texifyidea.lang.LatexPackage
import nl.hannahsten.texifyidea.run.compiler.MakeindexProgram
import nl.hannahsten.texifyidea.run.latex.LatexConfigurationFactory
import nl.hannahsten.texifyidea.run.latex.LatexRunConfiguration
import nl.hannahsten.texifyidea.run.latex.getDefaultMakeindexPrograms
import nl.hannahsten.texifyidea.run.latex.getMakeindexOptions
import nl.hannahsten.texifyidea.util.appendExtension
import nl.hannahsten.texifyidea.util.files.psiFile
import nl.hannahsten.texifyidea.util.includedPackages
import nl.hannahsten.texifyidea.util.magic.FileMagic
import java.io.File
import java.io.FileNotFoundException
Expand Down Expand Up @@ -98,7 +102,12 @@ class RunMakeindexListener(

private fun generateIndexConfigs(): Set<RunnerAndConfigurationSettings> {
val runManager = RunManagerImpl.getInstanceImpl(environment.project)
val indexPrograms = getDefaultMakeindexPrograms(latexRunConfig.mainFile, environment.project)

val usedPackages = runReadAction {
latexRunConfig.mainFile?.psiFile(environment.project)?.includedPackages() ?: emptySet()
}
val mainFile = latexRunConfig.mainFile
val indexPrograms = getDefaultMakeindexPrograms(mainFile, environment.project, usedPackages)

val runConfigs = mutableSetOf<RunnerAndConfigurationSettings>()

Expand All @@ -110,9 +119,13 @@ class RunMakeindexListener(

val runConfig = makeindexRunConfigSettings.configuration as MakeindexRunConfiguration

runConfig.mainFile = latexRunConfig.mainFile
runConfig.mainFile = mainFile
runConfig.makeindexProgram = indexProgram
runConfig.setSuggestedName()
// See nomencl documentation
if (LatexPackage.NOMENCL in usedPackages && indexProgram == MakeindexProgram.MAKEINDEX) {
runConfig.commandLineArguments = "${mainFile?.nameWithoutExtension}.nlo -s nomencl.ist -o ${mainFile?.nameWithoutExtension}.nls"
}

// bib2gls we handle separately, because it needs the bib file, so instead of running it in the auxil dir we run it next to the main file
runConfig.workingDirectory = if (runConfig.makeindexProgram != MakeindexProgram.BIB2GLS) latexRunConfig.getAuxilDirectory() else runConfig.mainFile?.parent
Expand Down
5 changes: 4 additions & 1 deletion src/nl/hannahsten/texifyidea/settings/sdk/LatexSdk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nl.hannahsten.texifyidea.settings.sdk
import com.intellij.openapi.projectRoots.*
import com.intellij.openapi.vfs.VirtualFile
import nl.hannahsten.texifyidea.run.latex.LatexDistributionType
import nl.hannahsten.texifyidea.util.runWriteAction
import org.jdom.Element

/**
Expand Down Expand Up @@ -30,7 +31,9 @@ abstract class LatexSdk(name: String) : SdkType(name) {
override fun setupSdkPaths(sdk: Sdk) {
val modificator = sdk.sdkModificator
modificator.versionString = getVersionString(sdk)
modificator.commitChanges() // save
runWriteAction {
modificator.commitChanges() // save
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/nl/hannahsten/texifyidea/util/magic/PackageMagic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.INDEX
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.INDEXTOOLS
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.MAKEIDX
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.MULTIND
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.NOMENCL
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.REPEATINDEX
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.SPLITIDX
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.SPLITINDEX
Expand All @@ -26,7 +27,7 @@ object PackageMagic {
* All known packages which provide an index.
*/
val index = hashSetOf(
MAKEIDX, MULTIND, INDEX, SPLITIDX, SPLITINDEX, IMAKEIDX, HVINDEX, IDXLAYOUT, REPEATINDEX, INDEXTOOLS
MAKEIDX, MULTIND, INDEX, SPLITIDX, SPLITINDEX, IMAKEIDX, HVINDEX, IDXLAYOUT, REPEATINDEX, INDEXTOOLS, NOMENCL
)

/**
Expand Down

0 comments on commit 725c9e4

Please sign in to comment.