I have done some extensive searching and have yet to find the answer to changing the color for lstset morekeywords. I want them to be a different color than my regular keywords. Here is what I have right now:
\documentclass{article}
\usepackage{listings,lstautogobble}
\usepackage[usenames,dvipsnames]{color}
% Custom Python Syntax
\lstset
{
basicstyle=\small\ttfamily,
commentstyle=\color{Green},
keywordstyle=\color{Cerulean},
frame=single,
language=python,
morekeywords={True, False},
numbers=left,
numbersep=10pt,
numberstyle=\footnotesize\color{Gray},
showstringspaces=false,
stringstyle=\color{Mulberry},
tabsize=3,
}
% Color Numbers
\lstset
{
literate=%
{0}{{{\color{Orange}0}}}1
{1}{{{\color{Orange}1}}}1
{2}{{{\color{Orange}2}}}1
{3}{{{\color{rOrange}3}}}1
{4}{{{\color{Orange}4}}}1
{5}{{{\color{Orange}5}}}1
{6}{{{\color{Orange}6}}}1
{7}{{{\color{Orange}7}}}1
{8}{{{\color{Orange}8}}}1
{9}{{{\color{Orange}9}}}1
}
\begin{document}
% A basic function that tests if a number is prime
\lstinputlisting{isPrime.py}
\end{document}
Which produces the following result
As you can see on lines 16 and 17 True and False are the same color as return and right next to each other. I am just wondering if I could just change the color of selected keywords. For instance changing True and False to a darker blue or another color entirely.
Also: This is less of a concern but is there a better way to change the color of the numbers (not the line numbers, the numbers in the code)? What I have clearly works but I feel like it's a little inefficient.
\documentclass{...}
and ending with\end{document}
.morekeywords
merely adds more keywords to the existing list; it won't allow you to giveTrue
andFalse
a distinct style from the existing one. If you want to create additional but separate lists of keywords, each list with a distinct style, you should check out tex.stackexchange.com/questions/148193/…filecontents
package, you will be able put the contents ofisPrime.py
inside a\begin{filecontents*}{isPrime.py} ... \end{filecontents*}
environment.for val in range(1, num)
.