Merge branch 'develop' into lsp-tex

This commit is contained in:
M. Yas. Davoodeh 2020-04-26 10:40:34 +04:30 committed by GitHub
commit 96276a688d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
263 changed files with 4049 additions and 2644 deletions

View file

@ -1,10 +1,5 @@
;;; lang/latex/+ref.el -*- lexical-binding: t; -*-
(when (stringp +latex-bibtex-file)
(setq bibtex-completion-bibliography (list (expand-file-name +latex-bibtex-file))
reftex-default-bibliography bibtex-completion-bibliography))
(use-package! reftex
:hook (LaTeX-mode . reftex-mode)
:config

View file

@ -8,6 +8,10 @@
- [[#module-flags][Module Flags]]
- [[#plugins][Plugins]]
- [[#prerequisites][Prerequisites]]
- [[#ubuntu][Ubuntu]]
- [[#arch-linux][Arch Linux]]
- [[#macos][macOS]]
- [[#nixos][NixOS]]
- [[#features][Features]]
- [[#customization][Customization]]
- [[#specifying-the-location-of-a-bibtex-file--corresponding-pdfs][Specifying the location of a bibtex file & corresponding PDFs]]
@ -24,7 +28,6 @@ Provide a helping hand when working with LaTeX documents.
+ Change PDF viewer to Okular or ~latex-preview-pane~
+ Bibtex editor
+ Autocompletion using ~company-mode~
+ Ivy or Helm for selecting bibliography
+ Compile your .tex code only once using LatexMk
** Module Flags
@ -32,6 +35,8 @@ Provide a helping hand when working with LaTeX documents.
+ =+cdlatex= Enable [[https://github.com/cdominik/cdlatex][cdlatex]] for fast math insertion.
+ =+lsp= Start LSP automatically in `tex-mode-hook`. This requires the =:tools
lsp= module. Supported servers are `digestif` and `TexLab`.
+ =+fold= Use TeX-fold (from auctex) to fold LaTeX macros to unicode, and make
folding hook-based and less manual.
** Plugins
+ [[http://www.gnu.org/software/auctex/][auctex]]
@ -41,23 +46,51 @@ Provide a helping hand when working with LaTeX documents.
+ [[https://github.com/alexeyr/company-auctex][company-auctex]]*
+ [[https://github.com/TheBB/company-reftex][company-reftex]]*
+ [[https://github.com/vspinu/company-math][company-math]]*
+ [[https://github.com/tmalsburg/helm-bibtex][ivy-bibtex]]* or [[https://github.com/tmalsburg/helm-bibtex][helm-bibtex]]*
+ [[https://github.com/cdominik/cdlatex][cdlatex]] (=+cdlatex=)
* TODO Prerequisites
* Prerequisites
You will need ghostscript and a latex compiler. All this is provided by
the =texlive= bundle, available through many OS package managers.
Ghostscript <= 9.27 is [[https://www.gnu.org/software/auctex/manual/preview-latex/No-images-are-displayed-with-gs-9_002e27-and-earlier.html][reported buggy]] and doesn't work with auctex's math
previews. (You can check you ghostscript version with ~gs --version~.) Most
package managers already have newer versions, but if not you might have to build
gs from source.
** Ubuntu
#+BEGIN_SRC sh
apt-get install texlive
#+END_SRC
** Arch Linux
#+BEGIN_SRC sh
pacman -S texlive
#+END_SRC
** TODO macOS
#+BEGIN_SRC sh
brew cask install basictex
# If the above doesn't work, then
brew cask install mactex # WARNING: large 4gb download!
#+END_SRC
#+begin_quote
This has not been verified.
#+end_quote
** NixOS
#+BEGIN_SRC nix
environment.systemPackages = [ pkgs.texlive.combined.scheme-medium ];
#+END_SRC
* TODO Features
* Customization
** Specifying the location of a bibtex file & corresponding PDFs
The reftex and bibtex-completion packages have two variables that allow you to
specify where it should find your bibliography file(s) and their corresponding
PDFs:
Reftex has a variable that allow you to
specify where it should find your bibliography file(s):
#+BEGIN_SRC emacs-lisp
(setq reftex-default-bibliography "/your/bib/file.bib")
;; Optionally specifying a location for the corresponding PDFs
(setq bibtex-completion-library-path (list "/your/bib/pdfs"))
#+END_SRC
** Changing the PDFs viewer

View file

@ -39,6 +39,18 @@ Continuation lines are indented either twice `LaTeX-indent-level', or
(+ offset indent))
((+ contin indent))))))
;;;###autoload
(defun +latex-fold-last-macro-a (&rest _)
"Advice to auto-fold LaTeX macros after functions that
typically insert macros."
;; A simpler approach would be to just fold the whole line, but if point was
;; inside a macro that would would kick it out. So instead we fold the last
;; macro before point, hoping its the one newly inserted.
(TeX-fold-region (save-excursion
(search-backward "\\" (line-beginning-position) t)
(point))
(1+ (point))))
;;;###autoload
(defun +latex-symbols-company-backend (command &optional arg &rest _ignored)
"A wrapper backend for `company-mode' that either uses

View file

@ -3,9 +3,6 @@
(defvar +latex-indent-level-item-continuation 4
"Custom indentation level for items in enumeration-type environments")
(defvar +latex-bibtex-file nil
"File AUCTeX (specifically RefTeX) uses to search for citations.")
(defvar +latex-enable-unicode-math nil
"If non-nil, use `company-math-symbols-unicode' backend in LaTeX-mode,
enabling unicode symbols in math regions. This requires the unicode-math latex
@ -39,6 +36,7 @@ If no viewers are found, `latex-preview-pane' is used.")
;; automatically insert braces after sub/superscript in math mode
TeX-electric-sub-and-superscript t)
(after! tex
;; fontify common latex commands
(load! "+fontification")
@ -55,8 +53,6 @@ If no viewers are found, `latex-preview-pane' is used.")
fill-nobreak-predicate (cons #'texmathp fill-nobreak-predicate))
;; Enable word wrapping
(add-hook 'TeX-mode-hook #'visual-line-mode)
;; Fold TeX macros
(add-hook 'TeX-mode-hook #'TeX-fold-mode)
;; Enable rainbow mode after applying styles to the buffer
(add-hook 'TeX-update-style-hook #'rainbow-delimiters-mode)
;; display output of latex commands in popup
@ -82,6 +78,45 @@ If no viewers are found, `latex-preview-pane' is used.")
#'lsp!)))
(use-package! tex-fold
:when (featurep! +fold)
:hook (TeX-mode . TeX-fold-buffer)
:hook (TeX-mode . TeX-fold-mode)
:config
;; Fold after all auctex macro insertions
(advice-add #'TeX-insert-macro :after #'+latex-fold-last-macro-a)
;; Fold after cdlatex macro insertions
(advice-add #'cdlatex-math-symbol :after #'+latex-fold-last-macro-a)
(advice-add #'cdlatex-math-modify :after #'+latex-fold-last-macro-a)
;; Fold after snippets
(when (featurep! :editor snippets)
(add-hook 'TeX-fold-mode-hook
(defun +latex-fold-set-yas-hook-h ()
"Set a local after-snippet-hook to fold the snippet contents."
(add-hook! 'yas-after-exit-snippet-hook :local
(TeX-fold-region yas-snippet-beg yas-snippet-end)))))
(add-hook 'mixed-pitch-mode-hook
(defun +latex-fold-set-variable-pitch-h ()
"Fix folded things invariably getting fixed pitch when using mixed-pitch.
Math faces should stay fixed by the mixed-pitch blacklist, this
is mostly for \\section etc."
(when mixed-pitch-mode
;; Adding to this list makes mixed-pitch clean the face remaps after us
(add-to-list 'mixed-pitch-fixed-cookie
(face-remap-add-relative
'TeX-fold-folded-face
:family (face-attribute 'variable-pitch :family)
:height (face-attribute 'variable-pitch :height))))))
(map! :map TeX-fold-mode-map
:localleader
:desc "Fold paragraph" "f" #'TeX-fold-paragraph
:desc "Unfold paragraph" "F" #'TeX-fold-clearout-paragraph
:desc "Unfold buffer" "C-f" #'TeX-fold-clearout-buffer))
(after! latex
(setq LaTeX-section-hook ; Add the toc entry to the sectioning hooks.
'(LaTeX-section-heading
@ -125,9 +160,9 @@ If no viewers are found, `latex-preview-pane' is used.")
(use-package! cdlatex
:defer t
:when (featurep! +cdlatex)
:hook (LaTeX-mode . cdlatex-mode)
:hook (org-mode . org-cdlatex-mode)
:config
;; Use \( ... \) instead of $ ... $
(setq cdlatex-use-dollar-to-ensure-math nil)
@ -135,22 +170,22 @@ If no viewers are found, `latex-preview-pane' is used.")
(map! :map cdlatex-mode-map
;; smartparens takes care of inserting closing delimiters, and if you
;; don't use smartparens you probably won't want these also.
:g "$" nil
:g "(" nil
:g "{" nil
:g "[" nil
:g "|" nil
:g "<" nil
"$" nil
"(" nil
"{" nil
"[" nil
"|" nil
"<" nil
;; TAB is used for cdlatex's snippets and navigation. But we have
;; yasnippet for that.
(:when (featurep! :editor snippets)
:g "TAB" nil)
"TAB" nil)
;; AUCTeX takes care of auto-inserting {} on _^ if you want, with
;; `TeX-electric-sub-and-superscript'
:g "^" nil
:g "_" nil
"^" nil
"_" nil
;; AUCTeX already provides this with `LaTeX-insert-item'
:g [(control return)] nil))
[(control return)] nil))
;; Nicely indent lines that have wrapped when visual line mode is activated

View file

@ -19,7 +19,3 @@
(package! company-auctex :pin "48c42c58ce")
(package! company-reftex :pin "275ef708f0")
(package! company-math :pin "a796053590"))
(when (featurep! :completion ivy)
(package! ivy-bibtex :pin "d4471232be"))
(when (featurep! :completion helm)
(package! helm-bibtex :pin "d4471232be"))