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 all commits
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
39 changes: 38 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,44 @@
### Added

### Fixed

## [0.9.9-alpha.8] - 2024-11-28

### Added

* Add support for \includesvg
* Support references in \subfix command
* Provide autocompletion for all relevant directories when using subfiles
* Do not format existing directories in the given path in the file creation quickfix dialog
* Disable Evince inverse search on Windows to avoid a UI freeze on opening a second project
* Use xdg-mime to choose a default pdf viewer in the run configuration template
* Don't insert the right brace when in front of text
* Add DeclareMathSymbol to indexed command definitions in installed packages
* Add support for TEXMFHOME for reference resolving
* Add diffcoeff and upgreek packages to autocompletion, by @Toseflo
* Improve reference resolving when using subfiles
* Add setting to disable auto-import of bibtex entries from remote libraries

### Fixed

* Fix exception #3771 when a file referenced from cache is deleted
* Fix basic case of false positive of duplicate label inspection when user defined \if commands are used
* Fix a parse error when using \else with a user defined \if-command
* Fix relative path conversion in graphics insertion wizard by resolving relative to the root file
* Fix exception #3763
* Fix 'missing import' false positive in subfiles
* Don't override the file icon for .txt files, by @Steve-Li-1998
* Fix exceptions #3754 and #3326
* Fix exceptions in structure view when command parameters are missing
* Improve error report submitter for long stacktraces
* Fix a parser issue with bidirectional arrow in TikZ
* Fix default Docker image name when running Dockerized TeX Live without a project SDK
* Always use content roots to resolve references
* Fix 'package not found' error when using texlive-full on Windows, and improve running of system commands, by @tristankretzer
* Fix rename of files when using subfiles
* Fix incorrect 'package already included' warning for the subfiles package
* Fix exception #3557 if using bibtex structure view when bibtex file type is reassignd to plain text
* Avoid referencing obsolete psifiles, fix exception #3635

## [0.9.9-alpha.7] - 2024-11-24

Expand All @@ -26,6 +61,7 @@
* Add setting to disable auto-import of bibtex entries from remote libraries

### Fixed

* Fix relative path conversion in graphics insertion wizard by resolving relative to the root file
* Fix exception #3763
* Fix 'missing import' false positive in subfiles
Expand Down Expand Up @@ -520,7 +556,8 @@ Thanks to @jojo2357 and @MisterDeenis for contributing to this release!
* Fix some intention previews. ([#2796](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2796))
* Other small bug fixes and improvements. ([#2776](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2776), [#2774](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2774), [#2765](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2765)-[#2773](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2773))

[Unreleased]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.9-alpha.7...HEAD
[Unreleased]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.9-alpha.8...HEAD
[0.9.9-alpha.8]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.9-alpha.7...v0.9.9-alpha.8
[0.9.9-alpha.7]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.9-alpha.6...v0.9.9-alpha.7
[0.9.9-alpha.6]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.9-alpha.4...v0.9.9-alpha.6
[0.9.9-alpha.4]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.9-alpha.3...v0.9.9-alpha.4
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pluginVersion = 0.9.9-alpha.7
pluginVersion = 0.9.9-alpha.8

# Info about build ranges: https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html
# Note that an xyz branch corresponds to version 20xy.z and a since build of xyz.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package nl.hannahsten.texifyidea.completion.pathcompletion
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiFile
import nl.hannahsten.texifyidea.index.LatexIncludesIndex
import nl.hannahsten.texifyidea.lang.commands.LatexGenericRegularCommand
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 +33,7 @@ class LatexGraphicsPathProvider : LatexPathProviderBase() {
*/
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 { command -> CommandMagic.graphicPathsCommands.map { it.cmd }.contains(command.name) }

// Is a graphicspath defined?
if (graphicsPathCommands.isNotEmpty()) {
Expand Down Expand Up @@ -95,7 +95,7 @@ class LatexGraphicsPathProvider : LatexPathProviderBase() {
* 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
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ open class LatexFileNotFoundInspection : TexifyInspectionBase() {

// Display a dialog to ask for the location and name of the new file.
// By default, all inclusion paths are relative to the main file
val newFilePath = CreateFileDialog(root, filePath.replace("$root/", "").formatAsFilePath())
val newFilePath = CreateFileDialog(root, filePath.replace("$root/", ""))
.newFileFullPath ?: return

runWriteAction {
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,9 +148,12 @@ 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)) {
// Add the graphics paths to the search paths
searchPaths.addAll(LatexGraphicsPathProvider().getGraphicsPathsInFileSet(element.containingFile))
if (!isBuildingFileset) {
val includedPackages = element.containingFile.includedPackages()
if (CommandMagic.graphicPathsCommands.any { includedPackages.contains(it.dependency) }) {
// Add the graphics paths to the search paths
searchPaths.addAll(LatexGraphicsPathProvider().getGraphicsPathsInFileSet(element.containingFile))
}
}
for (searchPath in searchPaths) {
val path = if (!searchPath.endsWith("/")) "$searchPath/" else searchPath
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