# Listings: line number separator rule

Here I found a similar question with horizontal rule, which answer I don't understand to a degree I could use it to solve my problem:

Adding a horizontal rule between caption and lstlisting inside a tcolorbox

I am looking for a separator rule for line numbers when the frame rule has already been extended to include the line numbers (Would be nice if it was possible with just the listings package). See this example:

## Minimal working example:

\documentclass{report}

\usepackage{xcolor}
\definecolor{halfgray}{gray}{0.55}
\definecolor{ipython_frame}{RGB}{207, 207, 207}

\usepackage{listings}

\lstdefinelanguage{iPython}{
stringstyle=\color{red}\ttfamily,
keepspaces=true,
showspaces=false,
showstringspaces=false,
%
rulecolor=\color{ipython_frame},
frame=single,
frameround={t}{t}{t}{t},
framexleftmargin=6mm,
numbers=left,
numberstyle=\tiny\color{halfgray},
%
basicstyle=\scriptsize\ttfamily,
keywordstyle=\color{green}\ttfamily,
}

\begin{document}
\begin{lstlisting}[language=iPython]
import math
import numpy as np
from lib.analytical import csa

sin2_theta  = np.sin(theta)**2
+= -= *= /= + - * / ? < > & % == <=
# += -= *= /= + - * / ? < > & % == <=
def test(a=100, b=True):
<= >= == 2 + 3j * 7e-3
\end{lstlisting}
\end{document}

• Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – jub0bs Mar 30 '15 at 1:10
• That is already there! Just see the second linked question Listings: recognize numbers and 1e-3. I added the words "minimal working" so it might become more of an eye-catcher. – gr4nt3d Mar 30 '15 at 9:31
• On this site, each question should be more or less standalone and should have its own MWE (when appropriate). Besides, the question you link to contains code that is far from minimal for the present question. – jub0bs Mar 30 '15 at 9:36
• The MWE is not the complete language definition anymore, but just code with some frame. – gr4nt3d Mar 30 '15 at 9:47
• That's much better :) – jub0bs Mar 30 '15 at 9:57

A rather hacky solution is to use tcolorbox for the border so that you can use listings frame for the rule. Tcolorbox provides a library for boxes that contain listings and minted codes. Below is a minimal setting but you have lots of room for improvement since tcolorboxes are highly customizable:

\documentclass{report}

\usepackage{xcolor}
\definecolor{halfgray}{gray}{0.55}
\definecolor{ipython_frame}{RGB}{207, 207, 207}
\usepackage{tcolorbox}

\tcbuselibrary{listings}%
\usepackage{lipsum}
\usepackage{listings}
\tcbset{listing engine={listings}}

\lstdefinelanguage[]{iPython}[]{python}{
stringstyle=\color{red}\ttfamily,
keepspaces=true,
showspaces=false,
showstringspaces=false,
%
rulecolor=\color{ipython_frame},
frame=l,
numbers=left,
numberstyle=\tiny\color{halfgray},
xleftmargin={0.75cm},
%
basicstyle=\scriptsize\ttfamily,
keywordstyle=\color{green}\ttfamily,
}

\begin{document}
\lipsum[1]
\begin{tcblisting}{boxrule=1pt, listing only,listing options={language=iPython}}
import math
import numpy as np
from lib.analytical import csa

sin2_theta  = np.sin(theta)**2
+= -= *= /= + - * / ? < > & % == <=
# += -= *= /= + - * / ? < > & % == <=
def test(a=100, b=True):
<= >= == 2 + 3j * 7e-3
\end{tcblisting}
\lipsum[2]
\end{document}


Which will give you this:

A quick note on defining new language in listings: You can use a base dialect for the new language so you don't need to define all the keywords from scratch.

\lstdefinelanguage
[[hdialecti]]{hlanguagei}
[[hbase dialecti]{hand base languagei}]
{hkey=value listi}

hence \lstdefinelanguage[]{iPython}[]{python}.
• This package seems to be either badly documented or corrupted. If I copy the command for "Producing tcblisting Environments" NewTCBListing I am getting an error. -> It has to be lower case newtcblisting. "Producing tcbinputlisting Commands" however is not working at all for me. Then you never really know what code is actually necessary or producing which part of the examples... I am a bit lost searching for the tcbinputlisting. – gr4nt3d Mar 30 '15 at 20:22
• Turns out this 'kinda works': \newtcbinputlisting[]{iPython}{ colframe=ipython_frame, colback=ipython_bg, left=0pt, top=-9pt, bottom=-9pt, boxrule=0.4pt, listing only, listing options={language=iPython}, }{} Yields an error though, not being able to find document.listing(.tex) when I try to use \iPython{test.py}. Input is crucial, since it's a good way to keep an oversight of different source codes right after another, imho. – gr4nt3d Mar 30 '15 at 20:34
• Well, I don't know how to describe it further. See tcolorbox.18.5. I would like to use \newtcbinputlisting to create a lstinputlisting-like command, which yields the above mentioned error though. The final product should be an style-file for iPython that I can reuse with a simple input and environment command. – gr4nt3d Apr 5 '15 at 13:58