Is it possible to add non-number characters on the left of a code block?
Specifically, I want to add ...
to correspond with some source code (see image).
I am currently using commands to stop / start the line numbers. Here is the code:
\documentclass[12pt]{article}
\usepackage[a4paper, margin = 20mm, top = 30mm, bottom = 25mm]{geometry}
\usepackage{xcolor, soul}
\usepackage{listings}
\definecolor{codebackground}{rgb}{0.95, 0.95, 0.92}
\lstset
{
frame = tb, % hrule above and below
keepspaces = true,
columns = flexible,
basicstyle = {\normalsize\ttfamily},
escapeinside = {(*@}{@*)}, % for escaping
backgroundcolor = \color{codebackground},
showstringspaces = false,
language = C,
keywordstyle = \color{blue},
stringstyle = \color{red},
commentstyle = \color{teal},
numbers = left, % {none, left, right}
firstnumber = 1,
numberstyle = \scriptsize\color{black},
numbersep = 5pt
}
\let\origthelstnumber\thelstnumber
\makeatletter
% for stopping line numbers
\newcommand*\stopnumber
{
\lst@AddToHook{OnNewLine}
{
\let\thelstnumber\relax
\advance\c@lstnumber-\@ne\relax
}
}
% for starting line numbers
\newcommand*\startnumber[1]
{
\setcounter{lstnumber}{\numexpr#1-1\relax}
\lst@AddToHook{OnNewLine}
{
\let\thelstnumber\origthelstnumber
\refstepcounter{lstnumber}
}
}
\makeatother
\begin{document}
\begin{lstlisting}[firstnumber = 456]
int third_function(const int c)
{
/* error checking */
if(c < 0)
{
return;
} (*@ \stopnumber @*)
...
(*@ \startnumber{512} @*)
/* other stuff */
int d = 4;
char* word = "third function"; (*@ \stopnumber @*)
...
(*@ \startnumber{678} @*)
return (c * d);
}
\end{lstlisting}
\end{document}