2

How to make lines code numbering uncopiable and white (or any other color)?

% arara: pdflatex: {shell: 1}
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings}
\usepackage{minted}
\usepackage{xcolor}
\usepackage{tcolorbox}
\tcbuselibrary{listings, minted, skins}

\tcbset{listing engine=minted}

\newtcblisting{javalst}{listing only, minted language=java, minted style=paraiso-dark, colback=bg, enhanced, frame hidden, minted options={numbersep=2.5mm, fontfamily=fdm, linenos, fontsize=\footnotesize, tabsize=2, breaklines, autogobble}, overlay={% \begin{tcbclipinterior} \fill[bg] (frame.south west) rectangle ([xshift=4mm]frame.north west); \end{tcbclipinterior} }}

\definecolor{inline}{RGB}{187,57,82} \definecolor{bg}{RGB}{22,43,58} \setminted[java]{bgcolor=bg, fontfamily=fdm, fontsize=\footnotesize}

\begin{document}

\begin{javalst} public class ClassName { public static void main(String[] args) { System.out.println(args); } } \end{javalst} \end{document}

enter image description here

Ingmar
  • 6,690
  • 5
  • 26
  • 47
WinnieNotThePooh
  • 3,008
  • 1
  • 7
  • 14
  • 1
    If I understand correctly, you are looking for this nice answer by @ulrike-fischer – Rmano Apr 05 '23 at 10:32
  • @Rmano thank You for the comment, but unfortunately the numbering of code is still copiable, according to your link, moreover couldn't implement the code suggested by ulrike-fischer into mine properly, thanks for any help – WinnieNotThePooh Apr 06 '23 at 09:32
  • That code is the one I use for the circuitikz manual --- Notice that the behavior is reader-dependent: the embedded PDF viewer in Firefox also copies the numbers but evince or okular work ok and copy just the code. – Rmano Apr 06 '23 at 11:33
  • Ah, but clearly adapting it to minted is not trivial at all, you are right. Hmmm.... – Rmano Apr 06 '23 at 12:10

1 Answers1

0

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings}
\usepackage{minted}
\usepackage{xcolor}
\usepackage{tcolorbox}
\tcbuselibrary{listings, minted, skins}

\tcbset{listing engine=minted}

\renewcommand{\theFancyVerbLine}{\textcolor[rgb]{1,1,1}{\texttt\footnotesize\arabic{FancyVerbLine}}}%<--- just add this line

\newtcblisting{javalst}{ listing only, minted language=java, minted style=paraiso-dark, colback=bg, enhanced, frame hidden, minted options={ fontsize=\footnotesize, tabsize=2, breaklines, autogobble, linenos, numbersep=5pt, fontsize=\small, }, overlay={\begin{tcbclipinterior}\fill[bg](frame.south west)rectangle([xshift=5mm]frame.north west);\end{tcbclipinterior}}

}

\definecolor{inline}{RGB}{187,57,82} \definecolor{bg}{RGB}{22,43,58} \setminted[java]{bgcolor=bg, fontfamily=fdm, fontsize=\footnotesize}

\begin{document}

\begin{javalst} public class ClassName { public static void main(String[] args) { System.out.println(args); } } \end{javalst}

\end{document}

WinnieNotThePooh
  • 3,008
  • 1
  • 7
  • 14