I am writing on a large LaTeX Document using Emacs with AUCTeX, RefTeX and Company for autocompletion. RefTeX for citations is working fine and finds my bibliography entries really fast. However, when company searches for labels it has to scan every file used in the project, this takes several seconds and is done every time I move the point in a \ref{} command. Also while scanning for files, I cannot make additional keyboard input, making me wait until scanning is finished every time. Here is the relevant part of my Emacs configuration:

;; Company -> Autocomplete

(use-package company
  (setq company-idle-delay 0
        company-minimum-prefix-length 4
        company-selection-wrap-around t)
  (("C-<tab>" . company-complete))

(global-company-mode t)

(use-package company-math :ensure t)
(use-package company-reftex :ensure t)
(use-package company-bibtex :ensure t)

(use-package math-symbol-lists)
(use-package company-math :ensure t)
(use-package company-reftex :ensure t)
(use-package company-bibtex :ensure t)  

(add-hook 'LaTeX-mode-hook
       (make-local-variable 'company-backends)
       (setq company-backends
                         (append '((:separate company-reftex-citations
       (setq company-backends
                         (append '((:separate company-math-symbols-latex

;; LaTeX

(setq-default TeX-output-dir "build")
(setq-default TeX-master nil)

;; RefTex
(add-hook 'LaTeX-mode-hook 'turn-on-reftex) ; Enable RefTex in AUCTex Latex mode
(add-hook 'latex-mode-hook 'turn-on-reftex) ; Enable RefTex in Emacs Latex mode

;; Enable LaTeX Preview Pane
;(add-hook 'LaTeX-mode-hook 'latex-preview-pane-mode)
;(add-hook 'latex-mode-hook 'latex-preview-pane-mode)

(setq-default reftex-plug-into-AUCTeX t)
(setq-default reftex-default-bibliography '("./bibliography/Masterthesis.bib"))
(setq-default reftex-bibliography-commands '("bibliography" "nobibliography" "addbibresource"))
(setq reftex-use-external-file-finders t)
(setq reftex-external-file-finders
      '(("tex". "kpsewhich -format=.tex %f")
                ("bib". "kpsewhich -format=.bib %f")))

Can I speed up the company process for scanning labels? Or is this there at least a way to disable the automatic scanning?

I am new to Emacs and think my problem might result from a faulty configuration.

  • 1
    I think the culprit is github.com/TheBB/company-reftex/commit/…. If you revert this change in company-reftex.el and recompile the file with emacs-lisp-byte-compile you should be fine. The drawback is that you need to run reftex-parse-all manually when needed. You could also run reftex-parse-all once and afterwards watch the input files for changes. But that is more complicated.
    – Tobias
    Sep 22, 2022 at 8:21
  • See also github.com/TheBB/company-reftex/issues/11. They already suspected that the change could cause some performance penalty. A shame that they didn't didn't put reftex-parse-all into a customizable hook such that it could be optionally removed or replaced by something better.
    – Tobias
    Sep 22, 2022 at 8:37
  • We are discussing making reftex-parse-all in company-reftex-label-candidates optional. Could you please check whether my suggestion, removing reftex-parse-all in company-reftex-label-candidates, solves your problem and report back afterwards? Thanks in advance. You could also participate there: github.com/TheBB/company-reftex/issues/11
    – Tobias
    Sep 26, 2022 at 4:57
  • Hello Tobias, thank you for your answers! I looked at the issue and I think you might be correct. Sadly, I will not be able to test your suggestion until next tuesday. But I will test it as soon as I can and answer here again! If this helps I will also tune in on the Github Issue.
    – ls.ptr
    Sep 27, 2022 at 6:57
  • github.com/atreyasha added an option company-reftex-labels-parse-all which can be set to nil. That change is still only in a pull request. Please test this planned changeset by temporarily replacing reftex-parse-all with reftex-parse-one in company-reftex-label-candidates. Please report the results of this test here or at github.com/TheBB/company-reftex/pull/13 Thank you in advance.
    – Tobias
    Oct 2, 2022 at 6:42

1 Answer 1


I think my question has been answered successfully. There has been no answers but comments to my question; so I thought to answer it myself and point other readers at the solution. If a mod can edit this or explain the best way to answer/mark this question, I would be happy to do so.

The performance problem was caused by the function call (reftex-parse-all) inside company-reftex-label-candidates, which gets called as soon as a \ref{} command is entered. There is a pull request on GitHub, which solves this problem. It is currently discussed whether a customizable hook should be added in order to change the parsing behavior easier. This can be found here.

Special thanks to Tobias, who pointed me towards the pull request and effectively solved my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.