I have some style references to use style in python highlighted code:
or
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
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:
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\usepackage{tikz}
\newcommand\circled[3]{%
\tikz[baseline=(char.base)]{
\node[shape=circle, fill=#1, inner sep=0pt, text width=8pt, align=center]
(char) {\textcolor{#2}{\sffamily\bfseries\scriptsize #3}};
}%
}
\newcommand\lstnote[1]{%
\kern 1.5em%
\circled{purple}{pink!50!white}{#1}%
}
\newcommand\circledstyle[1]{%
\circled{gray}{white}{#1}%
}
\lstset{
basicstyle = \ttfamily,
language = [LaTeX]TeX,
texcsstyle = *\color{blue},
escapeinside = {<@}{@>},
backgroundcolor = \color{lightgray!30!white},
framexleftmargin = 3em,
framerule = 0pt,
frame = tb,
numbers = left,
numberstyle = \circledstyle
}
\begin{document}
\begin{lstlisting}
\documentclass{article} <@ \lstnote{1} @>
\usepackage{xcolor} <@ \lstnote{2} @>
\begin{document}
\textcolor{blue}{Hello world!} <@ \lstnote{3} @>
New paragraph.
And another one.
\end{document}
\end{lstlisting}
\end{document}
\input
it or even create a new package for them
escapeinside
. (The first one seems to be moreminted
-like, the second one morelstlisting
-like.) What have you tried so far?minted
? but I would like you to make an example