Hannah-Sten / TeXiFy-IDEA

LaTeX support for the IntelliJ platform by JetBrains.
https://hannah-sten.github.io/TeXiFy-IDEA
MIT License
897 stars 90 forks source link

Support commands in paths in \addbibresource #3655

Closed maxanier closed 1 week ago

maxanier commented 2 months ago

Situation

I have multiple Bibtex libraries outside my project directory which I a) include in my Tex file and b) have added to the "Remote Libraries" tab. In addition, I have included a IEEEabrv.bib file inside the project directory with journal title abbreviations in my Tex file.

TeXiFy: 0.9.7 PyCharm: 2024.2.0.1 (Community Edition)

Problem

If I have a citation of a reference that is in the "remote" (outside of project directory), this is fine for pdflatex/biblatex/biber, but TeXiFy shows a warning that the reference cannot be found. This seems to be due to those files not being indexed. This is ok for me. However: When typing a \cite{ command, TeXiFy offers to autocomplete the citation key from the remote libraries. If accepted, it copies that entry from the "remote" library to the "local" IEEEabrv.bib file. This is apparently intentional:

When using completion on an item that is not in the local bibliography file it will be added by TeXiFy and makes sense if the "remote" library is actually remote or at least not included in the main file anyway.

For me, this does not make sense because the "remote" library is included in my Tex document anyway.

Proposed Feature

I would like to see maybe a config option to disable this auto-import (globally, on project basis, or even per remote library). This would also might help with informing the user about the feature itself. It took me some time to figure out why references that I deleted would still be available in my Tex document (they were unknowingly added somewhere in the middle of my IEEEabrv.bib file).

Alternatively or additionally, I would like to either configure the "local" .bib file to which the imported entries are added or have a documentation on how this file is selected by TeXiFy. I don't want my IEEEabrv.bib modified, but rather another.

If you happen to have time to implement this, that would be awesome. If not, maybe you can point me to a point to get started. I have no experience with Kotlin nor Intellij plugins, but maybe I will be able to create at least a hacky workaround.

Sidenote: Awesome plugin. PyCharm + TeXiFy is now my favorite LaTeX IDE

PHPirates commented 1 month ago

I have multiple Bibtex libraries outside my project directory which I a) include in my Tex file and b) have added to the "Remote Libraries" tab.

Could you explain why you use the remote libraries tool window? If you include a bib file in your main LaTeX file then you should have autocompletion. Where is the bib file located and how do you include it?

maxanier commented 1 month ago

I have a non "standard" setup (of course): The Tex code is in a Git repository. The .bib files are in a different location and synced by Nextcloud. I work on different systems and both Linux and Windows, so the paths of .bib files vary. Hence, I have a "environment" file in the Tex repo which is not checked in and defines the root path for my .bib files on the respective system as a macro. Then I include the bibliography in my main.tex using the macro:

\addbibresource{references/IEEEabrv.bib}
%! suppress = FileNotFound
\addbibresource{\myCloudstoreLocation/Publikationen/mybib.bib}
...

I don't know how TeXiFy identifies and indexes the bibliography, but I assume it does not parse macros and doesn't index outside the project root anyway. This is fine. But I want to have all my references in a single synced location independent of my Tex repositories. Therefore, the "remote" libraries tool seems ideal.

The autoimport to a local file is also nice in general, but since I sometimes edit the references in my main file (change keywords, change from submitted to published, ...). I wanted to disable this feature to avoid having outdated local entries. But maybe it is not a bad idea after all... Maybe I have to use it a bit to weight benefits and drawbacks.

So my main feature request would be to have a way to specify the file the entries are imported to. Then I can still just delete that file if I don't want the imported entries. I was not able to figure out, which file is currently selected. Adding a second local bib did not work.

PHPirates commented 1 month ago

Thanks, that makes sense. I assume \myCloudstoreLocation is defined like \newcommand{\myCloudstoreLocation}{/some/path}? If yes, we should be able to support that, I believe we already support commands in paths for some other feature. TeXiFy already indexes files outside the project root, as that is how we provide autocompletion for installed packages.

In the meantime, I agree the remote libraries feature could be used as a workaround if we add a setting to disable the auto import.

maxanier commented 2 weeks ago

Great :)

Parsing such commands/"macros" to determine the path and indexing them too would of course be ideal. But I understand/assume that this is not trivial and may become messy due to the flexibility in doing such.

My \addbibresource works as follows:

main.tex:

\input{env}
\addbibresource{\myCloudstoreLocation/Publikationen/mybib.bib}

env.tex

\def\myCloudstoreLocation{C:/cloud/datashare}

Of course I can replace my \def with \newcommand{\myCloudstoreLocation}{/some/path}

PHPirates commented 2 weeks ago

Added the setting in 0.9.9-alpha.1 (it is waiting for review for some reason)

PHPirates commented 1 week ago

Of course I can replace my \def with \newcommand{\myCloudstoreLocation}{/some/path}

I just checked again, and the reason it doesn't work is indeed that a plain \def is used, which is hard(er) to support. With a \newcommand it works for me:

\newcommand{\dateispeicherort}{/some/path}
\addbibresource{\dateispeicherort/Literaturverzeichnis.bib}

Please reopen if this does not work.

maxanier commented 1 week ago

The added config option works for me. Thank you :) I can confirm that the \newcommand method also works :) Although it only works if the reference file is inside the project scope #3748