Created
October 28, 2019 18:08
-
-
Save antoine-levitt/cf61b3a5ce6bc4a8d52b4f7c3b3cf69a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'latex nil t) | |
;; Math insertion in julia. Use it with | |
(defun julia-math-insert (s) | |
"Inserts math symbol given by `s'" | |
(when s | |
(let ((sym (gethash (concat "\\" s) julia-latexsubs))) | |
(when sym | |
(insert sym))))) | |
;; unicode insertion of math symbols | |
(define-minor-mode julia-math-mode | |
"A minor mode with easy access to TeX math commands. The | |
command is only entered if it is supported in Julia. The | |
following commands are defined: | |
\\{LaTeX-math-mode-map}" | |
nil nil (list (cons (LaTeX-math-abbrev-prefix) LaTeX-math-keymap)) | |
(if julia-math-mode | |
(set (make-local-variable 'LaTeX-math-insert-function) 'julia-math-insert))) | |
(define-globalized-minor-mode global-math-mode julia-math-mode | |
(lambda () | |
(unless (eq major-mode 'latex-mode) | |
(julia-math-mode)))) | |
(global-math-mode 1) | |
;; (add-hook 'julia-mode-hook 'julia-math-mode) | |
;; (add-hook 'inferior-julia-mode-hook 'julia-math-mode) | |
;; (add-hook 'inferior-ess-mode-hook 'julia-math-mode) | |
;; (add-hook 'message-mode-hook 'julia-math-mode) | |
;; Make math insertion work in isearch | |
(add-hook 'isearch-mode-hook 'isearch-setup-latex-math) | |
(add-hook 'isearch-mode-end-hook 'isearch-unsetup-latex-math) | |
(define-key isearch-mode-map (LaTeX-math-abbrev-prefix) LaTeX-math-keymap) | |
(defun isearch-setup-latex-math () | |
(when (eq (current-mm) 'latex-mode) | |
(set (make-local-variable 'LaTeX-math-insert-function) (lambda (s) (isearch-process-search-string (concat "\\" s) (concat "\\" s))))) | |
(when (eq (current-mm) 'ess-julia-mode) | |
(set (make-local-variable 'LaTeX-math-insert-function) (lambda (s) (isearch-process-search-string (gethash (concat "\\" s) julia-latexsubs) (gethash (concat "\\" s) julia-latexsubs))))) | |
(when (eq (current-mm) 'julia-mode) | |
(set (make-local-variable 'LaTeX-math-insert-function) (lambda (s) (isearch-process-search-string (gethash (concat "\\" s) julia-latexsubs) (gethash (concat "\\" s) julia-latexsubs))))) | |
) | |
(defun isearch-unsetup-latex-math () | |
(when (eq (current-mm) 'latex-mode) | |
(set (make-local-variable 'LaTeX-math-insert-function) 'TeX-insert-macro)) | |
(when (eq (current-mm) 'ess-julia-mode) | |
(set (make-local-variable 'LaTeX-math-insert-function) 'julia-math-insert)) | |
(when (eq (current-mm) 'julia-mode) | |
(set (make-local-variable 'LaTeX-math-insert-function) 'julia-math-insert))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment