{"id":5096,"date":"2012-10-05T00:27:18","date_gmt":"2012-10-04T22:27:18","guid":{"rendered":"http:\/\/djalil.chafai.net\/blog\/?p=5096"},"modified":"2013-05-02T19:12:23","modified_gmt":"2013-05-02T17:12:23","slug":"emacsulation","status":"publish","type":"post","link":"https:\/\/djalil.chafai.net\/blog\/2012\/10\/05\/emacsulation\/","title":{"rendered":"Emacsulation"},"content":{"rendered":"<p style=\"text-align: justify;\"><a href=\"http:\/\/djalil.chafai.net\/blog\/2012\/10\/05\/emacsulation\/220px-emacs-logo-svg\/\" rel=\"attachment wp-att-5102\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-5102\" title=\"GNU Emacs\" alt=\"GNU Emacs\" src=\"\/blog\/wp-content\/uploads\/2012\/10\/220px-Emacs-logo.svg_.png\" width=\"220\" height=\"177\" \/><\/a>For typesetting mathematics, I am used to use the <a href=\"http:\/\/en.wikipedia.org\/wiki\/LaTeX\">LaTeX<\/a> document preparation system with the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Auctex\">AUCTeX<\/a> package for the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Emacs\">GNU Emacs<\/a> editor, and the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Evince\">GNOME Evince<\/a> viewer, provided by <a href=\"http:\/\/en.wikipedia.org\/wiki\/Debian\">Debian<\/a>. Here is my modest init file: <strong><a href=\"\/Docs\/dot-emacs-el-2013-05.el\">dot-emacs.el<\/a><\/strong>. It features synctex forward and inverse search (without focus problems) and many other goodies. Feel free to use it and to improve it!<\/p>\n<p style=\"text-align: justify;\">Wikipedia provides a rich <a href=\"http:\/\/en.wikipedia.org\/wiki\/Comparison_of_TeX_editors\">list of LaTeX editors<\/a>. By curiosity, you may try from time to time some of these editors. Even if they have made huge progresses, I still believe personally that Emacs is the best to date, due to its versatility: within the editor, one can open a remote file using SSH, one can search for bibtex entries from arXiv or MathSciNet, one can play with Octave, etc.<\/p>\n<p style=\"text-align: justify;\">PS: EMACSulation is the name of an <a href=\"http:\/\/linuxgazette.net\/issue31\/marsden.html\">old series of articles<\/a> by <span title=\"An old friend!\">Eric Marsden<\/span> in the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Linux_Gazette\">Linux Gazette<\/a>.<\/p>\n<pre style=\"font-size: small;\">\r\n;;;\r\n;;; Djalil's GNU Emacs .emacs.el init file, dated 2013-05. \r\n;;; Tested with Emacs 23 and 24, Auctex 11.86, Evince 3.4\r\n;;; With Auctex 11.87, reverse\/forward search is almost built-in (with bugs)\r\n;;; Debian: apt-get install wmctrl auctex preview-latex \r\n;;;\r\n(add-to-list 'load-path \"~\/S\/elisp\")\r\n(setq custom-file \"~\/.emacs.cu\")\r\n;;;\r\n(setq locale-coding-system 'utf-8)\r\n(set-selection-coding-system 'utf-8)\r\n(prefer-coding-system 'utf-8)\r\n(set-default-font \"DejaVu Sans Mono-16\")\r\n;;;\r\n(require 'jka-compr) ; Read compressed files\r\n(require 'paren)     ; Visual matching () {} [] \r\n;; s-region.el and pc-select are obsolete.\r\n;;  They are superseded by shift-select-mode enabled by default in 23.1.\r\n;(require 's-region)  ; Copy\/Cut\/Paste with Shift\/Delete\/Insert\r\n;;;\r\n(put 'eval-expression 'disabled nil)\r\n(put 'erase-buffer 'disabled nil)\r\n(put 'narrow-to-region 'disabled nil)\r\n;;;\r\n(custom-set-variables \r\n '(column-number-mode t)\r\n '(default-major-mode 'text-mode)\r\n '(delete-selection-mode t)\r\n '(dired-listing-switches \"-alF\")\r\n '(dired-ls-program \"\/bin\/ls\")\r\n '(fill-column 78)\r\n '(global-font-lock-mode t)\r\n '(indent-tabs-mode nil)\r\n '(iso-accents-customize french)\r\n '(line-number-mode t)\r\n '(resize-minibuffer-mode t)\r\n '(search-highlight t)\r\n '(sentence-end-double-space nil)\r\n '(show-paren-mode t)\r\n '(show-paren-ring-bell-on-mismatch t)\r\n '(show-paren-style 'mixed)\r\n '(tab-width 4)\r\n '(tool-bar-mode nil)\r\n '(transient-mark-mode t)\r\n)\r\n;;;\r\n;;; I don't remember who wrote this useful function...\r\n;;;\r\n(defun match-paren (arg)\r\n  \" Go to the matching parenthesis if on parenthesis otherwise insert %.\"\r\n  (interactive \"p\")\r\n  (cond ((looking-at \"\\\\s\\(\") (forward-list 1) (backward-char 1))\r\n        ((looking-at \"\\\\s\\)\") (forward-char 1) (backward-list 1))\r\n        (t (self-insert-command (or arg 1)))))\r\n;;;\r\n;;; Keys\r\n;;;\r\n(define-key global-map [(%)] 'match-paren)\r\n(define-key global-map [(f1)] 'help)\r\n(define-key global-map [(f2)] 'run-octave)\r\n(define-key global-map [(f3)] 'font-lock-mode)\r\n(define-key global-map [(f4)] 'ispell-change-dictionary)\r\n(define-key global-map [(next)] '(lambda ()(interactive)(scroll-up 25)))\r\n(define-key global-map [(prior)] '(lambda ()(interactive)(scroll-down 25)))\r\n(define-key global-map [(control home)] 'beginning-of-buffer)\r\n(define-key global-map [(control end)] 'end-of-buffer)\r\n(define-key global-map [(meta backspace)] 'undo)\r\n(define-key global-map [(meta return)] 'eshell)\r\n;(define-key global-map [(delete)] 'delete-char)\r\n;;;\r\n;;; Bibretrieve allows to fetch Bibtex entries from MathSciNet or arXiv\r\n;;; Get if from http:\/\/www.emacswiki.org\/emacs\/download\/bibretrieve.el\r\n;;;\r\n(autoload 'bibretrieve \"bibretrieve\" \"Search for BibTeX entries on the web\" t) \r\n(setq bibretrieve-backends '((\"mrl\" . 10) (\"arxiv\" . 5)))\r\n;;;\r\n;;; LaTeX: AUCTeX, Bibcite, RefTeX, etc\r\n;;;\r\n(require 'tex-site)\r\n(load-library \"auctex\")\r\n(load-library \"preview-latex\") \r\n(load \"server\")\r\n(unless (server-running-p) (server-start))\r\n(if window-system (require 'font-latex))\r\n(autoload 'turn-on-bib-cite \"bib-cite\")\r\n(custom-set-variables\r\n '(TeX-auto-save t)\r\n '(TeX-master nil)\r\n '(TeX-parse-self t)\r\n '(TeX-source-specials-mode t)\r\n '(bib-cite-use-reftex-view-crossref t)\r\n '(reftex-enable-partial-scans t)\r\n '(reftex-insert-label-flags (quote (t t)))\r\n '(reftex-plug-into-AUCTeX t)\r\n '(reftex-save-parse-info t)\r\n '(reftex-label-alist \r\n   (quote ((\"thm\" ?h \"th:\" \"~\\\\ref{%s}\" nil (\"thm\" \"th.\")) \r\n           (\"defn\" ?d \"def:\" \"~\\\\ref{%s}\" nil (\"defn\" \"def.\")) \r\n           (\"lem\" ?l \"lem:\" \"~\\\\ref{%s}\" t (\"lem\" \"lem.\")))))\r\n '(reftex-use-multiple-selection-buffers t))\r\n(add-hook 'LaTeX-mode-hook 'turn-on-auto-fill)\r\n(add-hook 'LaTeX-mode-hook 'turn-on-bib-cite)\r\n(add-hook 'LaTeX-mode-hook 'turn-on-reftex)\r\n(add-hook 'LaTeX-mode-hook 'font-lock-mode)\r\n(add-hook 'LaTeX-mode-hook 'imenu-add-menubar-index)\r\n(add-hook 'LaTeX-mode-hook 'my-LaTeX-keys)\r\n(defun my-LaTeX-keys ()\r\n  (define-key LaTeX-mode-map [down-mouse-3] 'imenu)\r\n  (define-key LaTeX-mode-map [(f7)] 'preview-buffer)\r\n  (define-key LaTeX-mode-map [(f8)] 'preview-clearout-buffer)\r\n  (define-key LaTeX-mode-map [(f9)] 'TeX-command-master)\r\n  (define-key LaTeX-mode-map [(f10)] 'TeX-next-error)\r\n  (define-key LaTeX-mode-map [(f12)] 'TeX-toggle-debug-bad-boxes)\r\n  (define-key LaTeX-mode-map [(print)] 'preview-buffer)\r\n  (define-key LaTeX-mode-map [(control B)] 'bibretrieve)\r\n  (define-key LaTeX-mode-map [(control C)] 'reftex-citation)\r\n  (define-key LaTeX-mode-map [(control R)] 'reftex-reference))\r\n(add-hook 'server-switch-hook 'raise-frame)\r\n;;\r\n;; Forward\/inverse search using Evince (based on dbus, needs also wmctrl)\r\n;; Forward: C-c C-v \r\n;; Inverse: Ctrl - Left Mouse Button\r\n;;\r\n(add-hook 'LaTeX-mode-hook 'TeX-PDF-mode)\r\n(setq TeX-source-correlate-method 'synctex) ; instead of source-specials \r\n(add-hook 'LaTeX-mode-hook 'TeX-source-correlate-mode)\r\n;;\r\n;; Forward search.\r\n;;\r\n(defun un-urlify (fname-or-url)\r\n  \"Transform file:\/\/\/absolute\/path into \/absolute\/path\"\r\n  ;; Limited support for special characters\"\r\n  (if (string= (substring fname-or-url 0 8) \"file:\/\/\/\")\r\n      (url-unhex-string (substring fname-or-url 7))\r\n    fname-or-url))\r\n;;\r\n(defun urlify-escape-only (path)\r\n  \"Handle special characters for urlify\"\r\n  (replace-regexp-in-string \" \" \"%20\" path))\r\n;;\r\n(defun urlify (absolute-path)\r\n  \"Transform \/absolute\/path to file:\/\/\/absolute\/path\"\r\n  ;; Limited support for special characters\"\r\n  (urlify-escape-only \r\n   (concat \"file:\/\/\" \r\n           (file-truename \r\n            (concat default-directory absolute-path)))))\r\n;;\r\n(if (require 'dbus \"dbus\" t) \r\n    (progn\r\n      ;; universal time, need by evince\r\n      (defun utime ()  \r\n        (let ((high (nth 0 (current-time)))\r\n              (low (nth 1 (current-time))))\r\n          (+ (* high (lsh 1 16) ) low)))\r\n      ;;\r\n      (defun auctex-evince-forward-sync (pdffile texfile line)\r\n        (let ((dbus-name\r\n               (dbus-call-method \r\n                :session\r\n                \"org.gnome.evince.Daemon\"  ; service\r\n                \"\/org\/gnome\/evince\/Daemon\" ; path\r\n                \"org.gnome.evince.Daemon\"  ; interface\r\n                \"FindDocument\"\r\n                (urlify pdffile)\r\n                t ; Open a new win if file not opened.\r\n                )))\r\n          (dbus-call-method \r\n           :session\r\n           dbus-name\r\n           \"\/org\/gnome\/evince\/Window\/0\"\r\n           \"org.gnome.evince.Window\"\r\n           \"SyncView\"\r\n           (urlify-escape-only texfile)\r\n           (list :struct :int32 line :int32 1)\r\n           (utime)))\r\n        ;DC: bring the window to the foreground and give it the focus \r\n        (call-process \"wmctrl\" nil nil nil \"-R\" pdffile)) \r\n      ;;\r\n      (defun auctex-evince-view ()\r\n        (let ((pdffile (concat (TeX-master-file TeX-output-extension)))\r\n              (texfile (buffer-file-name))\r\n              (line (line-number-at-pos)))\r\n          (auctex-evince-forward-sync pdffile texfile line)))\r\n      ;; New view entry: Evince via D-bus.\r\n      (setq TeX-view-program-list '())\r\n      (add-to-list 'TeX-view-program-list\r\n                   '(\"EvinceDbus\" auctex-evince-view))\r\n      ;; Prepend Evince via D-bus to program selection list\r\n      ;; overriding other settings for PDF viewing.\r\n      (setq TeX-view-program-selection '())\r\n      (add-to-list 'TeX-view-program-selection\r\n                   '(output-pdf \"EvinceDbus\"))))\r\n;;\r\n;; Inverse search.\r\n;;\r\n(if (require 'dbus \"dbus\" t) \r\n    (progn\r\n      ;;\r\n      (defadvice raise-frame (after make-it-work (&optional frame) activate)\r\n        \"Work around some bug? in raise-frame\/Emacs\/GTK\/Metacity\/something.\r\n         Katsumi Yamaoka http:\/\/article.gmane.org\/gmane.emacs.devel:39702\"\r\n        (call-process \r\n         \"wmctrl\" nil nil nil \"-i\" \"-R\"\r\n         (frame-parameter (or frame (selected-frame)) 'outer-window-id)))\r\n      ;;\r\n      (defun auctex-evince-inverse-sync (file linecol timestamp)\r\n        (let ((buf (get-file-buffer (un-urlify file)))\r\n              (line (car linecol))\r\n              (col (cadr linecol)))\r\n          (if (null buf)\r\n              (message \"Sorry, %s is not opened...\" file)\r\n            (switch-to-buffer buf)\r\n            (goto-line (car linecol))\r\n            (unless (= col -1)\r\n              (move-to-column col))\r\n            (raise-frame))))\r\n      ;; \r\n      (dbus-register-signal \r\n       :session \r\n       nil \r\n       \"\/org\/gnome\/evince\/Window\/0\"\r\n       \"org.gnome.evince.Window\" \r\n       \"SyncSource\"\r\n       'auctex-evince-inverse-sync)))\r\n;;;\r\n;;; Tramp \r\n;;;\r\n(require 'tramp)\r\n(setq tramp-default-method \"scp\")\r\n;;; \r\n;;; Octave mode\r\n;;;\r\n(autoload 'octave-mode \"octave-mod\" nil t)\r\n(setq auto-mode-alist\r\n      (cons '(\"\\\\.m$\" . octave-mode) auto-mode-alist))\r\n(add-hook 'octave-mode-hook\r\n          (lambda ()\r\n            (abbrev-mode 1)\r\n            (auto-fill-mode 1)\r\n            (if (eq window-system 'x)\r\n                (font-lock-mode 1))))\r\n(add-hook 'inferior-octave-mode-hook\r\n          (lambda ()\r\n            (turn-on-font-lock)\r\n            (define-key inferior-octave-mode-map [up]\r\n              'comint-previous-input)\r\n            (define-key inferior-octave-mode-map [down]\r\n              'comint-next-input)))\r\n;;;\r\n;;\r\n;; Credits\r\n;;\r\n;; http:\/\/dud.inf.tu-dresden.de\/~ben\/evince_synctex.tar.gz\r\n;; http:\/\/tex.stackexchange.com\/questions\/29813\/setup-synctex-with-emacs\r\n;; http:\/\/coderuins.wordpress.com\/2011\/10\/04\/using-synctex-with-emacs-and-evince-3-2\/\r\n;; http:\/\/www.mail-archive.com\/auctex@gnu.org\/msg04175.html\r\n;;\r\n;;; EOF.\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>For typesetting mathematics, I am used to use the LaTeX document preparation system with the AUCTeX package for the GNU Emacs editor, and the GNOME&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/djalil.chafai.net\/blog\/2012\/10\/05\/emacsulation\/\">Continue reading<span class=\"screen-reader-text\">Emacsulation<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":97},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/posts\/5096"}],"collection":[{"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/comments?post=5096"}],"version-history":[{"count":116,"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/posts\/5096\/revisions"}],"predecessor-version":[{"id":5942,"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/posts\/5096\/revisions\/5942"}],"wp:attachment":[{"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/media?parent=5096"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/categories?post=5096"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/djalil.chafai.net\/blog\/wp-json\/wp\/v2\/tags?post=5096"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}