Emacs: TeX pdf compression now supports spaces.

Emacs: tex-clean in LISP, no more shell.
master
Pierre Neidhardt 2013-02-26 21:30:27 +01:00
parent b97c7e9f40
commit 14dae113bb
1 changed files with 24 additions and 12 deletions

View File

@ -125,7 +125,7 @@
;; I find the default tex-mode and AucTeX quite disappointing. I'm using custom ;; I find the default tex-mode and AucTeX quite disappointing. I'm using custom
;; functions for everything. ;; functions for everything.
(defcustom tex-my-viewer "zathura --fork -s -x \"emacsclient --eval '(progn (switch-to-buffer (file-name-nondirectory \"'\"'\"%{input}\"'\"'\")) (goto-line %{line}))'\"" (defcustom tex-my-viewer "zathura --fork -s -x \"emacsclient --eval '(progn (switch-to-buffer (file-name-nondirectory \"'\"'\"%{input}\"'\"'\")) (goto-line %{line}))'\""
"PDF Viewer for TeX documents. You may want to fork the viewer "PDF Viewer for TeX documents. You may want to fork the viewer
so that it detects when the same document is launched twice, and so that it detects when the same document is launched twice, and
persists when Emacs gets closed. persists when Emacs gets closed.
@ -242,13 +242,13 @@ WARNING: the -shell-escape option is a potential security issue."
((string= "plain-tex-mode" major-mode) tex-my-default-compiler) ((string= "plain-tex-mode" major-mode) tex-my-default-compiler)
(t (message "Warning: unknown major mode. Trying pdftex.") "pdftex")) (t (message "Warning: unknown major mode. Trying pdftex.") "pdftex"))
tex-my-compiler)) tex-my-compiler))
;; Master file ;; Master file
(local-master (local-master
(if (not tex-my-masterfile) (if (not tex-my-masterfile)
buffer-file-name buffer-file-name
tex-my-masterfile)) tex-my-masterfile))
;; If tex-my-startcommands has some content, we make sure it is a string ;; If tex-my-startcommands has some content, we make sure it is a string
;; that loads the file. ;; that loads the file.
(local-start-cmd (local-start-cmd
@ -268,13 +268,13 @@ WARNING: the -shell-escape option is a potential security issue."
(save-buffer) (save-buffer)
(setq compilation-scroll-output t) (setq compilation-scroll-output t)
(compile local-compile-command) (compile local-compile-command)
;; If no user interaction for 2 seconds, hide the compilation window. ;; If no user interaction for 2 seconds, hide the compilation window.
(sit-for 2) (sit-for 2)
(delete-windows-on "*compilation*")))) (delete-windows-on "*compilation*"))))
(defcustom tex-my-extension-list '(".aux" ".glg" ".glo" ".gls" ".idx" ".ilg" ".ind" ".lof" ".log" ".nav" ".out" ".snm" ".synctex" ".synctex.gz" ".tns" ".toc" ".xdy") (defcustom tex-my-extension-list '("aux" "glg" "glo" "gls" "idx" "ilg" "ind" "lof" "log" "nav" "out" "snm" "synctex" "synctex.gz" "tns" "toc" "xdy")
"List of known TeX exentsions. This list is used by 'tex-clean to purge all matching files." "List of known TeX exentsions. This list is used by 'tex-clean to purge all matching files."
:safe 'listp) :safe 'listp)
@ -290,11 +290,23 @@ but there is no warranty."
buffer-file-name buffer-file-name
tex-my-masterfile))) tex-my-masterfile)))
(setq file-noext (replace-regexp-in-string ".tex" "" (file-name-nondirectory local-master))) (let (
(shell-command ;; File name without extension.
(concat "rm -f \"" file-noext (file
(mapconcat 'identity tex-my-extension-list (concat "\" \"" file-noext)) (replace-regexp-in-string "tex" "" (file-name-nondirectory local-master))))
"\""))))
;; Concatate file name to list.
(mapcar
;; Delete file if exist
(lambda (argfile) (interactive)
(when (and (file-exists-p argfile) (file-writable-p argfile))
(delete-file argfile)
(message "[%s] deleted." argfile)))
(mapcar
;; Concat file name with extensions.
(lambda (arg) (interactive) (concat file arg))
tex-my-extension-list))
)))
(defun tex-pdf-compress () (defun tex-pdf-compress ()
"PDF compressions might really strip down the PDF size. The "PDF compressions might really strip down the PDF size. The
@ -313,13 +325,13 @@ your document embeds raster graphics."
(file-temp (file-temp
(concat (make-temp-name (concat "/tmp/" (file-name-nondirectory local-master))) ".pdf")) (concat (make-temp-name (concat "/tmp/" (file-name-nondirectory local-master))) ".pdf"))
;; File name with extension. ;; File name with PDF extension.
(file (file
(replace-regexp-in-string "tex" "pdf" (file-name-nondirectory local-master)))) (replace-regexp-in-string "tex" "pdf" (file-name-nondirectory local-master))))
(when (and (file-exists-p file) (file-writable-p file)) (when (and (file-exists-p file) (file-writable-p file))
(shell-command (shell-command
(concat "gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=" file-temp " " file)) (concat "gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=\"" file-temp "\" \"" file "\""))
(rename-file file-temp file t) (rename-file file-temp file t)
)))) ))))