Are you after something like this? I have provided new keys:
widthgobble
, which takes as an argument #tabs*#tabsize
firstlineandnumber
, which sets both firstline
and firstnumber
Note that I had some trouble using the *
syntax for setting the length of \gobble
so have implemented an ugly workaround (which currently means that the argument to widthgobble
should always have two numbers separated by an asterisk):
\documentclass{article}
\usepackage{listings}
\usepackage{filecontents}
\begin{filecontents*}{hello1.c}
if (a<b){
if (b<a){
//do something
}
}
\end{filecontents*}
\errorcontextlines=\maxdimen
\lstset{tabsize=3,numbers=left,frame=single,basicstyle=\Huge\ttfamily,columns=flexible}
\newlength{\rawgobble}
\newlength{\gobble}
\newlength{\gobblea}
% The width of a single space. basicstyle from lstset should be used
\sbox0{\Huge\ttfamily \ }
% Remove a single space
\settowidth{\rawgobble}{\Huge\ttfamily \ }
\setlength{\rawgobble}{-\rawgobble}
\makeatletter
\def\sepstar#1*#2\relax{%
\def\sepstarone{#1}%
\def\sepstartwo{#2}%
}
\lst@Key{firstlineandnumber}\relax{\def\lst@firstline{#1\relax}\def\lst@firstnumber{#1\relax}}
\lst@Key{widthgobble}{0*0}{%
% Reindent a bit by multiplying with 0.9, then multiply by tabsize and number of indentation levels
\sepstar #1\relax
\setlength{\gobble}{0.9\rawgobble}%
\setlength{\gobble}{\sepstarone\gobble}%
\setlength{\gobble}{\sepstartwo\gobble}%
\setlength{\gobblea}{\gobble}%
\addtolength{\gobblea}{10pt}%
\def\lst@xleftmargin{\gobble}%
\def\lst@framexleftmargin{\gobble}%
\def\lst@numbersep{\gobblea}%
}
\makeatother
\begin{document}
%widthgobble=#tabs*#tabsize,firstlineandnumber sets firstline and firstnumber
\lstinputlisting[widthgobble=1*3,firstlineandnumber=2,lastline=4]{hello1.c}
\end{document}
You can use
keywords=[<number>]{<list of keywords>}
to add another set of keywords and then
keywordstyle={[<number>]<style commands>},
to give a style for this new set.
Since I didn't have the original definitions for your colors nor of the \ttb command, in the example below I used some own settings, but you can easily use your own settings; the code was randomly taken, just for this example.
\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{bera}% optional; just for the example
\lstset{
language=Python,
basicstyle=\ttfamily,
otherkeywords={self},
keywordstyle=\ttfamily\color{blue!90!black},
keywords=[2]{True,False},
keywords=[3]{ttk},
keywordstyle={[2]\ttfamily\color{yellow!80!orange}},
keywordstyle={[3]\ttfamily\color{red!80!orange}},
emph={MyClass,__init__},
emphstyle=\ttfamily\color{red!80!black},
stringstyle=\color{green!80!black},
showstringspaces=false
}
\begin{document}
\begin{lstlisting}
def under_attack(col, queens):
left = right = col
for r, c in reversed(queens):
left, right = left - 1, right + 1
if c in (left, col, right):
return True
return False
print 'This generation has {0} babies'.format(babies)
ttk.Button(buttonframe,width = 3,
textvariable=guivars["%s %s" %(current, item)],
command=lambda: remoteButton(current, item))
\end{lstlisting}
\end{document}
Please notice that "ttk" is being treated as a keyword with red color, as was also requested.
Best Answer
You need a font that has a bold version of the typewriter family. If you look in the
.log
file you will find:A recent new choice of typewriter font with a bold version is provided by the
newtxttt
package:An alternative is the
zlmtt
package:which fits better with the standard computer modern fonts of LaTeX.
If you do not wish to change fonts in this way and just want to use the ordinary bold font, then you should switch to
\rmfamily
before selecting\bfseries
: