Latex-Completitions in Emacs

In an old discussion, tpapp suggested company-math:

https://www.emacswiki.org/emacs/company-math

However, for the life of me, I cannot get it to work.
I am new to emacs, so I don’t really know what I am doing. But I tried a few different permutations like:

(add-hook 'after-init-hook 'global-company-mode)
(with-eval-after-load 'company
  (add-to-list 'company-backends 'company-math-symbols-unicode 'company-latex-commands))

OR

(defun my-julia-mode-setup ()
  (setq-local company-backends
              (append '((company-math-symbols-unicode))
                      company-backends)))
(add-hook 'julia-mode-hook 'my-julia-mode-setup)

based on what I’ve read online.
I do not have a mental model of what is going on.

I can confirm that company-mode is on with M-x company-mode. I also tried to check the variables with M-x customize-variable RET company-backends, and see that the end of the list says
User defined: company-math-symbols-unicode
where company-math-symbols-unicode is in a text-box.

However, there does not seem to be any sort of auto-completion. For example, typing \alpha and then hitting [TAB] does nothing at all.

What am I missing?

The relevant code snippets from my .init.el are

(defun setup-unicode ()
  "Unicode input for the buffer."
  (interactive)
  (company-mode)                        ; using company-mode
  (setq-local company-backends '(company-math-symbols-unicode))
  (setq-local company-minimum-prefix-length 1)
  (setq-local company-idle-delay 0))

and then I call (setup-unicode) in the Julia setup. But I can also test and use it separately.

Are you using ESS or the standalone julia-mode?

1 Like

I use
(add-hook 'julia-mode-hook 'julia-math-mode)
(add-hook 'inferior-julia-mode-hook 'julia-math-mode)

to insert Unicode math just like in latex, I find it extremely convenient.

1 Like

I am using ESS with julia-mode.

I did try julia-repl, but had an issue with extra close-brackets appearing when I send text from the editor to the REPL with C-RET or C-c C-c. That is, x = [i for i in 1:4] would send x = [i for i in 1:4]] to the REPL, which throws an error.
I didn’t file an issue because I’m not sure where the problem is. It might be related to OhMyREPL. I may try removing that line from my startup.jl and retrying julia-repl later.
Commenting here in case that is a known issue.

I use
(add-hook 'julia-mode-hook 'julia-math-mode)
(add-hook 'inferior-julia-mode-hook 'julia-math-mode)

to insert Unicode math just like in latex, I find it extremely convenient.

Does julia-mode provide julia-math-mode?

Does julia-mode provide julia-math-mode?

Yes, I added it in Insertion of math symbols in julia using auctex's mechanism by antoine-levitt · Pull Request #42 · JuliaEditorSupport/julia-emacs · GitHub by simply reusing auctex’s machinery (isn’t emacs wonderful?). It’s very convenient if you’re used to typing latex: you type “`” (or whatever character you want: I use ù because that’s easily accessible on a french keyboard and not frequently used in code) then “a” and it inserts \alpha (in latex mode) or α (in julia mode). I actually like it so much that I use it for every mode (eg email or note taking), like so:

(define-globalized-minor-mode global-math-mode julia-math-mode
  (lambda ()
    (unless (eq major-mode 'latex-mode)
      (julia-math-mode))))
(global-math-mode 1)
2 Likes

I made a PR cleaning up the LaTeX substitutions a bit, bringing it up to date with 1.0:

https://github.com/JuliaEditorSupport/julia-emacs/pull/67

1 Like