From 446f82205a1a1df09b0a13bc1db368c94187eff9 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Wed, 1 Jul 2026 18:23:52 +0200 Subject: [PATCH] Add latexmk colored output --- .latexmkrc | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/.latexmkrc b/.latexmkrc index 189ddf4..ae92ca8 100644 --- a/.latexmkrc +++ b/.latexmkrc @@ -1,5 +1,42 @@ -$pdf_mode = 1; -$pdflatex = "lualatex -shell-escape -interaction=nonstopmode %O %S"; +$pdf_mode = 1; +$pdflatex = +q{lualatex -shell-escape -interaction=nonstopmode %O %S 2>&1 | perl -pe 's/(^!.*)/\e[1;31m$1\e[0m/; s/([Ww]arning)/\e[1;33m$1\e[0m/'}; $out_dir = "build"; $bibtex = "biber %O %S"; $pdf_previewer = "zathura %O %S"; + +# Color output: https://tex.stackexchange.com/questions/617572/is-it-possible-to-make-latexmk-ouput-with-color +{ + no warnings 'redefine'; + use Term::ANSIColor; + + my $old_warn_running = \&main::warn_running; + + sub color_warn_running { + print STDERR color('green'); + $old_warn_running->(@_); + print STDERR color('reset'); + } + + my $old_failure = \&main::failure; + + sub color_failure { + print STDERR color('bold red'); + $old_failure->(@_); + print STDERR color('reset'); + } + + my $old_failure_msg = \&main::failure_msg; + + sub color_failure_msg { + print STDERR color('bold red'); + $old_failure_msg->(@_); + print STDERR color('reset'); + } + + if ( -t STDERR ) { + *main::warn_running = \&color_warn_running; + *main::failure = \&color_failure; + *main::failure_msg = \&color_failure_msg; + } +}