[英]Emacs + AUCTeX: How to get colored pdflatex output?
我使用latexmk通過GNU Emacs + AUCTeX編譯.tex文件(我的設置在解決方案部分描述: Emacs + Synctex + Skim:如何正確設置同步?[現有方法都沒有正常工作] )
通過使用Cc Cc
,編譯.tex文檔(例如使用pdflatex)。 可以通過Cc Cl
查看/檢查此過程的輸出。 通常,存在大量輸出並且難以閱讀。 有沒有辦法讓這個輸出變成彩色? 如果我從終端使用latexmk,我至少會突出顯示latexmk輸出的重要部分。
通常的方法是將字體鎖定關鍵字添加到主模式,但輸出文件處於基本模式,因此您可能希望使用如下所示的define-derived-mode
編寫一個簡單的主模式,然后建議(說Cc Cl
)打開那個模式(肯定有更好的建議功能,但我不確定哪一個)。
(define-derived-mode latex-output-mode fundamental-mode "LaTeX Output"
"Simple mode for colorizing LaTeX output."
(set (make-local-variable 'font-lock-defaults)
'((("^!.*" . font-lock-warning-face) ; LaTeX error
("^-+$" . font-lock-builtin-face) ; latexmk divider
("^\\(?:Overfull\\|Underfull\\|Tight\\|Loose\\).*" . font-lock-string-face)
;; .....
))))
(defadvice TeX-recenter-output-buffer (after colorize-latex-output activate)
(latex-output-mode))
或者,您可以(如NN建議的那樣)覆蓋TeX-parse-error
以添加文本屬性或疊加層,突出顯示您感興趣的部分。 這樣做的缺點是,如果更新了TeX-parse-error
,您還必須手動更新您的版本,否則可能會減少工作量。 當然,只有當它已經在搜索您想要突出顯示的內容時才會起作用,即錯誤,警告,過滿/過滿的框和文件信息。
第二個選項的示例可能是:
(defun TeX-parse-error (old)
"Goto next error. Pop to OLD buffer if no more errors are found.
This version colorizes file name parsing helping to track down annoying bugs"
(let ((regexp
(concat
;; TeX error
"^\\(!\\|\\(.*?\\):[0-9]+:\\) \\|"
;; New file
"(\\(\"[^\"]*?\"\\|/*\
\\(?:\\.+[^()\r\n{} \\/]*\\|[^()\r\n{} .\\/]+\
\\(?: [^()\r\n{} .\\/]+\\)*\\(?:\\.[-0-9a-zA-Z_.]*\\)?\\)\
\\(?:[\\/]+\\(?:\\.+[^()\r\n{} \\/]*\\|[^()\r\n{} .\\/]+\
\\(?: [^()\r\n{} .\\/]+\\)*\\(?:\\.[-0-9a-zA-Z_.]*\\)?\\)?\\)*\\)\
)*\\(?: \\|\r?$\\)\\|"
;; End of file
"\\()\\))*\\|"
;; Hook to change line numbers
" !\\(?:offset(\\([---0-9]+\\))\\|"
;; Hook to change file name
"name(\\([^)]+\\))\\)\\|"
;; LaTeX bad box
"^\\(\\(?:Overfull\\|Underfull\\|Tight\\|Loose\\)\
\\\\.*?[0-9]+--[0-9]+\\)\\|"
;; LaTeX warning
"^\\(LaTeX [A-Za-z]*\\|Package [A-Za-z]+ \\)Warning:.*")))
(while
(cond
;; Nothing found
((null
(re-search-forward regexp nil t))
;; No more errors.
(message "No more errors.")
(beep)
(TeX-pop-to-buffer old)
nil)
;; TeX error
((match-beginning 1)
(put-text-property (match-beginning 2) (match-end 2)
'face 'font-lock-warning-face)
(when (match-beginning 2)
(unless TeX-error-file
(push nil TeX-error-file)
(push nil TeX-error-offset))
(unless (car TeX-error-offset)
(rplaca TeX-error-file (TeX-match-buffer 2))))
(if (looking-at "Preview ")
t
(TeX-error)
nil))
;; LaTeX bad box
((match-beginning 7)
(put-text-property (match-beginning 0) (match-end 0)
'face 'font-lock-doc-face)
(if TeX-debug-bad-boxes
(progn
(TeX-warning (TeX-match-buffer 7))
nil)
(re-search-forward "\r?\n\
\\(?:.\\{79\\}\r?\n\
\\)*.*\r?$")
t))
;; LaTeX warning
((match-beginning 8)
(put-text-property (match-beginning 0) (match-end 0)
'face 'font-lock-string-face)
(if TeX-debug-warnings
(progn
(TeX-warning (TeX-match-buffer 8))
nil)
t))
;; New file -- Push on stack
((match-beginning 3)
(let ((file (TeX-match-buffer 3))
(end (match-end 3)))
(put-text-property (match-beginning 0) (match-end 0)
'face 'font-lock-type-face)
;; Strip quotation marks and remove newlines if necessary
(when (or (eq (string-to-char file) ?\")
(string-match "\n" file))
(setq file
(mapconcat 'identity (split-string file "[\"\n]+") "")))
(push file TeX-error-file)
(push nil TeX-error-offset)
(goto-char end))
t)
;; End of file -- Pop from stack
((match-beginning 4)
;; (overlay-put
;; (make-overlay (match-beginning 4) (match-end 4))
;; 'face 'font-lock-warning-face)
(put-text-property (match-beginning 0) (match-end 0)
'face 'font-lock-warning-face)
(when (> (length TeX-error-file) 1)
(when (string= (pop TeX-error-file) "./auctex-bug.tex")
(goto-char (match-end 4)))
(pop TeX-error-offset))
(goto-char (match-end 4))
t)
;; Hook to change line numbers
((match-beginning 5)
(setq TeX-error-offset
(list (string-to-number (TeX-match-buffer 5))))
t)
;; Hook to change file name
((match-beginning 6)
(setq TeX-error-file
(list (TeX-match-buffer 6)))
t)))))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.