2

Currently I am trying to work with the minted package. My aim is to have a code snippet with the numbering for each line, which is centered in a figure.

My top level configuration looks like following:

\documentclass[parskip=full, fontsize=12pt, twoside=false]{scrreprt}

\usepackage{graphicx}
\usepackage{minted}
\setminted{linenos=true}
\RecustomVerbatimEnvironment{Verbatim}{BVerbatim}{}

\begin{document}
\begin{figure}[!htb]
    \centering
    \begin{minted}{javascript}
    let Parser = require('rss-parser');
    let parser = new Parser();
    \end{minted}
\end{figure}
\end{document}

The result looks like this: Minted package looses numbering

The good thing is that it is centered in the document but the bad thing is that the numbering is missing.

If i comment out following line i get the numbering but the code is not centered anymore.

%\RecustomVerbatimEnvironment{Verbatim}{BVerbatim}{}

Result looks like following then: enter image description here

So is there any way how i can achieve both options? Centered and numbered? Hopefully someone has an answer! :)

  • 2
    Don't show only snippets but a complete document that can be compiled and tested. – Ulrike Fischer Dec 9 '18 at 15:36
  • I Changed it! :) – Dariusch Dec 9 '18 at 17:29
4

I don't think that BVerbatim can be numbered in the standard way, but you could try this

\documentclass[parskip=full, fontsize=12pt, twoside=false]{scrreprt}

\usepackage{graphicx}
\usepackage{minted}
\setminted{linenos=true}
\newcommand\mynumberformat{\def\FancyVerbFormatLine##1{{\theFancyVerbLine} ##1}}
\RecustomVerbatimEnvironment{Verbatim}{BVerbatim}
{formatcom=\mynumberformat}

\begin{document}

\begin{figure}[!htb]
    \centering
    \begin{minted}{javascript}
    let Parser = require('rss-parser');
    let parser = new Parser();
    \end{minted}
\end{figure}
\end{document}

enter image description here

  • @egreg Oh I see you found the solution, thanks. – Ulrike Fischer Dec 9 '18 at 23:22
  • The definition of \theFancyVerbLine is \def\theFancyVerbLine{\rmfamily\tiny\arabic{FancyVerbLine}} and you can guess what the problem was. – egreg Dec 9 '18 at 23:23
  • @egreg grumpf. Who makes such definitions? I think I will complain ... – Ulrike Fischer Dec 9 '18 at 23:27
  • What would the definition look like, if it was better or even perfect? Is there just a \space missing at the end or what is the issue? – thymaro Dec 10 '18 at 10:03
  • 1
    @thymaro an additional pair of braces is missing, as it is it implicitly assumes that the \rmfamily has no side effects. – Ulrike Fischer Dec 10 '18 at 10:09

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.