[LyX/master] Track whether a latex rerun is needed with minted.

Juergen Spitzmueller <[email protected]> Sat, 25 Jul 2026 15:26:33 +0000
Newsgroups gmane.editors.lyx.cvs
Message-ID <[email protected]>
commit 5caf79a0973dd3353067b1245ed9a7a3fad1f07a
Author: Juergen Spitzmueller <[email protected]>
Date:   Sat Jul 25 17:25:29 2026 +0200

    Track whether a latex rerun is needed with minted.
    
    Alas, minted does not output a proper log message, so we need to
    check for existing *.minted files
---
 src/LaTeX.cpp | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/LaTeX.cpp b/src/LaTeX.cpp
index c1a855c40c..065bf20cb3 100644
--- a/src/LaTeX.cpp
+++ b/src/LaTeX.cpp
@@ -857,6 +857,8 @@ int LaTeX::scanLogFile(TeXErrors & terr)
 	static regex const file_line_error(".+\\.\\D+:[0-9]+: (.+)");
 	static regex const child_file("[^0-9]*([0-9]+[A-Za-z]*_.+\\.tex).*");
 	static regex const undef_ref(".*Reference `(.+)\\' on page.*");
+	static regex const minted_data("\\\\openout[0-9]+.*=.*`(.+)(..).*data\\.minted'\\.");
+	static regex const minted_highlight("\\(\\./.*highlight\\.minted");
 	// Flag for 'File ended while scanning' message.
 	// We need to wait for subsequent processing.
 	string wait_for_error;
@@ -869,6 +871,8 @@ int LaTeX::scanLogFile(TeXErrors & terr)
 
 	string token;
 	string ml_token;
+	bool have_minted_data = false;
+	bool have_minted_highlight = false;
 	while (getline(ifs, token)) {
 		// MikTeX sometimes inserts \0 in the log file. They can't be
 		// removed directly with the existing string utility
@@ -1042,13 +1046,16 @@ int LaTeX::scanLogFile(TeXErrors & terr)
 				LYXERR(Debug::OUTFILE, "We should rerun.");
 				retval |= RERUN;
 			}
+		} else if (regex_match(token, sub, minted_data)) {
+			have_minted_data = true;
 		} else if (token[0] == '(') {
 			if (contains(token, "Rerun LaTeX") ||
 			    contains(token, "Rerun to get")) {
 				// Used by natbib
 				LYXERR(Debug::OUTFILE, "We should rerun.");
 				retval |= RERUN;
-			}
+			} else if (regex_match(token, sub, minted_highlight))
+				have_minted_highlight = true;
 		} else if (prefixIs(token, "! ")
 			    || (fle_style
 				&& regex_match(token, sub, file_line_error)
@@ -1250,6 +1257,10 @@ int LaTeX::scanLogFile(TeXErrors & terr)
 			}
 		}
 	}
+	// If we found a *data.minted but no *highlight.minted file
+	// we need another run to get proper minted output
+	if (have_minted_data && !have_minted_highlight)
+		retval |= RERUN;
 	LYXERR(Debug::OUTFILE, "Log line: " << token);
 	return retval;
 }
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs