I am trying to get LaTeX-specific backends for company
to work well with LSP
and LaTeX. My problem is I cannot seem to get all the desired backends to work well together. For example, company-capf
seems to give me completions for \ref{sec:*}
and BIB entries, but then company-dabbrev
or company-ispell
is not completing English words.
I have added a MWE. I have TexLab v2.0 installed for use with LSP.
(eval-when-compile
(require 'package)
(setq package-user-dir (expand-file-name (concat user-emacs-directory "elpa"))
;; Avoid loading packages twice
package-enable-at-startup nil)
(package-initialize)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t))
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(eval-when-compile
(require 'use-package))
(use-package company
:ensure t
:hook (after-init . global-company-mode)
:custom (company-dabbrev-downcase nil) ; Do not downcase returned candidates
:bind (:map company-active-map
("C-n" . company-select-next)
("C-p" . company-select-previous)))
(use-package company-math
:ensure t
:ensure math-symbol-lists
:demand t)
(use-package company-bibtex
:ensure t
:demand t)
(use-package company-reftex
:ensure t
:demand t)
(dolist (hook '(text-mode-hook markdown-mode-hook))
(add-hook hook
(lambda ()
(make-local-variable 'company-backends)
(setq-local company-backends '(company-capf
company-dabbrev
company-abbrev
company-ispell)))))
(dolist (tex-hooks '(latex-mode-hook LaTeX-mode-hook plain-tex-mode-hook))
(add-hook tex-hooks
(lambda ()
(set (make-local-variable 'company-backends) '(company-capf
company-ispell
company-dabbrev
company-bibtex
company-reftex-labels
company-reftex-citations
company-math-symbols-latex
company-latex-commands
company-math-symbols-Unicode
company-abbrev)))))
(use-package lsp-mode
:ensure t
:hook ((latex-mode plain-tex-mode) . lsp-deferred)
:custom (lsp-prefer-capf t))
Here is a simple LaTeX document.
\documentclass[12pt,a4paper]{article}
\usepackage{lipsum}
\begin{document}
\title{Company Test}
\author{Swarnendu Biswas}
\date{}
\maketitle
\section*{Introduction}
\label{sec:intro}
\lipsum
\section*{Methodology}
This is a long paragraph about nothing that makes sense. I do not understand what is going wrong.
\section*{Conclusion}
\label{sec:conc}
The shutdown on cricket in England and Wales will remain until at least 1 July, meaning the postponement of England's Test series against West Indies.
No domestic competitions have been cancelled yet, but the England and Wales Cricket Board (ECB) will meet on Wednesday to discuss the inaugural season of The Hundred, which is due to start on 17 July.
The domestic season, scheduled to start on 12 April, had been delayed until at least 28 May because of coronavirus.
The ECB says it will look to schedule all international cricket between July and the end of September.
England women's limited-overs series against India - scheduled to start on 25 June - has also been postponed.
ECB chief executive Tom Harrison said: "As much as we remain hopeful that we can deliver some cricket this summer, we are in the midst of a worldwide crisis and our priority - over and above the playing of professional sport - will be to protect the vulnerable, key workers and society as a whole.
\end{document}
Please let me know what could be wrong with my setup. Thanks.