I have some style references to use style in python highlighted code: enter image description here


enter image description here

Can you achieve this type of style with minted or listings? By the way, the language is Python.

please give an example of how it is used

  • 2
    This should be possible using both packages and some options like escapeinside. (The first one seems to be more minted-like, the second one more lstlisting-like.) What have you tried so far?
    – epR8GaYuh
    Jun 27, 2019 at 12:15
  • Just for clarity, you are asking about how to add these circled numbers to your listings?
    – siracusa
    Jun 27, 2019 at 14:47
  • @siracusa Yes, My question is as achievement this design with the package minted? but I would like you to make an example
    – royer
    Jun 27, 2019 at 16:46
  • 1
    You received an answer, but we generally like to see some sort of effort on the part of those asking questions (much more than just posting two pictures). It would have been preferable to also include the TeX code you used to create the output you showed us.
    – Teepeemm
    Jun 27, 2019 at 23:44

1 Answer 1


A solution sketch using the listings package

As suggested in the comments, with the listings package you can use the escapeinside option to escape from the verbatim typesetting context to call a macro that outputs a circled number.

The \circled macro is inspired by this answer but with some additions to make the circles have a fixed size. Also the background and text color can be passed as a parameter.

For the circled notes after certain lines in the listing, escapeinside = {<@}{@>} was set to escape the listing. Within those delimiters we then can use the \lstnote{...} macro to add a fixed amount of spacing plus the number in a circle.

For the circled line numbers another macro \circledstyle was defined. We make listings typeset line numbers using this style by adding the numberstyle = \circledstyle option.

The full example document:


        \node[shape=circle, fill=#1, inner sep=0pt, text width=8pt, align=center]
            (char) {\textcolor{#2}{\sffamily\bfseries\scriptsize #3}};

    \kern 1.5em%


    basicstyle = \ttfamily,
    language = [LaTeX]TeX,
    texcsstyle = *\color{blue},
    escapeinside = {<@}{@>},
    backgroundcolor = \color{lightgray!30!white},
    framexleftmargin = 3em,
    framerule = 0pt,
    frame = tb,
    numbers = left,
    numberstyle = \circledstyle

\documentclass{article} <@ \lstnote{1} @>
\usepackage{xcolor}  <@ \lstnote{2} @>

\textcolor{blue}{Hello world!} <@ \lstnote{3} @>

New paragraph.

And another one.

enter image description here

  • 1
    Perfect your code and explanations! :-)
    – Sebastiano
    Jun 27, 2019 at 21:47
  • Oh great, can you configure it from an external file of the "code.tex" code?
    – royer
    Jun 28, 2019 at 1:57
  • @royer Sure, you can put the definitons into another file and \input it or even create a new package for them
    – siracusa
    Jun 28, 2019 at 12:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .