Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for \includesvg #3776

Merged
merged 6 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

### Added
* Add support for \includesvg

### Fixed
* Fix basic case of false positive of duplicate label inspection when user defined \if commands are used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiFile
import nl.hannahsten.texifyidea.index.LatexIncludesIndex
import nl.hannahsten.texifyidea.lang.commands.LatexGenericRegularCommand

Check warning on line 6 in src/nl/hannahsten/texifyidea/completion/pathcompletion/LatexGraphicsPathProvider.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unused import directive

Unused import directive
import nl.hannahsten.texifyidea.psi.LatexCommands
import nl.hannahsten.texifyidea.psi.LatexNormalText
import nl.hannahsten.texifyidea.util.files.*
import nl.hannahsten.texifyidea.util.magic.CommandMagic
import nl.hannahsten.texifyidea.util.magic.cmd
import nl.hannahsten.texifyidea.util.parser.childrenOfType
import java.io.File
Expand All @@ -33,7 +34,7 @@
*/
fun getGraphicsPathsInFileSet(file: PsiFile): List<String> {
val graphicsPaths = mutableListOf<String>()
val graphicsPathCommands = file.commandsInFileSet().filter { it.name == LatexGenericRegularCommand.GRAPHICSPATH.cmd }
val graphicsPathCommands = file.commandsInFileSet().filter { CommandMagic.graphicPathsCommands.map { it.cmd }.contains(it.name) }

Check notice on line 37 in src/nl/hannahsten/texifyidea/completion/pathcompletion/LatexGraphicsPathProvider.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nested lambda has shadowed implicit parameter

Implicit parameter 'it' of enclosing lambda is shadowed
Fixed Show fixed Hide fixed

// Is a graphicspath defined?
if (graphicsPathCommands.isNotEmpty()) {
Expand Down Expand Up @@ -95,7 +96,7 @@
* Get all the graphics paths defined by one \graphicspaths command.
*/
private fun LatexCommands.getGraphicsPaths(): List<String> {
if (name != LatexGenericRegularCommand.GRAPHICSPATH.cmd) return emptyList()
if (!CommandMagic.graphicPathsCommands.map { it.cmd }.contains(name)) return emptyList()
return parameterList.firstNotNullOfOrNull { it.requiredParam }
// Each graphics path is in a group.
?.childrenOfType(LatexNormalText::class)
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 @@ -83,6 +83,7 @@ open class LatexPackage @JvmOverloads constructor(
val SPLITINDEX = LatexPackage("splitindex")
val STMARYRD = LatexPackage("stmaryrd")
val SUBFILES = LatexPackage("subfiles")
val SVG = LatexPackage("svg")
val TABULARRAY = LatexPackage("tabularray")
val TCOLORBOX = LatexPackage("tcolorbox")
val TEXTCOMP = LatexPackage("textcomp")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.GLOSSARIES
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.GRAPHICX
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.MATHTOOLS
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.NTHEOREM
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.SVG
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.TEXTCOMP
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.ULEM
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.VARIOREF
Expand Down Expand Up @@ -147,6 +148,7 @@ enum class LatexGenericRegularCommand(
INPUTMINTED("inputminted", "language".asRequired(Argument.Type.MINTED_FUNTIME_LAND), RequiredFileArgument("sourcefile", true, false, ""), dependency = LatexPackage.MINTED),
INCLUDEGRAPHICS("includegraphics", "key-val-list".asOptional(), RequiredPicturePathArgument("imagefile", isAbsolutePathSupported = true, commaSeparatesArguments = false, FileMagic.graphicFileExtensions, supportsAnyExtension = false), dependency = GRAPHICX),
INCLUDEONLY("includeonly", RequiredFileArgument("sourcefile", false, true, "tex")),
INCLUDESVG("includesvg", "options".asOptional(), RequiredPicturePathArgument("svg file", isAbsolutePathSupported = true, commaSeparatesArguments = false, extension = listOf("svg"), supportsAnyExtension = false), dependency = SVG),
INDEXNAME("indexname", "name".asRequired()),
INDEXSPACE("indexspace"),
INDEX("intex", "entry".asRequired()),
Expand Down Expand Up @@ -303,6 +305,7 @@ enum class LatexGenericRegularCommand(
SUBSUBSECTION_STAR("subsubsection*", "title".asRequired(Argument.Type.TEXT)),
SUBSUBSECTIONMARK("subsubsectionmark", "code".asRequired()),
SUPPRESSFLOATS("suppressfloats", "placement".asOptional()),
SVGPATH("svgpath", RequiredFolderArgument("foldername"), dependency = SVG),
SYMBOL("symbol", "n".asRequired()),
TABCOLSEP("tabcolsep"),
TABLENAME("tablename", "name".asRequired(Argument.Type.TEXT)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ class InputFileReference(
// Try graphicspaths
if (targetFile == null) {
// If we are not building the fileset, we can make use of it
if (!isBuildingFileset && element.containingFile.includedPackages().contains(LatexGenericRegularCommand.GRAPHICSPATH.dependency)) {
val includedPackages = element.containingFile.includedPackages()
if (!isBuildingFileset && CommandMagic.graphicPathsCommands.any { includedPackages.contains(it.dependency) }) {
// Add the graphics paths to the search paths
searchPaths.addAll(LatexGraphicsPathProvider().getGraphicsPathsInFileSet(element.containingFile))
}
Expand Down
2 changes: 2 additions & 0 deletions src/nl/hannahsten/texifyidea/util/magic/CommandMagic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ object CommandMagic {
"\\DeclareDocumentEnvironment"
)

val graphicPathsCommands = listOf(GRAPHICSPATH, SVGPATH)

/**
* Commands that should not have the given file extensions.
*/
Expand Down
Loading