It may sound picky, but I'd like to highlight some special messages while compiling LaTeX document by latexmk. For example, these are the first few lines of screen messages when I tried to compile a LaTeX document.

> 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:
Rule 'pdflatex': The following rules & subrules became out-of-date:
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
LaTeX2e <2014/05/01>
Babel <3.9k> and hyphenation patterns for 79 languages loaded.
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class

In this example, I'd like to colorize the following two blocks of latexmk execution messages

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

to distinguish them from the usual LaTeX screen messages.

For colorization, any color will do. For your information, I use bash at Mac OS X.


Stealing from https://stackoverflow.com/questions/510202/apply-formatting-to-unix-shell

If the script ./zz outputs the code in your question then (on terminals supporting "ansi" colour codes)

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"


enter image description here


I use the following trick, which redefines Run_msg to reset the color between calls to subprocesses. In your 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.