textmate / latex.tmbundle

TextMate support for LaTeX
97 stars 64 forks source link

Failure running "Citation Based on Current Word..." #125

Closed alfureu closed 9 years ago

alfureu commented 9 years ago

Hi, after updating the bundle I am getting this error when asking for bib autocomplete:

/Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:627:in `exist?': can't convert Array into String (TypeError)
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:627:in `file?'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:332:in `bib_entries'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:304:in `parse_bibfile'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:808:in `add_bibliography_scan'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:805:in `each'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:805:in `add_bibliography_scan'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:828:in `call'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:828:in `extractors_process_line'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:827:in `each'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:827:in `extractors_process_line'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:826:in `each_pair'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:826:in `extractors_process_line'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:710:in `recursive_scan'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:708:in `each_pair'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:708:in `recursive_scan'
    from Citation Based on Current Word…:5:in `each_with_index'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:707:in `each'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:707:in `each_with_index'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:707:in `recursive_scan'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:820:in `inlcude_process_line'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:817:in `each'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:817:in `inlcude_process_line'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:815:in `each'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:815:in `inlcude_process_line'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:709:in `recursive_scan'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:708:in `each_pair'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:708:in `recursive_scan'
    from Citation Based on Current Word…:5:in `each_with_index'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:707:in `each'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:707:in `each_with_index'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:707:in `recursive_scan'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:784:in `cite_scan'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/latex.rb:159:in `citations'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/command.rb:235:in `citations'
    from /Users/N/Library/Application Support/TextMate/Managed/Bundles/LaTeX.tmbundle/Support/lib/command.rb:246:in `insert_citation'
    from Citation Based on Current Word…:9```
sanssecours commented 9 years ago

Hi DOFfactory,

thanks for the bug report. This issue might be the result of a non-existent bibliography file. If that is indeed the case, then commit 0532e59d should fix your issue.

Could you please prove a (minimal) example project that shows this behaviour?

Kind regards, René

alfureu commented 9 years ago

Hi Rene, thanks for the reply, I changed the latex.rb file to the commit mentioned. Now the error shows "Could not locate any file named Bibliography". You are right, it seems TextMate 2 cannot locate the bib file.

However I have a %!TEX root defined in the particular file, the path is correct. Also I did not change the BIBINPUTS variable in TextMate. I noticed in the changelogs and issues that there have been some updates to the citations, but could not figure it out why my previously working project cannot locate the bib file anymore. It is still there on its original location (in the project folder) ... Any ideas?

sanssecours commented 9 years ago

Ok, I noticed in the latex.rb file that it does not look for BIBINPUTS variable anymore, but a new variable has been introduced like TM_LATEX_BIB. Am I correct? What is the syntax expected in this?

As far as I know BIBINPUTS was never (directly) used in the citation completion code. BIBINPUTS might be read by kpsewhich though. Maybe I introduced a bug in the code that searches for files via kpsewhich. It would be super nice of you if you could provide steps to reproduce your problem.

... but a new variable has been introduced like TM_LATEX_BIB. Am I correct?

TM_LATEX_BIB was also used in the “old” code — see commit 59191ffc.

What is the syntax expected in this?

According to the code you can specify the path to an (additional) bib file in this variable.

alfureu commented 9 years ago

Hi Rene,

thanks for your reply. Unfortunately I cannot produce now easily a test-environment, I am in the middle of doing something else.

In short, I am using the classicthesis folder structure:

classicthesis.tex – master file bibliography.bib chapters\chapter1.tex chapters\chapter2.tex frontbackmatter\bibliography.tex

In the classicthesis.tex I am calling the bib file through bibliography.tex, and the chapters. So far, when I was writing a chapter, and I needed a reference from the bib, I hit alt+esc and TextMate autocompleted the reference. This is now broken.

I tried using the TM_LATEX_BIB instead of BIBINPUTS, but no luck, the same error. I had it set up on folder paths, but even defining the specific file does not help.

IMHO the latex.rb somehow fails to follow-up on the call of the bib file in bibliography.tex that is called then again in the master file.

sanssecours commented 9 years ago

I used the folder structure you provided and created classicthesis.tex with the following content:

\documentclass{report}
\begin{document}
\input{chapters/chapter1}
\input{chapters/chapter2}
\input{frontbackmatter/bibliography}
\end{document}

The file bibliography.bib contains the following code:

%% This BibTeX bibliography file was created using BibDesk.
%% http://bibdesk.sourceforge.net/

%% Created for René Schwaiger at 2015-04-20 19:35:21 +0200 

%% Saved with string encoding Unicode (UTF-8) 

@electronic{citekey,
    Author = {Mr. Author},
    Date-Added = {2015-04-20 17:34:08 +0000},
    Date-Modified = {2015-04-20 17:35:02 +0000},
    Title = {Mrs. Title}}

chapter1.tex and chapter2.tex both contain the following:

%!TEX root = ../classicthesis.tex

Chapter~

bibliography.tex is a tex file with the following content:

\bibliographystyle{alpha}
\bibliography{bibliography}

If I invoke use “Insert Citation” in the file chapter1.tex after ~, then TextMate correctly inserts the following code \cite{citekey}.

I tried using the TM_LATEX_BIB instead of BIBINPUTS, but no luck, the same error. I had it set up on folder paths, but even defining the specific file does not help.

Could you please specify what you used as value for BIBINPUTS? Is there a reason why you set this variable explicitly?

alfureu commented 9 years ago

Hi Rene,

Thanks for creating this. I have everything exactly the same, except I did not have the \addbibresource{bibliography.bib} defined.

My BIBINPUTS look the following: /Users/N/Documents:/Users/N/Dropbox/PhD:. I set this variable ages ago (times of TextMate 1), and it always worked, so there was no need to change.

I tried to set the same for TM_LATEX_BIB, tried removing the colon, removed the full stop at the end, tried defining the full path to the file, nothing worked. It seems TextMate recognises the path set by the variable, but the script cannot find the file :-/

alfureu commented 9 years ago

One more thing. If I do not trigger the alt+esc buttons within the \cite{} command, but instead I select under Bundles > Select Bundle Item > Action: BibDesk Completion, this method works. Though I liked the autocomplete trigger more, instead of opening a new window.

sanssecours commented 9 years ago

I have everything exactly the same, except I did not have the \addbibresource{bibliography.bib} defined.

The \addbibresource{bibliography.bib} was actually left from my first try to reproduce the error. I corrected the above to my current version of the sample project. Does the code from the sample project work for you?

My BIBINPUTS look the following: /Users/N/Documents:/Users/N/Dropbox/PhD:. I set this variable ages ago (times of TextMate 1), and it always worked, so there was no need to change.

latex.rb should actually never (directly or indirectly) use the content of this variable if you use the folder structure you specified above, since bibliography.bib is in the same folder as the master file.

sanssecours commented 9 years ago

It also works for me if I move the bibliography file into ~/Documents (~ = /Users/rene = $HOME) and set BIBINPUTS to $HOME/Documents:$HOME/Dropbox/:.:

variables

Could you please recheck the value of BIBINPUTS:

  1. Open a new document
  2. Paste the following into the document: echo $BIBINPUTS
  3. Press ^R while your caret is in the line where you pasted the code
  4. The content of the file should now include the path specified in BIBINPUTS e.g.:
echo $BIBINPUTS
/Users/rene/Documents:/Users/rene/Dropbox/:.
alfureu commented 9 years ago

Ok, I recreated a dummy folder structure, as described above in your example and it worked. I was testing until now, when I think I found the bug.

Again, the example above, with the following file structure:

classicthesis.tex – master file bibliography.bib chapters\chapter1.tex chapters\chapter2.tex frontbackmatter\bibliography.tex

Now the content of the frontbackmatter\bibliography.tex is the following:

\bibliographystyle{alpha}
\bibliography{bibliography}

... and as a result everything works.

However, if the content of the frontbackmatter\bibliography.tex contains an even commented-out bibliography command, then it fails to load, e.g.:

\bibliographystyle{alpha}
\bibliography{bibliography}
% \bibliography{dummy}

... and it says "Could not locate any file named dummy".

Voila.

sanssecours commented 9 years ago

Hi DOFfactory,

thanks for taking the time to recreate the buggy example code! Commit d1311b86 fixes the issue. The official bundle will be updated when Michael (infininight) or Allan (sorbits) have time to push out the changes.

Kind regards, René

infininight commented 9 years ago

Deployed