James-Yu / LaTeX-Workshop

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

latex.watch.files.ignore not ignoring tex files #3585

Closed drriguz closed 1 year ago

drriguz commented 1 year ago

Hi, I'd like to make some pre-processing to generate a "final" tex from the original one, the file structure looks like bellow:

\src
   - main.tex 
   \ chapters
     - ch01.tex
\ generated
   - main.tex

So I would like latex workshop to watch only the generated folder, but not the src one, because it is actually not a valid tex file. I set latex.watch.files.ignore=src/** or latex.watch.files.ignore=**/src/** , but latex woskshop still will try to build it when save src/main.tex.

I'm not sure whether this is the intended behavior, any help will be appreciated.

James-Yu commented 1 year ago

This is by design. A quick fix is to use TeX root comment to define the root file.

However, the description of latex.watch.files.ignore states files to ignore from the watching mechanism used for triggering autobuild. Now the config is used to stop sub-file parsing, but allows for findRootFromActive(). Shall we change the logic so that files defined in ignore won't be selected as root? @jlelong

jlelong commented 1 year ago

This is actually more complicated than I thought and the logic is sometimes hard to follow. I will make a detailed report shortly.

drriguz commented 1 year ago

Hi there, since it's more complicated than I originally thought, I'm taking another approach now. I'll use another file extension for the half-done tex files, ie.

\src
   - main.txt
   \ chapters
     - ch01.txt
\ generated
   - main.tex

Thus there's no conflication anymore.

BTW, I'm trying to copy the latexmk commands to a Makefile, however I cannot compile using the same commands copied from the output window. It seems that some magic things is used in latex-workshop, maybe TEXTINPUTS? Where can I found the complete latex make commands (as well as other environment varibles) that is using when latex-workshop compiles the file?

jlelong commented 1 year ago

The description of the setting latex.watch.files.ignore is not completely correct. This setting has a much wider impact than just auto-build and unfortunately it is not always coherent.

Consider the case of a main.tex file including subfile.tex and add subfile.tex to latex.watch.files.ignore. There are two different situations depending on which file is edited

  1. Open main.tex. The file subfile.tex is almost completely ignored:

    • It is listed as a child of main.tex in this.extension.manager.cachedContent['main.tex']
    • An entry this.extension.manager.cachedContent['subfile.tex'] exists
    • It is used for build the structure view in the TeX badge
    • Its content is not parsed by parseFileAndSubs
    • The file is not watched. Hence, its content is not used to provide intellisense (eg. references defined in subfile.tex are not available for completion) and (external) changes to the file will not trigger auto build even when set to on file change.
  2. Switch to subfile.tex

    • Saving updates its cached content in this.extension.manager.cachedContent['subfile.tex']
    • When intellisense.update.aggressive.enabled is set to true, updateCompleter is called and the content of the file becomes available for intellisense.

I will think about all this and try to come with clearer and more coherent logic. I think its deserves a dedicated issue.

For the time being, I am against changing the behaviour of findRootFromActive. This has to be part of a more general reflexion.

jlelong commented 1 year ago

@drriguz If I understand your use case correctly, you edit the files in src, but you want those in generated to be compiled. If this is the case, I suggest you to keep the .tex extension for the files in src otherwise lots of LW features will not work. Create a recipe to run your preprocessing and then to build the files in generated, which means running latexmk path/to/generated/main.tex.

Trying to extract commands from latexmk is a bad idea because latexmk is a very sophisticated tool to handle dependencies and LaTeX multiple compilations.

James-Yu commented 1 year ago

With the new cacher design, latex.watch.files.ignore behavior seems a bit more coherent. This config is used only to determine whether a file should be watched / cached. Together with other big and small refactors, now the user-sensible behavior are changed to

  1. Open main.tex. The file subfile.tex is almost completely ignored:

    • It is listed as a child of main.tex in this.extension.manager.cachedContent['main.tex'] lw.cacher.contexts['main.tex'].children
    • An entry this.extension.manager.cachedContent['subfile.tex'] exists lw.cacher.contexts['subfile.tex'] does not exist
    • It is used for build the structure view in the TeX badge
    • Its content is not parsed by parseFileAndSubs cached (equivalent to the previous parseFileAndSubs)
    • The file is not watched. Hence, its content is not used to provide intellisense (eg. references defined in subfile.tex are not available for completion) and (external) changes to the file will not trigger auto build even when set to on file change.
  2. Switch to subfile.tex

    • Saving updates does not its cached content in this.extension.manager.cachedContent['subfile.tex'] create cache in the form lw.cacher.contexts['subfile.tex'], therefore not watched
    • When intellisense.update.aggressive.enabled is set to true, updateCompleter is called and the content of the file becomes available for intellisense. the sub-file is still not watched or cached
    • (NEW!) Saving the file will trigger an auto-build if onSave, but not onFileChanged as it is never watched

To summarize:

I think the current behavior is more understandable. What about I update the description to this config according to the summary and call it a day? @jlelong

jlelong commented 1 year ago

The new behaviour of latex.watch.files.ignore looks much more natural. I agree that updating its description based in the above summary is probably enough to consider that the issue is solved.

drriguz commented 1 year ago

Thanks for the awesome work! :p