繁体   English   中英

Emacs + AUCTeX:如何获得彩色pdflatex输出?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM