SublimeText / LaTeXTools

LaTeX plugin for Sublime Text
https://latextools.readthedocs.io/
2.01k stars 365 forks source link

"No bib files found!" pop-up on `\cite{}` #1084

Open kortschak opened 7 years ago

kortschak commented 7 years ago

Recently (past week or so) LaTeXTools has been popping up the "No bib files found!" error dialog.

Installed version of LaTexTools is v3.13.5. SublimeText 3 Build 3126.

Console:

TEX root: '/path/to/document.tex'
Bib files found: 
[]
error: No bib files found!

Shell:

$ ls /path/to | head -n 1
bibliography.bib
r-stein commented 7 years ago

How do you add the bibliography? Does this also happen after you clear the cache (C-l, C-d, C-c)?

kortschak commented 7 years ago

How do you add the bibliography?

The bibliography is included with \bibliography{bibliography} and the bibliography.bib file is placed in the working directory. This worked until recently (it would be surprising to me for that to not work).

Does this also happen after you clear the cache (C-l, C-d, C-c)?

No change.

r-stein commented 7 years ago

Have you wrapped \bibliography{bibliography} inside an other command? Can you please provide a minimal working example, which produces the error?

kortschak commented 7 years ago

My minimal reproducer is

\begin{document}
\cite{}
\verb|\end{document}|
\bibliography{bibliography}
\end{document}

with a valid bibliography.bib.

Removing the \verb|\end{document}| fixes the problem, so I suspect that the quoted \end{document} is being parsed as \end{document} rather than text.

r-stein commented 7 years ago

Yes you are correct the analysis stops at \end{document} and is not smart enough to detect such cases. You can try to remove that line. Not sure what would be the best to solve this in general.

kortschak commented 7 years ago

That text is only there in placeholder text in my case, so this is not a huge issue. For others, a work around is to replace that with \verb|\|\verb|end{document}|. Ugly, but workable.

Removing that whole condition also fixes the problem. It would seem that erroring in greediness would be better that in the other direction.

r-stein commented 7 years ago

Removing that whole condition also fixes the problem. It would seem that erroring in greediness would be better that in the other direction.

I tend to agree on that.

lrdegeest commented 7 years ago

Similar problem. No .tex files can detect the bibliography one month after it was working fine.

lrdegeest commented 7 years ago

Exhibit A. Path to the .bib file is as it used to be. screen shot 2017-04-27 at 10 54 02 pm

r-stein commented 7 years ago

@lrdegeest Do you also have \end{document} inside a verb inside your document? Otherwise it would also be good, if you good provide a minimal working example.

lrdegeest commented 7 years ago

Negative. MWE:

\begin{document}
Consider the lobster \citep{}
\bibliography{bibfile}
\end{document}
r-stein commented 7 years ago

@lrdegeest Then it is an other bug and it would be nice if you could create a new issue as I can't reproduce it.

lrdegeest commented 7 years ago

Sure, but one last point. The problem is also sensitive to the name of a file. "test.tex" works; "experiment.tex" or "asasdfl.tex" (random letters) do not.

r-stein commented 7 years ago

Can you press C-l, C-d, C-c and then check whether it still doesn't work?

lrdegeest commented 7 years ago

Already tried clearing the cache. No effect.

r-stein commented 7 years ago

Do you have any errors in the console ctrl+`?

lrdegeest commented 7 years ago

Yes:

Running "'' -version"
Traceback (most recent call last):
  File "/Users/LawrenceDeGeest/Library/Application Support/Sublime Text 3/Packages/LaTeXTools/st_preview/preview_utils.py", line 99, in _update_gs_version
    raw_version = check_output([_GS_COMMAND, '-version'])
  File "/Users/LawrenceDeGeest/Library/Application Support/Sublime Text 3/Packages/LaTeXTools/latextools_utils/external_command.py", line 348, in check_output
    show_window=show_window
  File "/Users/LawrenceDeGeest/Library/Application Support/Sublime Text 3/Packages/LaTeXTools/latextools_utils/external_command.py", line 268, in execute_command
    show_window=show_window
  File "/Users/LawrenceDeGeest/Library/Application Support/Sublime Text 3/Packages/LaTeXTools/latextools_utils/external_command.py", line 221, in external_command
    cwd=cwd
  File "./python3.3/subprocess.py", line 819, in __init__
  File "./python3.3/subprocess.py", line 1370, in _execute_child
  File "./python3.3/os.py", line 791, in fsencode
TypeError: expect bytes or str, not NoneType
lrdegeest commented 7 years ago

However, if I rename the file to "test.tex", changing nothing else, it works.

lrdegeest commented 7 years ago

In fact, I am noticing that the problem arises in any tex file if if move it. This should not be a problem because I provide the absolute path to the bibliography, and anyway, it worked perfectly fine before.

r-stein commented 7 years ago

That error is not related to that (and not really problematic).

We have changed things in that completion, because we now use a backward analysis to extract information of the document instead rewritting that feature everywhere (this adds support for the import package). It doesn't seem to support absolute paths.

Can you try to change this line to:

            if not os.path.isabs(res):
                candidate_file = os.path.normpath(os.path.join(rootdir, res))
            else:
                candidate_file = os.path.normpath(res)

You can use PackageResourceViewer to edit the files.

lrdegeest commented 7 years ago

On the contrary, it is quite problematic!

Changing the line in the python file has no effect. For example, I create an empty file called "results.tex" and add a path to the bibliography. Nada:

screen shot 2017-04-28 at 2 10 15 pm

but if I change the file name to "test.tex" (mv results.tex test.tex), suddenly it works:

screen shot 2017-04-28 at 2 10 42 pm

lrdegeest commented 7 years ago

Just to be clear, pdflatex and bibtex still compile a bibliography despite the message "No bib file found."

ig0774 commented 7 years ago

@r-stein wasn't saying the "No bib files" message is problematic. It's the output from the console you showed that indicates a problem finding Ghostscript on your machine, which is completely unrelated to the bibliography problem.

Unfortunately, it's not possible to reproduce the error you're showing from the MWE you provided on my machine, which just indicates that the problem isn't obvious just from the example you provided. Can you be a bit more detailed as to the steps you're taking to produce this issue? You seem to be renaming the file via mv; is this change immediately reflected in ST or do you somehow reopen the file once it's been renamed? Being specific and clear will help us to help you.

ig0774 commented 7 years ago

Sorry, first line should be isn't instead of is.

lrdegeest commented 7 years ago

Thanks a lot for your help. I recreated the problem with a fresh example. I created a directory called "mypaper":

└── mypaper
    ├── conclusion.tex
    ├── intro.tex
    ├── main.tex
    └── results.tex

where the child documents are added to "main.tex" via \input{}.

"main.tex" looks like this:

\begin{document}
Consider the lobster \citep{acheson1988lobster}
\section{Introduction}
\input{intro}
\section{Results}
\input{results}
\section{Conclusion}
\input{conclusion}
\bibliographystyle{chicago}
\bibliography{/Users/LawrenceDeGeest/Desktop/notebook/references}
\end{document}

and "intro.tex" looks like this:

%\bibliography{/Users/LawrenceDeGeest/Desktop/notebook/references}

Consider the lobster \citep{}

I add the commented-out references file at the top so I can use the wonderful auto-fill feature when typing \citep{}. However, this now produces the "no bib file found" message. Strange because it used to work just fine.

Stranger yet is that copy-pasting a working file to a new, empty file in a new, empty directory causes it to break. Suppose I create a new directory called "mypaper2" and add a blank "main.tex" file, then copy the contents from mypaper/main.tex to mypaper2/main.tex. This should be fine, but instead it leads to an error.

Some more detail. I have this tree:

├── mypaper
│   └── main.tex
└── mypaper2
    └── main.tex

Here is the output from ctr+' on mypaper/main.tex:

TEX root: '/Users/LawrenceDeGeest/Desktop/notebook/latex_sandbox/sublime/mypaper/main.tex'
Bib files found: 
('/Users/LawrenceDeGeest/Desktop/notebook/references.bib',)

and here is the output on mypaper2/main.tex:

Exception KeyError: KeyError('/Users/LawrenceDeGeest/Desktop/notebook/latex_sandbox/sublime/mypaper2/main.tex',) in <bound method LocalCache.__del__ of <LaTeXTools.latextools_utils.cache.LocalCache object at 0x10c33d050>> ignored
Exception KeyError: KeyError('/Users/LawrenceDeGeest/Desktop/notebook/latex_sandbox/sublime/mypaper2/main.tex',) in <bound method LocalCache.__del__ of <LaTeXTools.latextools_utils.cache.LocalCache object at 0x10c33dad0>> ignored
TEX root: '/Users/LawrenceDeGeest/Desktop/notebook/latex_sandbox/sublime/mypaper2/main.tex'
Bib files found: 
()
error: No bib files found!
Exception KeyError: KeyError('/Users/LawrenceDeGeest/Desktop/notebook/latex_sandbox/sublime/mypaper2/main.tex',) in <bound method LocalCache.__del__ of <LaTeXTools.latextools_utils.cache.LocalCache object at 0x10c2dc1d0>> ignored

All these files compile accordingly with references included, whether I build from Sublime or from the command line.

r-stein commented 7 years ago

and "intro.tex" looks like this:

%\bibliography{/Users/LawrenceDeGeest/Desktop/notebook/references}
Consider the lobster \citep{}

Writing \bibliography inside comments is not supported anymore. The recommended way is to write % !TEX root = main.tex at the top of each included document. We may also provide a way to add some meta information in the comments.

The other seems to be a bug, if the same bibliography is used by two documents. We will have a look at this.

lrdegeest commented 7 years ago

Ok, thank you.

KTGLeiden commented 7 years ago

Just to let you know, I have the same issues with the latest Git version. Renaming the document to test.tex works great. Thanks for the fix and for looking into this.

superjax commented 7 years ago

I can confirm the same behavior on my machine. Renaming the document to test.tex fixed it.

brainbug89 commented 7 years ago

I have the same problem. I getting the "No bib files found!" pop-up when trying to use \cite{} Here is the output from the console on zusammenfassung.tex:

TEX root: 'D:\\privat\\xxx\\xxx\\xxx\\xxx\\xxx\\xxx\\version06\\contents\\zusammenfassung.tex'
Bib files found: 
[]
error: No bib files found!

The TEX root is wrong. Looks like the "TEXroot": "main.tex", setting at the .sublime-project suddenly doesn't work anymore. (btw \cite{} works fine at main.tex)

lrdegeest commented 7 years ago

Now bibliography commands like \citep{} no longer brings up the list of references in the attached .bib file. This used to work fine days ago. Nothing changed on my end. This is getting quite frustrating. Is there any news with this?

r-stein commented 7 years ago

try to press C-l,C-backspace

lrdegeest commented 7 years ago

No effect.

Also, I am getting the same "no bib files found!" pop-up on a beamer presentation. There is just one .tex file and the bibliography compiles fine.

lrdegeest commented 7 years ago

Oh, I forgot to mention that like before, re-naming the file to "test.tex" resolves the pop-up issue. Very bizarre.

r-stein commented 7 years ago

Not sure what's the issue. You can try to open the ST console and paste import os; os.startfile(sublime.cache_path() + "/LaTeXTools") this should open the cache folder. Just delete the local_cache folder and the files, which are called like tradbib_XXXX or new_XXX. Afterwards restart ST.

lrdegeest commented 7 years ago

But the bug persists even if I remove the package altogether and re-install. Other users are pointing out that renaming files to "test.tex" resolves the issue for them too.

r-stein commented 7 years ago

Reinstalling the package doesn't clear the cache. Not sure about the renaming it think it just clears the cache by using a different file path. We had the last update 12 days ago and did not change the cache in it, but we may just invalidate all old cache files in the next one.

lrdegeest commented 7 years ago

Renaming the file to "test.tex" really appears to be the only solution so far. Clearing cache has no effect. Do you have any insight at all as to why?

r-stein commented 7 years ago

Have you manually deleted those files? We don't have a special meaning for a file with the name "test.tex", but use the md5sum of the file path to identify the caches. I think it's more about renaming then about the file name.

r-stein commented 7 years ago

@lrdegeest I have relased a prerelease, which slighty improves error handlings of the cache and adds a LaTeXTools: Clear Cache command, which superseeds the other clear cache commands and removes all cache files. It does not fix the underlaying issues, but you may try that if you still have the problems.

ntvy95 commented 7 years ago

@r-stein I have met the same problem as lrdegeest. I installed the prerelease version but I could not find the Clear Cache command? Renaming the file to "test.tex" does the trick, and it turns out that it is the only name that works.

larkinlheintzman commented 7 years ago

@r-stein clearing the cache, via the Clear Cache command worked for me! Thanks for the fix.

RAXYAO commented 7 years ago

Clearing the cache and renaming the file both work for me.

TaylanT commented 7 years ago

Hey guys, same problem here. My .bib file is in the same directory as my main.tex. Cache and document cache is cleared. The \bibliographycommand is called from a separate file (.sty - File) . % !TEX root = ../my-thesis.tex is included in the page header renaming the file did not work for me. Unfortunately Sublime / LatexTools still gives me the popup "No bib files found!" .

@r-stein is there a problem when \bibliography is called from somewhere else besides the main.tex?

r-stein commented 7 years ago

@TaylanT Calling \bibliography should behave the same no matter from where you call. We rely on a document-wide analysis, which is independent of the currently opened file. You may add .sty to your "tex_file_exts" though.

Bankimchandrayadav commented 7 years ago

Solution for Sublime Text 3

It generally appears when working in a structure where main file is kept in one folder while child documents are kept in a subfolder

    -  directory
    -   main.tex
    -   (subdirectory)chapters
    -   (subdirectory)images

Individual chapters files are kept in chapters subdirectory.

Solution

The above three changes can guarantee the solution with 90% probability.

babesyoung commented 7 years ago

thx "% !TEX root = ***.tex" works for me

bbercovici commented 6 years ago

I've been running into the same problem today: C-B was compiling a document along with its bibliography fine, but the autocomplete of \cite{ was sometimes failing with a "No bib file found" error message, depending upon the document. The bibliography was loaded in using its absolute path.

I could not understand why some of my documents were working fine, while others were not. After some fiddling, I can confirm that the master document's name matters. "poster.tex" does not let me use autocomplete within Sublime Text, but renaming it "postera.tex" does the trick. Modifying it back to "poster.tex" brings the error back. o_O

r-stein commented 6 years ago

If changing the document name helps try to press ctrl+shift+p and execute LaTeXTools: Clear Cache

jorgeam11 commented 6 years ago

I've had same issue with everything working fine except for the \cite{} command giving me "No bib file found". Doing the LaTeXTools: Clear Cache fixed the problem instantly thanks!