Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

[aucTeX] une synthèse entre auctex et auto-complete pour écrire des fichiers TeX

3 réponses
Avatar
Guy
Bonjour,

Voici un paquet très court mais efficace ! pour écrire en LaTeX.

Il nécessite l'installation des paquets aucTeX et de auto-complete (de
Tomohiro Matsuyama).


usage:

Si vous écrivez "enu" dans le buffer apparaît alors, dans un menu afin
de completion, les environements et les macros commencant par ces trois
lettres. (y compris ceux ou celles que vous venez de définir). Il
suufit alors de pointer ce que vous recherchez <RET> et la macro ou
l'environement s'écrit dans le buffer.


Si vous utilisez TeXlive une aide (à base de TeXdoc) est fournie.


Happy TeXing !

Guy Yeterian.



=================================================================================================================
;;; auto-complete-latex --- auto-complete for LaTeX auctex

;; Copyright (C) 2010 Guy Yeterian gyecmonet <@> free <dot> fr

;; Author: Guy Yeterian
;; Maintainer: the author
;; Created: 07 Aug 2010
;; Version: 1.0
;; version 1.8 Jun 2011
;; Keywords: auctex auto-complete


;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 1, or (at your option)
;; any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; A copy of the GNU General Public License can be obtained from this
;; program's author (send electronic mail to
;; root@localhost.localdomain) or from the Free Software Foundation,
;; Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

;; LCD Archive Entry:
;; ac-latex|rockymyroot|root@localhost.localdomain
;; |auto-complete for LaTeX auctex
;; |$Date$|$Revision$|~/packages/ac-latex.el

;;; Installation
;; This is a very useful package to write LaTeX documents with aucTeX
and auto-complete
;; To use this package you must install aucTeX and auto-complete packages.
;; Just add to the .emacs file:
;; (autoload 'ac-latex-setup "auto-complete-latex" "ac and aucTeX" t)
;; (add-hook 'LaTeX-mode-hook (lambda() (ac-latex-setup)))
;; when you type 'enu' you must see all (even yours) laTeX-environments
and TeX-macros that
;; begins with this words.


;;; Commentary:
;; Free softwards are great and make me happy.
;; Many thanks to Richard Stallman for free softward concept and for emacs
;; Many thanks for the aucTeX group mainteners
;; Many thanks for auto-complete author Tomohiro Matsuyama.

;;; Change log:
;; $Log$

;;; Code:
(provide 'auto-complete-latex)

(require 'tex)
(require 'latex)


(eval-when-compile
(require 'auto-complete)
(require 'popup-pos-tip))




(defface ac-latex-candidate-face
'((t (:background "LemonChiffon1" :foreground "black")))
"Face for LaTeX candidate."
:group 'LaTeX)

(defface ac-latex-selection-face
'((t (:background "PaleGreen1" :foreground "black")))
"Face for the LaTeX selected candidate."
:group 'LaTeX)


;; add LaTeX-mode to ac-modes
(setq ac-modes (append '(LaTeX-mode latex-mode) ac-modes))



(defvar candidate nil
"Just for the Elisp compiler not complain")





;;; TeX-macros source and action

(defun ac-source-latex-macros ()
(let ((comlist (if TeX-symbol-list
(mapcar (lambda (x)
(if (listp x)
(car x)
x))
(mapcar 'car TeX-symbol-list)))))
(all-completions ac-prefix comlist))) ;; ac-latex-source-commandes



;;; action on macros
(defun action-auctex-macro ()
(re-search-backward candidate)
(delete-region (match-beginning 0) (match-end 0))
(TeX-insert-macro candidate)
) ;; action-auctex-commande



(ac-define-source LaTeX-macros
'((init . TeX-symbol-list)
(candidates . ac-source-latex-macros)
(document . TeXdoc)
(cache)
;(depends . '(LaTeX-mode auto-complete-mode))
(action . action-auctex-macro)
(requires . 2)
(candidate-face . ac-latex-candidate-face)
(selection-face . ac-latex-selection-face)
(symbol . "m")));; LaTeX-macros

;; end TeX macros







;;; LaTeX-environmants source and action

(defun ac-source-latex-environments ()
(let ((envlist (mapcar 'car LaTeX-environment-list))
)

(all-completions ac-prefix envlist))
) ;; ac-latex-source-environments

;; action pour les environments
(defun action-auctex-environment ()
(re-search-backward candidate)
(delete-region (match-beginning 0) (match-end 0))
(LaTeX-environment-menu candidate)
) ;; action-auctex-environment



(ac-define-source LaTeX-environments
'((init . LaTeX-environment-list)
(candidates . ac-source-latex-environments)
(document . TeXdoc)
(cache)
(action . action-auctex-environment)
(requires . 2)
(selection-face . ac-latex-selection-face)
(candidate-face . ac-latex-candidate-face)
(symbol . "e")))

;;; end LaTeX environments source and action






;; some help if you work with TeXlive
;; you can change it if too long. F1 give help immediateley
;; this work with TeXlive
(setq ac-quick-help-delay 10.2)

;; work with TeXlive
(defun TeXdoc (item)
(interactive)
(TeX-doc item))
;; end of TeXdoc





;; setup you call ac-latex-setup with LaTeX-mode-hook
;;;###autoload
(defun ac-latex-setup ()
(interactive)
(TeX-symbol-list)
(LaTeX-environment-list)
(setq ac-sources (append
'(ac-source-LaTeX-macros ac-source-LaTeX-environments)
ac-sources))
)

(provide 'auto-complete-latex)
;;; end of auto-complete-package

3 réponses

Avatar
Olve
Bonjour,

[follow-up sur fr.comp.applications.emacs]

Bon, il faut un peu d'aide pour l'installation --
D'abord, il faut les paquets :

auto-complete.el (évidemment)
pos-tip.el
popup-pos-tip.el

Le paquet popup-pos-tip.el a l'air de demander d'introduire
un defadvice dans son .emacs. C'est suffisamment inhabituel
pour mériter une indication :p

Bilan, j'en suis à

-------------------------------------------------------
(setq load-path
(append
(list "/home/moi/lisp/first-look/auto-complete-latex-et-all")
load-path))

(require 'pos-tip)
(require 'popup-pos-tip)

(defadvice popup-tip
(around popup-pos-tip-wrapper (string &rest args) activate)
(if (eq window-system 'x)
(apply 'popup-pos-tip string args)
ad-do-it))

(autoload 'ac-latex-setup "auto-complete-latex" "ac and aucTeX" t)
(add-hook 'LaTeX-mode-hook (lambda() (ac-latex-setup)))
-----------------------------------------------------------

Où, vous avez bien compris que j'avais mis
auto-complete-latex.el
pos-tip.el
popup-pos-tip.el
dans le répertoire
/home/moi/lisp/first-look/auto-complete-latex-et-all

[Je vous laisse commenter sur la faiblesse du append
comparé au add-to-list :D]

Plus d'erreurs au chargement d'emacs en mode LaTeX/AUCTeX,
mais comment doit donc apparaitre cette complétion ??
Je tape "subs" et j'aimerai voir subsection, subsection*,
subsubsection etc apparaître quelque part :p

Un peu d'aide donc ?
Amitiés,
Olivier
Avatar
Guy
bonjour,

Je ne sais plus si le paquet popup-pos-tip.el est encore necessaire.

Il faut installer le paquet de Matsuyama complet (si tu es sous linux
fedora ; yum install emacs-auto-complete) sinon aller sur le site de
l'auteur (ou bien emacswiki ...)

pour obtenir ce que tu veux: jamais d'antislash (jamais)

tu écris "subs" et là apparait un menu avec subsection ret puis cela
complete.


je regarderai tes recommandations en Lisp mais je ne suis qu'un amateur
(pas professionnel de l'info)




Le 16/07/2011 12:25, Olve a écrit :
Bonjour,

[follow-up sur fr.comp.applications.emacs]

Bon, il faut un peu d'aide pour l'installation --
D'abord, il faut les paquets :

auto-complete.el (évidemment)
pos-tip.el
popup-pos-tip.el

Le paquet popup-pos-tip.el a l'air de demander d'introduire
un defadvice dans son .emacs. C'est suffisamment inhabituel
pour mériter une indication :p

Bilan, j'en suis à

-------------------------------------------------------
(setq load-path
(append
(list "/home/moi/lisp/first-look/auto-complete-latex-et-all")
load-path))

(require 'pos-tip)
(require 'popup-pos-tip)

(defadvice popup-tip
(around popup-pos-tip-wrapper (string &rest args) activate)
(if (eq window-system 'x)
(apply 'popup-pos-tip string args)
ad-do-it))

(autoload 'ac-latex-setup "auto-complete-latex" "ac and aucTeX" t)
(add-hook 'LaTeX-mode-hook (lambda() (ac-latex-setup)))
-----------------------------------------------------------

Où, vous avez bien compris que j'avais mis
auto-complete-latex.el
pos-tip.el
popup-pos-tip.el
dans le répertoire
/home/moi/lisp/first-look/auto-complete-latex-et-all

[Je vous laisse commenter sur la faiblesse du append
comparé au add-to-list :D]

Plus d'erreurs au chargement d'emacs en mode LaTeX/AUCTeX,
mais comment doit donc apparaitre cette complétion ??
Je tape "subs" et j'aimerai voir subsection, subsection*,
subsubsection etc apparaître quelque part :p

Un peu d'aide donc ?
Amitiés,
Olivier


Avatar
Olve
Ok, ça y est, j'ai trouvé.

Voici pour les suivants :

------------------------------------------------------
;; path for specific libraries
(setq load-path
(append
(list "/home/moi/lisp/first-look/auto-complete-latex-et-all")
load-path))

;; tips and popups
(require 'pos-tip)
(require 'popup-pos-tip)

(defadvice popup-tip
(around popup-pos-tip-wrapper (string &rest args) activate)
(if (eq window-system 'x)
(apply 'popup-pos-tip string args)
ad-do-it))

;; auto-complete
(require 'auto-complete-config)
(ac-config-default)

;; auto-complete-latex
(autoload 'ac-latex-setup "auto-complete-latex" "ac and aucTeX" t)
(add-hook 'LaTeX-mode-hook (lambda() (ac-latex-setup)))
-----------------------------------------------------------

Ca m'a l'air très très bien !!
Il faut que j'essaie sur de gros fichiers.
On peut mettre des (ouf, sinon, c'eut été catastrophe)
Amitiés,
Olivier