From a47e4a3766b7f864d1cbdebf0faace7e0e14763e Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Thu, 18 Oct 2012 20:41:23 +0200 Subject: [PATCH] Add automatic color package loading for listings The listings inset does automatically load the color package if any parameter contains \color. As mentioned in bug #8066 tex2lyx needs to be aware of this, so the \usepckage{color} is automatically skipped in these cases. --- src/tex2lyx/test/test-insets.tex | 2 +- src/tex2lyx/text.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tex2lyx/test/test-insets.tex b/src/tex2lyx/test/test-insets.tex index 487effa933..8052c727c5 100644 --- a/src/tex2lyx/test/test-insets.tex +++ b/src/tex2lyx/test/test-insets.tex @@ -169,7 +169,7 @@ parser test (escaped):\href{http://www.test.test}{a brace \} and another one \{ \section{Listings} -Inline: \lstinline[language={C++}]!int a=5;!\\ +Inline: \lstinline[language={C++},keywordstyle={\color{green}}]!int a=5;!\\ Float: \begin{lstlisting}[caption={Example Listing float},label={lst:Example-Listing},language=Python] diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 4d01a0e26a..3a2e493f8c 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -1114,6 +1114,12 @@ void parse_listings(Parser & p, ostream & os, Context & parent_context) { parent_context.check_layout(os); begin_inset(os, "listings\n"); + if (p.hasOpt()) { + string arg = p.verbatimOption(); + os << "lstparams " << '"' << arg << '"' << '\n'; + if (arg.find("\\color") != string::npos) + preamble.registerAutomaticallyLoadedPackage("color"); + } os << "inline false\n" << "status collapsed\n"; Context context(true, parent_context.textclass); -- 2.39.5