James-Yu / LaTeX-Workshop

Boost LaTeX typesetting efficiency with preview, compile, autocomplete, colorize, and more.
MIT License
10.62k stars 529 forks source link

How to add IntelliSense to personal packages in a texmf tree? #4285

Closed ShaiAvr closed 3 months ago

ShaiAvr commented 3 months ago

I am using VSCode with the Latex Workshop extension as my new Latex IDE and I am loving it so far. However, I can't figure out how to add IntelliSense to my personal packages. I have a repository for my University assignments and inside it, I have a texmf tree which contains my packages with custom styles and macros. I set the TEXMFLOCAL variable to point to that directory, so my code compiles and works fine. As an example, here's my texmf tree:

Screenshot 2024-06-14 132436

Now somewhere else in the repo I have a document:

% main.tex
\documentclass{article}

\usepackage{my-style} % Includes many packages I always use and personal macros

\begin{document}
\Foo % use my personal macro \Foo
\include{bar} % include another file
\end{document}

% bar.tex
\section{Demo}
\Bar % Use another macro \Bar from my-style

I don't get IntelliSense for the \Foo and \Bar macros either in main.tex or bar.tex. I read the wiki page about IntelliSense and it looks like the 4th point suits my case. I tried adding my texmf tree to the latex-workshop.latex.texDirs option. I first tried using placeholders so it doesn't depend on the actual path on my system:

"latex-workshop.latex.texDirs": ["%WORKSPACE_FOLDER/texmf%"]

I also tried to use wildcards to get all the subdirectories, and I tried to give it the absolute path too. Nothing worked. I never got IntelliSense for my macros. How can I generate IntelliSense for the macros in my package? Maybe I was wrong about using point 4 and I should implement point 5? Does it mean I need to write a .cwl file and parse it with pkgcommand.py?

Maybe we need to update the documentation to give clearer instructions on how to add custom IntelliSense and provide some examples people can learn from.