On Wed, May 3, 2023 at 8:08 AM Hongyi Zhao <hongyi.z...@gmail.com> wrote:
>
> On Wed, May 3, 2023 at 1:55 AM Mandar Mitra <mandar.mi...@gmail.com> wrote:
> >
> > Hongyi Zhao wrote (Tue, May 02, 2023 at 10:03:23PM +0800):
> > > The example setting of this variable is as follows:
> > >
> > > (setq bibtex-completion-bibliography (directory-files-recursively
> > >                         (concat (getenv "HOME")
> > > "/texmf/bibtex/bib/local") "^[A-Za-z].+.bib$"))
> > >
> > > But the above setup uses a fixed directory, so it doesn't meet the
> > > requirements here. Any suggestions for achieving the goal will be
> > > appreciated.
> >
> > Random suggestion: in LaTeX-mode-hook
> >
> > (setq (make-local-variable 'bibtex-completion-bibliography)
> >       (lisp-expression-to-create-the-list-of-files-that-you-want))
> >
> > Disclaimer: not sure this will work, not sure it's the "right" way to 
> > achieve what you want, just something for you to try before the experts 
> > chime in.
>
> I have some preliminary ideas as follows:
>
> First, define `my-bibtex-completion-bibliography` function to search
> for bib files in, e.g., the `bibs` subdirectory of the current master
> TeX file directory; then set `bibtex-completion-bibliography` to the
> result of calling this function.
>
> ```emacs-lisp
> (defun my-bibtex-completion-bibliography ()
>   "Return a list of bib files in the 'bibs' subdirectory of the
> current master tex file directory."
>   (let ((master-file (buffer-file-name))
>         (bibs-dir (concat (file-name-directory (buffer-file-name)) "bibs/")))
>     (directory-files-recursively bibs-dir "^[A-Za-z].+.bib$")))
>
> (setq bibtex-completion-bibliography (my-bibtex-completion-bibliography))
> ```
>
> This function first gets the filename of the current master TeX file
> (`master-file`) and constructs the path to the `bibs` subdirectory
> using `concat`. It then returns a list of bib files in that directory
> using `directory-files-recursively`.
>
> Any corrections/comments will be appreciated.

In fact, helm-bibtex already has a built-in function, aka,
`helm-bibtex-with-local-bibliography`, which provides this feature.
See https://github.com/tmalsburg/helm-bibtex/issues/429 for more
detailed discussion.

> > -mandar
>
> Zhao

Reply via email to