Giter Site home page Giter Site logo

Set the variable bibtex-completion-bibliography used by helm-bibtex to the dynamical generated bib files list corresponding to the current master tex file. about helm-bibtex HOT 14 CLOSED

hongyi-zhao avatar hongyi-zhao commented on June 14, 2024
Set the variable bibtex-completion-bibliography used by helm-bibtex to the dynamical generated bib files list corresponding to the current master tex file.

from helm-bibtex.

Comments (14)

hongyi-zhao avatar hongyi-zhao commented on June 14, 2024 1

Hm, no idea why it doesn't work the first time.

The reason is explained here, and the following modifications should be made

(use-package helm-bibtex
  :init
  (setq
   bibtex-completion-pdf-field "File"
   ;;https://github.com/tmalsburg/helm-bibtex#insert-latex-cite-commands
   bibtex-completion-cite-prompt-for-optional-arguments nil)

  :bind-keymap
  ("<menu>" . helm-command-prefix)
  :bind
  (
   :map helm-command-map
   ("b" . helm-bibtex)
   ("B" . helm-bibtex-with-local-bibliography)
   ("n" . helm-bibtex-with-notes)
   ("<menu>" . helm-resume)
   )

  :config
  (require 'helm-config)
  ;;https://github.com/tmalsburg/helm-bibtex#application-used-for-opening-pdfs
  ;;https://github.com/tmalsburg/helm-bibtex/issues/386
  (defun bibtex-completion-open-pdf-external (keys &optional fallback-action)
    (let ((bibtex-completion-pdf-open-function
       (lambda (fpath) (start-process "evince" "*helm-bibtex-evince*"
"/usr/bin/evince" fpath))))
      (bibtex-completion-open-pdf keys fallback-action)))

  (helm-bibtex-helmify-action bibtex-completion-open-pdf-external
helm-bibtex-open-pdf-external)

  (helm-add-action-to-source
   'helm-bibtex
   '(("P" helm-bibtex-open-pdf-external "Open PDF file in external
viewer (if present)")))

  ;;https://github.com/tmalsburg/helm-bibtex#browser-used-for-opening-urls-and-dois
  (setq bibtex-completion-browser-function
    (lambda (url _) (start-process "firefox" "*firefox*" "firefox" url)))

  )

from helm-bibtex.

hongyi-zhao avatar hongyi-zhao commented on June 14, 2024 1
  1. This method works.
  2. In order to print out the bibliography list for testing, the \nocite{*} command should be used as commented here and use the biber command to generate the bibliographies:
\documentclass[]{article}

% for working with biblatex
 \usepackage[backend=biber]{biblatex}
 \addbibresource{references/orbnpg.bib}
 \nocite{*}

\begin{document}

The document.

% for testing biblatex
 \printbibliography[]

% for testing bibtex
%\cite{gahlerCaratInterfaceInterfaceCARAT2022}

% for working with bibtex
%\bibliographystyle{plain}
%\bibliography{references/orbnpg}


\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
  1. I'm not familiar with biblatex, so I adapt the example code to use BibTeX instead of biblatex, and it also works:
\documentclass[]{article}

% for working with biblatex
% \usepackage[backend=biber]{biblatex}
% \addbibresource{references/orbnpg.bib}


\begin{document}

The document.

% for testing biblatex
% \printbibliography[]

% for testing bibtex
\cite{gahlerCaratInterfaceInterfaceCARAT2022}

% for working with bibtex
\bibliographystyle{plain}
\bibliography{references/orbnpg}

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:

Sidenote: Maybe my problem is caused by not enabling the reftex package, as you have pointed out. I now have enabled it according to the guide here:

(require 'reftex) ; Loading RefTeX
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)   ; with AUCTeX LaTeX mode

from helm-bibtex.

tmalsburg avatar tmalsburg commented on June 14, 2024

Please try the command helm-bibtex-with-local-bibliography.

from helm-bibtex.

tmalsburg avatar tmalsburg commented on June 14, 2024

If no local bibliography can be found, this will fall back to the global one (default).

from helm-bibtex.

hongyi-zhao avatar hongyi-zhao commented on June 14, 2024

I have a bib file located in the same director as the master TeX file:

werner@X10DAi:~/Desktop/iucr/latex$ ls orbnpg.bib 
orbnpg.bib

And I have set the following in my master TeX file:

\bibliographystyle{iucr}
% To submit a manuscript, simply provide the corresponding bbl file.
\bibliography{orbnpg}

The helm-bibtex configuration in Emacs init.el is as follows:

(use-package helm-bibtex
  :init
  (setq

   ;; bibtex-completion-bibliography (directory-files-recursively
   ;;  				   (concat (getenv "HOME") "/texmf/bibtex/bib/local") "^[A-Za-z].+.bib$")


   ;;bibtex-completion-library-path (concat (getenv "HOME") "/pdf")
   ;;bibtex-completion-notes-path (concat (getenv "HOME") "/notes")
   bibtex-completion-pdf-field "File"
   ;;https://github.com/tmalsburg/helm-bibtex#insert-latex-cite-commands
   bibtex-completion-cite-prompt-for-optional-arguments nil)

  :bind
  (("<menu>" . helm-command-prefix)
   :map helm-command-map
   ("b" . helm-bibtex)
   ("B" . helm-bibtex-with-local-bibliography)
   ("n" . helm-bibtex-with-notes)
   ("<menu>" . helm-resume))

  :config
  (require 'helm-config)
  ;;https://github.com/tmalsburg/helm-bibtex#application-used-for-opening-pdfs
  ;;https://github.com/tmalsburg/helm-bibtex/issues/386
  (defun bibtex-completion-open-pdf-external (keys &optional fallback-action)
    (let ((bibtex-completion-pdf-open-function
	   (lambda (fpath) (start-process "evince" "*helm-bibtex-evince*" "/usr/bin/evince" fpath))))
      (bibtex-completion-open-pdf keys fallback-action)))

  (helm-bibtex-helmify-action bibtex-completion-open-pdf-external helm-bibtex-open-pdf-external)

  (helm-add-action-to-source
   'helm-bibtex
   '(("P" helm-bibtex-open-pdf-external "Open PDF file in external viewer (if present)")))

  ;;https://github.com/tmalsburg/helm-bibtex#browser-used-for-opening-urls-and-dois
  (setq bibtex-completion-browser-function
	(lambda (url _) (start-process "firefox" "*firefox*" "firefox" url)))

  )

But when I hit "<menu>-B", the local bibliography still cannot be found:

image

from helm-bibtex.

tmalsburg avatar tmalsburg commented on June 14, 2024

Can you please execute the function bibtex-completion-find-local-bibliography in the tex buffer and report the result?

from helm-bibtex.

hongyi-zhao avatar hongyi-zhao commented on June 14, 2024

Now, it works. But I still encounter the following strange problem.

When I first time press <menu>, the following error will be triggered:

image

When I hit "<menu>-B" the second time, it will work:

image

from helm-bibtex.

tmalsburg avatar tmalsburg commented on June 14, 2024

Hm, no idea why it doesn't work the first time.

Sidenote: I see that the display of entries is messed up. Apparently due to the entry numbering. I wasn't aware that helm could be configured to number the entries. Could you please let know which option that is? Perhaps I can find a work-around. Thank you.

from helm-bibtex.

hongyi-zhao avatar hongyi-zhao commented on June 14, 2024

I see that the display of entries is messed up.

What do you mean by saying messed up?

Apparently due to the entry numbering.

I have a lot of configurations in init.el, can you give me some clues to locate the corresponding configuration?

from helm-bibtex.

tmalsburg avatar tmalsburg commented on June 14, 2024

What do you mean by saying messed up?

In your screenshot, each entry occupies two lines, instead of just one. This is because some extra space is used by the numbering. This numbering is not added by helm-bibtex (I never saw it). I assumed that the entry numbering is a helm feature that you activated.

from helm-bibtex.

hongyi-zhao avatar hongyi-zhao commented on June 14, 2024

I have noticed that the helm-bibtex-with-local-bibliography command only try to find the bib file on the top level directory of the master TeX file and doesn't do a recursive search into subdirectories.

Say, if the bib file is set to \bibliography{./refs/orbnpg}, in this case, helm-bibtex-with-local-bibliography can not find this bib file at all.

from helm-bibtex.

tmalsburg avatar tmalsburg commented on June 14, 2024

Detection of the .bib files associated with a .tex file is handled by the reftex package. In my setup, it does succeed at finding .bib files in subdirectories. Example below:

\documentclass[]{article}

\usepackage[backend=biber]{biblatex}
\addbibresource{dir1/test.bib}

\title{The title}
\oneauthor{Myself}
\oneaffiliation{My Affiliation}
\abstract{The abstract}

\begin{document}

The document:

\printbibliography[]

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:

from helm-bibtex.

tmalsburg avatar tmalsburg commented on June 14, 2024

Sidenote: Maybe my problem is caused by not enabling the reftex package,

Hm, helm-bibtex should actually take care of loading reftext. But anyway, good that you got it to work.

from helm-bibtex.

hongyi-zhao avatar hongyi-zhao commented on June 14, 2024

You have a typo here: reftext should be reftex.

from helm-bibtex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.