2
votes

I need to insert Java/Android code into Latex/Lyx, and I would like to highlight Java comments with a certain colour. I have done it earlier in the document, but now when I try the same code, it is not working for some reason. One difference between the codes are, that the one I'm now trying to insert is Android Java-code, and the former was pure Java, could that have an affect? The settings I'm using in the both cases are these:

\def\listingsfont{\ttfamily}
\lstset{language=Java}
\lstset{basicstyle=\ttfamily\scriptsize}
\lstset{keywordstyle=\color{blue}\ttfamily}
\lstset{stringstyle=\color{red}\ttfamily}
\lstset{commentstyle=\color{green}\ttfamily}
\lstset{breaklines=true}
\lstset{tabsize=2}
\begin{lstlisting}[frame=single]  % Start your code-block 

So first time working, second time not any more. What happens is, that all comment marks (//) appear as blue, but only the marks, not the whole comments with them. Strings are highlighted correctly.

EDIT: I have gained some new information what is happening. After the first time, when this code was working, I have a latex code where language is set as R. If I insert this code before the code that is written in R, all is working as it should. But if I insert the code after the code that is written in R, then it is no longer working. So something weird happens there.

EDIT2: For testing purposes, I changed the settings for the R-code as (language=Java). What happened was, that after that, all the Java code in the latex appeared correctly. So apparently, setting language as R breaks Lyx/Latex somehow to not being able to highlight other languages.

1

1 Answers

0
votes

If you use \lstset, this is the default for the whole document. Try setting the language of each listing in LyX separate instead (through the settings you reach in the context menu of the program listing)