Function: TeX-read-hook
TeX-read-hook is a byte-compiled function defined in latex.el.
Signature
(TeX-read-hook)
Documentation
Read a LaTeX hook and return it as a string.
Source Code
;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/latex.el
(defun TeX-read-hook ()
"Read a LaTeX hook and return it as a string."
(let* ((hook (completing-read
(TeX-argument-prompt nil nil "Hook")
'("cmd"
"env"
;; From ltfilehook-doc.pdf
"file" "include" "class" "package"
;; From lthooks-doc.pdf
"begindocument" "enddocument"
"rmfamily" "sffamily"
"ttfamily" "normalfont"
"bfseries" "mdseries"
;; From ltshipout-doc.pdf
"shipout"
;; From ltpara-doc.pdf
"para"
;; From ltmarks-doc.pdf
"insertmark"
;; From ltoutput.dtx
"build")))
(place (lambda (&optional opt pr)
(completing-read
(TeX-argument-prompt opt pr "Where")
(cond ((member hook '("env" "para"))
'("after" "before" "begin" "end"))
((string= hook "include")
'("after" "before" "end" "excluded"))
((string= hook "begindocument")
'("before" "end"))
((string= hook "enddocument")
'("afterlastpage" "afteraux" "info" "end"))
((member hook '("bfseries" "mdseries"))
'("defaults"))
((string= hook "shipout")
'("before" "after"
"foreground" "background"
"firstpage" "lastpage"))
(t
'("after" "before"))))))
(search (lambda ()
(if (eq TeX-arg-input-file-search 'ask)
(not (y-or-n-p "Find file yourself? "))
TeX-arg-input-file-search)))
name where files)
(cond ((string= hook "cmd")
;; cmd/<name>/<where>: <where> is one of (before|after)
(setq name (completing-read
(TeX-argument-prompt nil nil "Command")
(TeX-symbol-list)))
(setq where (funcall place)))
;; env/<name>/<where>: <where> is one of (before|after|begin|end)
((string= hook "env")
(setq name (completing-read
(TeX-argument-prompt nil nil "Environment")
(LaTeX-environment-list)))
(setq where (funcall place)))
;; file/<file-name.xxx>/<where>: <file-name> is optional and
;; must be with extension and <where> is one of
;; (before|after)
((string= hook "file")
(if (funcall search)
(progn
(unless TeX-global-input-files-with-extension
(setq TeX-global-input-files-with-extension
(prog2
(message "Searching for files...")
(mapcar #'list
(TeX-search-files-by-type 'texinputs
'global
t nil))
(message "Searching for files...done"))))
(setq name
(completing-read
(TeX-argument-prompt t nil "File")
TeX-global-input-files-with-extension)))
(setq name
(file-name-nondirectory
(read-file-name
(TeX-argument-prompt t nil "File")
nil ""))))
(setq where (funcall place)))
;; include/<file-name>/<where>: <file-name> is optional and
;; <where> is one of (before|after|end|excluded)
((string= hook "include")
(if (funcall search)
(progn
(setq files
(prog2
(message "Searching for files...")
;; \include looks for files with TeX content,
;; so limit the search:
(let* ((TeX-file-extensions '("tex" "ltx")))
(TeX-search-files-by-type 'texinputs 'local t t))
(message "Searching for files...done")))
(setq name (completing-read
(TeX-argument-prompt t nil "File")
files)))
(setq name
(file-name-base
(read-file-name
(TeX-argument-prompt t nil "File")
nil ""))))
(setq where (funcall place)))
;; class/<doc-class>/<where>: <doc-class> is optional and
;; <where> is one of (before|after)
((string= hook "class")
(if (funcall search)
(progn
(unless LaTeX-global-class-files
(setq LaTeX-global-class-files
(prog2
(message "Searching for LaTeX classes...")
(let* ((TeX-file-extensions '("cls")))
(mapcar #'list
(TeX-search-files-by-type 'texinputs
'global
t t)))
(message "Searching for LaTeX classes...done"))))
(setq name (completing-read
(TeX-argument-prompt t nil "Document class")
LaTeX-global-class-files)))
(setq name
(file-name-base
(read-file-name
(TeX-argument-prompt t nil "Document class")
nil ""))))
(setq where (funcall place)))
;; package/<pack-name>/<where>: <pack-name> is optional and
;; <where> is one of (before|after)
((string= hook "package")
(if (funcall search)
(progn
(unless LaTeX-global-package-files
(setq LaTeX-global-package-files
(prog2
(message "Searching for LaTeX packages...")
(let* ((TeX-file-extensions '("sty")))
(mapcar #'list
(TeX-search-files-by-type 'texinputs
'global
t t)))
(message "Searching for LaTeX packages...done"))))
(setq name (completing-read
(TeX-argument-prompt t nil "Package")
LaTeX-global-package-files)))
(setq name (file-name-base
(read-file-name
(TeX-argument-prompt t nil "Package")
nil ""))))
(setq where (funcall place)))
;; begindocument/<where>: <where> is empty or one of
;; (before|end)
((string= hook "begindocument")
(setq where (funcall place t)))
;; enddocument/<where>: <where> is empty or one of
;; (afterlastpage|afteraux|info|end)
((string= hook "enddocument")
(setq where (funcall place t)))
;; bfseries|mdseries/<where>: <where> is empty or defaults
((member hook '("bfseries" "mdseries"))
(setq where (funcall place t)))
;; shipout/<where>: <where> is one of
;; (before|after|foreground|background|firstpage|lastpage)
((string= hook "shipout")
(setq where (funcall place)))
;; build/<name>/<where>: <name> is one of (page|column) and
;; <where> is one of (before|after|(reset)?)
((string= hook "build")
(setq name (completing-read
(TeX-argument-prompt nil nil "Place")
'("page" "column")))
(setq where (if (string= name "page")
(completing-read
(TeX-argument-prompt nil nil "Where")
'("after" "before" "reset"))
(funcall place))))
;; Other hooks or user specific input, do nothing:
(t nil))
;; Process the input: Concat the given parts and return it
(concat hook
(when (and name (not (string= name "")))
(concat "/" name))
(when (and where (not (string= where "")))
(concat "/" where)))))