Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some commands, say, \bra, can't be completed in math mode, while they can be completed in normal literal typesetting mode. #19

Open
hongyi-zhao opened this issue Jun 25, 2021 · 5 comments

Comments

@hongyi-zhao
Copy link

The testing configuration:

(use-package lsp-mode
 :hook
 (TeX-mode . lsp)
 :custom (lsp-prefer-capf t))

(use-package lsp-latex
  :straight (:host github :repo "ROCKTAKEY/lsp-latex"))

(use-package company
  :hook
  (TeX-mode . company-mode)
  :custom
  ;https://github.com/company-mode/company-mode/issues/14#issuecomment-290261406
  ; Do not downcase the returned candidates automatically
  (company-dabbrev-downcase nil) 
  (company-idle-delay 0) 
  (company-minimum-prefix-length 1))

(use-package company-math)
(use-package math-symbol-lists)
(use-package ac-math)
(use-package company-auctex)

;;https://www.emacswiki.org/emacs/company-math
(defun my-latex-mode-setup ()
  (setq-local company-math-allow-unicode-symbols-in-faces (quote (tex-math font-latex-math-face)))
  (setq-local company-math-disallow-unicode-symbols-in-faces nil)
  (setq-local company-math-allow-latex-symbols-in-faces nil)
;  (setq-local company-backends
;               (append '((company-math-symbols-latex company-math-symbols-unicode company-auctex-macros company-auctex-environments))
;                      company-backends)))

  (setq-local company-backends
               (append '((company-math-symbols-latex company-math-symbols-unicode company-auctex-environments 
                          company-auctex-macros company-capf company-ispell company-latex-commands
                          company-abbrev company-bbdb company-dabbrev-code company-dabbrev
                          company-files company-keywords company-semantic
                         ))
                      company-backends
                      )))
(add-hook 'LaTeX-mode-hook 'my-latex-mode-setup)

image
image

Obviously, this is not the desired result.

Any hints for this problem?

Regards,
HY

@hongyi-zhao hongyi-zhao changed the title The unicode symbol will be input into the tex document instead of the corresponding latex command. The unicode symbol will be inserted into the tex source document instead of the corresponding latex command. Jun 25, 2021
@hongyi-zhao
Copy link
Author

hongyi-zhao commented Jun 25, 2021

Comment out the following two lines in the above configuration seems to solve this problem:

  (setq-local company-math-disallow-unicode-symbols-in-faces nil)
  (setq-local company-math-allow-latex-symbols-in-faces nil)

But some commands, say, \bra, can't be completed in math mode:
image
While they can be completed in text mode:
image

@hongyi-zhao hongyi-zhao changed the title The unicode symbol will be inserted into the tex source document instead of the corresponding latex command. Some commands, say, \href, \bra, and so on, can't be completed in math mode, while then can be completed in normal literal typesetting mode. Jun 25, 2021
@hongyi-zhao hongyi-zhao changed the title Some commands, say, \href, \bra, and so on, can't be completed in math mode, while then can be completed in normal literal typesetting mode. Some commands, say, \href, \bra, and so on, can't be completed in math mode, while then can be completed in normal literal typesetting mode. Jun 25, 2021
@hongyi-zhao hongyi-zhao changed the title Some commands, say, \href, \bra, and so on, can't be completed in math mode, while then can be completed in normal literal typesetting mode. Some commands, say, \bra, and so on, can't be completed in math mode, while then can be completed in normal literal typesetting mode. Jun 25, 2021
@hongyi-zhao hongyi-zhao changed the title Some commands, say, \bra, and so on, can't be completed in math mode, while then can be completed in normal literal typesetting mode. Some commands, say, \bra, can't be completed in math mode, while then can be completed in normal literal typesetting mode. Jun 25, 2021
@hongyi-zhao hongyi-zhao changed the title Some commands, say, \bra, can't be completed in math mode, while then can be completed in normal literal typesetting mode. Some commands, say, \bra, can't be completed in math mode, while they can be completed in normal literal typesetting mode. Jun 25, 2021
@vspinu
Copy link
Owner

vspinu commented Jun 25, 2021

     (append '((company-math-symbols-latex company-math-symbols-unicode company-auctex-environments 
                          company-auctex-macros company-capf company-ispell company-latex-commands
                          company-abbrev company-bbdb company-dabbrev-code company-dabbrev
                          company-files company-keywords company-semantic
                         ))

This doens't seem right to me, but if it works for you ok. All those backends are triggered simultaneously. The point of company backends is that if the first ones don't find it, the following ones are triggered. company-math backends start with \ prefix, if there is no prefix they are not triggered.

But some commands, say, \bra, can't be completed in math mode:

Bra completion is not comming form company math. Probably from company-capf which triggers auctex completion and it looks in braket.sty file (just a guess). So it's not a company-math issue.

Comment out the following two lines in the above configuration seems to solve this problem:

Yes, you need to look at company-math custom variables and configure as you see fit.

@hongyi-zhao
Copy link
Author

This doens't seem right to me, but if it works for you ok.

What's your working configuration?

@vspinu
Copy link
Owner

vspinu commented Jun 25, 2021

I do (add-to-list 'company-backends 'company-math-symbols-unicode) globally and

(setq-local company-backends
                (append '((company-math-symbols-latex
						   company-latex-commands))
                        company-backends))

In latex mode.

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Jun 25, 2021

If you want the normal human writing completion, the following backend should be appended to the list too:

company-ispell

But even so, there are still many commands that cannot be completed., as I've described here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants