There are at least four issues with your listings
settings.
You load the C
language too late. Loading a language discards most of the listings
tweaks that were performed (using \lstset
) beforehand. You must load the language first, and only then customise the appearance. I recommend you define your own style, for convenience.
You're trying to define things like "DSP28x_Project.h"
as keywords. This is awkward because listings
doesn't allow (by default) "
in identifiers, and because the C
language uses "
as string delimiter. If what you want is to highlight C string literals in blue, you should simply tell listings
what of your prefered string style is:
stringstyle = \color{blue},
You're trying to define things like ePWM_config()
as keywords. By default, listings
does not allow parentheses to be part of identifiers, for good reason. There are cases where you might want to override that behaviour (see this answer for an example), but that's unwarranted here. Moreover, parentheses don't seem to be in boldface in your screenshot. Simply define ePWM_config
(not ePWM_config()
) as a keyword.
You use a font family that does not come with a boldface typewriter font. TeX font families, such as Computer Modern (which is used by default in LaTeX), do not provide a boldface typewriter font. When listings
attempts to typeset stuff in bold typewriter, TeX complains that no such font is available and uses the "normal" (i.e. medium-series) typewriter font instead. To remedy that problem, you must use a font family that comes with boldface typewriter font. A popular choice is Bera Mono. Inserting the following lines in your preamble tells LaTeX to use Bera Mono as typewriter font throughout your LaTeX document.
\usepackage[T1]{fontenc}
\usepackage[scaled=0.85]{beramono}
Edit: if you want the typewriter font to be Bera Mono only in your listings, not in the rest of the document, use something like this:
basicstyle = \footnotesize\def\fvm@Scale{.85}\fontfamily{fvm}\selectfont

Complete code
\documentclass[12pt,a4paper]{report}
\usepackage{listings}
\usepackage{xcolor}
\usepackage[T1]{fontenc}
\definecolor{mygreen}{rgb}{0,0.5,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{byzantium}{rgb}{0.44, 0.16, 0.39}
\makeatletter
\lstdefinestyle{myCstyle}{
language = C,
basicstyle = \footnotesize\def\fvm@Scale{.85}\fontfamily{fvm}\selectfont,
numbers = left,
numberstyle = \color{mygray},
commentstyle = \color{mygreen},
keywordstyle = \bfseries\color{byzantium},
keywordstyle =[2]\bfseries,
keywordstyle =[3]\color{blue},
stringstyle = \color{blue},
morekeywords = {},
directivestyle = \color{violet}\bfseries,
morekeywords =[2]{ePWM_config,ePWM},
morekeywords =[3]{PCLKCR0,bit,TBCLKSYNC},
title = ePWM.c,
}
\makeatother
\begin{document}
{
\ttfamily
This should be typeset in Computer Modern typewriter font,
contrary to C listings, which should be typeset in scaled-down Bera Mono font.
}
\begin{lstlisting}[style=myCstyle]
#include "DSP28x_Project.h"
static void ePWM_config();
#define deadband 76;
void ePWM()
{
// Stop the Time Base Clock
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
EDIS;
// configure the ePWM
ePWM_config();
// Enable the Time Base Clock
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;
}
\end{lstlisting}
\end{document}