How to make this configuration file work with use-package
with regard to AucTeX
, RefTeX
and LaTeX
. I usually write latex rahter than pure tex documents.
Current Working Emacs Configuration
(load "auctex.el" nil t t)
(setq-default TeX-master nil) ; by each new fie AUCTEX will ask for a master fie.
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-PDF-mode t)
(setq TeX-show-compilation nil) ; if `t`, automatically shows compilation log
;; (setq-default TeX-engine 'xetex) ; optional
(setq TeX-save-query nil) ; don't prompt for saving the .tex file
;; add makeglossaries to TeX-run-command-list
(eval-after-load "tex" '(add-to-list 'TeX-command-list
'("Makeglossaries" "makeglossaries %s" TeX-run-command nil
(latex-mode)
:help "Run makeglossaries script, which will choose xindy or makeindex") t))
;; Font-lock for AUCTeX
;; Note: '«' and '»' is by pressing 'C-x 8 <' and 'C-x 8 >', respectively
(font-lock-add-keywords 'latex-mode (list (list "\\(«\\(.+?\\|\n\\)\\)\\(+?\\)\\(»\\)" '(1 'font-latex-string-face t) '(2 'font-latex-string-face t) '(3 'font-latex-string-face t))))
;; Add standard Sweave file extensions to the list of files recognized by AUCTeX.
(setq TeX-file-extensions
'("Rnw" "rnw" "Snw" "snw" "tex" "sty" "cls" "ltx" "texi" "texinfo" "dtx"))
(setq LaTeX-babel-hyphen nil) ; Disable language-specific hyphen insertion.
;; `"` expands into csquotes macros (for this to work babel must be loaded after csquotes).
(setq LaTeX-csquotes-close-quote "}"
LaTeX-csquotes-open-quote "\\enquote{")
;; RefTeX
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(setq reftex-plug-into-AUCTeX t)
(add-hook 'LaTeX-mode-hook (function (lambda() (bind-key "C-c C-r" 'reftex-query-replace-document))))
(add-hook 'LaTeX-mode-hook (function (lambda() (bind-key "C-c C-g" 'reftex-grep-document))))
(add-hook 'TeX-mode-hook (lambda () (reftex-isearch-minor-mode))) ; for AUCTeX
;; A user-defined function to delete the current macro in AUCTeX.
;; Note: keybinds won't be added to TeX-mode-hook if not kept at the end of the AUCTeX setup!
(defun TeX-remove-macro ()
"Remove current macro and return `t'. If no macro at point,
return 'nil'."
(interactive)
(when (TeX-current-macro)
(let ((bounds (TeX-find-macro-boundaries))
(brace (save-excursion
(goto-char (1- (TeX-find-macro-end)))
(TeX-find-opening-brace))))
(delete-region (1- (cdr bounds)) (cdr bounds))
(delete-region (car bounds) (1+ brace)))
t))
(add-hook 'LaTeX-mode-hook (lambda () (bind-key "M-DEL" 'TeX-remove-macro)))
My Trial with use-package (not working properly)
(use-package reftex
:commands turn-on-reftex
:config (setq reftex-plug-into-AUCTeX t))
(use-package tex
:ensure auctex
:init
(progn
;; A function to delete the current macro in AUCTeX.
;; Note: keybinds won't be added to TeX-mode-hook if not kept at the end of the AUCTeX setup!
(defun TeX-remove-macro ()
"Remove current macro and return TRUE, If no macro at point, return Nil."
(interactive)
(when (TeX-current-macro)
(let ((bounds (TeX-find-macro-boundaries))
(brace (save-excursion
(goto-char (1- (TeX-find-macro-end)))
(TeX-find-opening-brace))))
(delete-region (1- (cdr bounds)) (cdr bounds))
(delete-region (car bounds) (1+ brace)))
t))
)
:bind (:map LaTeX-mode-map
("M-<delete>" . TeX-remove-macro)
("C-c C-r" . reftex-query-replace-document)
("C-c C-g" . reftex-grep-document))
:config
(progn
(add-to-list 'TeX-command-list
'("Makeglossaries" "makeglossaries %s" TeX-run-command nil
(latex-mode)
:help "Run makeglossaries script, which will choose xindy or makeindex") t)
(setq-default TeX-master nil) ; by each new fie AUCTEX will ask for a master fie.
(setq TeX-auto-save t)
(setq TeX-save-query nil) ; don't prompt for saving the .tex file
(setq TeX-parse-self t)
(setq-default TeX-PDF-mode t)
(setq TeX-show-compilation nil) ; if `t`, automatically shows compilation log
(setq-default TeX-engine 'xetex) ; optional
(setq LaTeX-babel-hyphen nil) ; Disable language-specific hyphen insertion.
;; `"` expands into csquotes macros (for this to work, babel pkg must be loaded after csquotes pkg).
(setq LaTeX-csquotes-close-quote "}"
LaTeX-csquotes-open-quote "\\enquote{")
;; Font-lock for AUCTeX
;; Note: '«' and '»' is by pressing 'C-x 8 <' and 'C-x 8 >', respectively
(font-lock-add-keywords 'latex-mode (list (list "\\(«\\(.+?\\|\n\\)\\)\\(+?\\)\\(»\\)" '(1 'font-latex-string-face t) '(2 'font-latex-string-face t) '(3 'font-latex-string-face t))))
;; Add standard Sweave file extensions to the list of files recognized by AUCTeX.
(setq TeX-file-extensions
'("Rnw" "rnw" "Snw" "snw" "tex" "sty" "cls" "ltx" "texi" "texinfo" "dtx"))
(add-hook 'TeX-mode-hook (lambda () (reftex-isearch-minor-mode))) ; for AUCTeX
)
:mode ("\\.tex\\'" . latex-mode)
)
Issues
When I open any .tex
file it is no longer recognized by AucTeX, and no font-locking is there.
After some googling around, I found handful of Emacs dot file setups, but the variety of setups left me clueless as what to do in order to get my LaTeX configuration adjusted after use-package
verse given the complexity of the different components and use cases (tex, latex, auctex, reftex, etc).
So given my working current configuration above, how should it be adjusted to fit the use-package
verse?
Note
- Other packages were working as expected with
use-package
, issues so far only with latex - GNU Emacs 25.2.2 (x86_64-pc-linux-gnu, GTK+ Version 3.18.9) of 2017-05-06
use-package
version: 20170710.1234