使用 latexmk 编译 LaTeX 文档时的消息突出显示

使用 latexmk 编译 LaTeX 文档时的消息突出显示

这可能听起来很挑剔,但我想在编译 LaTeX 文档时突出显示一些特殊消息,方法是latexmk。例如,当我尝试编译 LaTeX 文档时,这些是屏幕消息的前几行。

> latexmk -pvc -pdf doc 
Latexmk: This is Latexmk, John Collins, 10 Nov 2013, version: 4.39.
**** Report bugs etc to John Collins <collins at phys.psu.edu>. ****
Viewing pdf
Latexmk: applying rule 'pdflatex'...
Rule 'pdflatex': Rules & subrules not known to be previously run:
   pdflatex
Rule 'pdflatex': The following rules & subrules became out-of-date:
  'pdflatex'
------------
Run number 1 of rule 'pdflatex'
------------
------------
Running 'xelatex -interaction=nonstopmode -synctex=1 --shell-escape  -recorder  "doc.tex"'
------------
This is XeTeX, Version 3.14159265-2.6-0.99991 (TeX Live 2014) (preloaded format=xelatex)
 \write18 enabled.
entering extended mode
(./doc.tex
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 79 languages loaded.
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/leqno.clo)
(/usr/local/texlive/2014/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2014/texmf-dist/tex/generic/babel/babel.sty

在此示例中,我想为以下两段 latexmk 执行消息添加颜色

------------
Run number 1 of rule 'pdflatex'
------------
------------
Running 'xelatex -interaction=nonstopmode -synctex=1 --shell-escape  -recorder  "doc.tex"'
------------

以区别于通常的 LaTeX 屏幕消息。

对于着色,任何颜色都可以。供您参考,我在 Mac OS X 上使用 bash。

答案1

窃取https://stackoverflow.com/questions/510202/apply-formatting-to-unix-shell

如果脚本./zz输出问题中的代码,那么(在支持“ansi”颜色代码的终端上)

RED=`echo -en '\e[31m'`
YELLOW=`echo -en '\e[93m'`
RESET=`echo -en '\e[00m'`
./zz | sed -E "s/(^Running.*)/$RED\1$RESET/g;s/(^Run number.*)/$YELLOW\1$RESET/g"

生产

在此处输入图片描述

答案2

我使用以下技巧,重新定义Run_msg在调用子进程之间重置颜色。在你的latexmkrc

use Term::ANSIColor;
$color = 'yellow';

print color($color);

{
    no warnings 'redefine';
    sub Run_msg {
        # Same as Run, but give message about my running
        print color('reset'); # NEW LINE-----
        warn_running( "Running '$_[0]'" );
        my $time1 = processing_time();
        my ($pid, $return) = Run($_[0]);
        print color($color); # NEW LINE------
        my $time = processing_time() - $time1;
        push @timings, "'$_[0]': time = $time\n"; 
        return ($pid, $return);
    } #END Run_msg
}

相关内容