4

I am trying to make a generic environment to use for all my boxes in my document. I want all my boxes to have line numbers. I can only get this to work some of the time. I don't get line numbers when I use minted content in the box.

\documentclass{article}

\usepackage{lineno}
\usepackage{tcolorbox}
\tcbuselibrary{minted, breakable, skins}

\definecolor{darkgray}{gray}{0.15}
\definecolor{gray}{gray}{0.30}

\newenvironment{mylisting}[1]
{
    \begin{tcolorbox}[
        title=#1,
        listing only,
        breakable,
        colframe=gray,
        colbacktitle=gray,
        colback=darkgray,
        enhanced,
        left=0.3125in,
        overlay={
            \begin{tcbclipinterior}
                \fill[gray] (frame.south west) rectangle ([xshift=0.25in]frame.north west);
            \end{tcbclipinterior}}]
        \begin{internallinenumbers}
}
{
        \end{internallinenumbers}
    \end{tcolorbox}
}

\begin{document}
    \begin{mylisting}{Test Line Numbers}
        Test

        the

        line

        numbers.
    \end{mylisting}
    \begin{mylisting}{Test Minted Line Numbers}
        \mint{cpp}|hi|
    \end{mylisting}
\end{document}

The first usage works, but the second usage with the \mint command does not. What am I missing?

PS - I'm aware that minted can do its own line numbering, but I wanted to handle line numbering in a centralized way, and not everything in a listing will be minted, so I figured the line numbering could be decoupled from minted.

  • 1
    I think that this is purely about interaction between lineno and minted (independent of tcolorbox). I just made some tests and it seems that internallinenumbers has no effect on any minted content. Maybe, someone know how to change that (?) – Thomas F. Sturm Dec 4 '14 at 16:04
  • Interesting. I didn't notice that. Good catch. I wonder if it is just minted, or other similar things too. – Aaron Wright Dec 5 '14 at 3:29
  • @ThomasF.Sturm Any news about this? – egreg Sep 5 '15 at 21:10
  • @egreg No, I don't think so. lineno and minted are not compatible as far as I know. – Thomas F. Sturm Sep 15 '15 at 11:07
  • @ThomasF.Sturm Has anything changed now? – TeXnician Apr 15 '17 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.