astoff / digestif

A language server for TeX and friends
Other
251 stars 6 forks source link

No completions for commands defined in another file #52

Open Glitzy3033 opened 1 year ago

Glitzy3033 commented 1 year ago

Greetings. Suppose I have two LaTeX files called main.tex and macro.tex in the same directory. Suppose macro.tex reads:

% !TeX root = main.tex
\newcommand{\hellohello}{\mathrm{hello}}

and it is included in main.tex:

\documentclass{article}
\input{macro.tex}
\begin{document}

...

\end{document}

An expected behavior is that when one starts to type \helloh... in main.tex, a completion should pop up. But the actual behavior is that no such completion is suggested by digestif. It seems that digestif does not find the commands defined in the included files.

astoff commented 1 year ago

It would be nice to fix this limitation, but this behavior stems from an important optimization tradeoff.

Currently, if main.tex includes, say, chapter1.tex and chapter2.tex, we pretend that any new commands or packages or further \inputs in chapter1.tex don't affect the way main.tex or chapter2.tex are parsed. This is not how TeX actually works, but it allows us not to reparse chapter2.tex if chapter1.tex changes. In this way, we can deal with documents of essentially arbitrary length as long as they are in the usual one-file-per-chapter model.

There are some even worse consequences of this optimization: If you move all your preamble to a sty file like this:

\documentclass{article}
\usepackage{mystyle}
\begin{document}
\include{chapter1}
\include{chapter2}
\end{document}

then Digesitf will not "see" any packages loaded in mystyle.sty.