Usually when adding code in a LaTeX document, I use the listings package. When trying to modify and personalise styles in listings, @1010011010 suggested to use the minted package.
To be quite frank, I was impressed! I've managed to install it and make it work according to my needs and taste. I've added line numbers and used the mdframed package to add colored background that breaks along pages. At the moment I am trying to break a line when it's too large to fit within the \textwidth. I used @MarcoDaniel 's answer on Box around minted environment to break the lines but it's not working as expected.
My code is
\documentclass{book}
\usepackage[]{minted}
\usepackage{tcolorbox}
\usepackage{lineno}
\usepackage{mdframed}
\def\gobble#1{}
\renewcommand\DeleteFile[1]{}
\usepackage{xparse}
\ExplSyntaxOn
\box_new:N \l_fvrb_box
\tl_new:N \l_fvrb_tl
\RenewDocumentCommand \FancyVerbFormatLine { m }
{
\hbox_set:Nn \l_fvrb_box { #1 }
\dim_compare:nNnTF { \box_wd:N \l_fvrb_box }>{ \linewidth }
{%box to big
\tl_set:Nn \l_fvrb_tl { #1 }
\fvrb_use_tl:N \l_fvrb_tl
}
{%box fits
\box_use:N \l_fvrb_box
}
}
\cs_new:Npn \fvrb_use_tl:N #1
{
\group_begin:
\null\hfill\vbox_set:Nn \l_fvrb_box
{\hsize=\linewidth
\renewcommand\thelinenumber
{
\ifnum\value{linenumber}=1\relax\else
$\rightarrow$
\fi
}
\begin{internallinenumbers}
\advance\hsize by -2em
\hspace*{-2em}\tl_use:N #1
\end{internallinenumbers}
}
\box_use:N \l_fvrb_box
\group_end:
}
\ExplSyntaxOff
\usepackage{etoolbox}
\usepackage{xcolor}
\definecolor{lbcolor}{rgb}{0.9,0.9,0.9}
\usepackage[margin=2.8cm]{geometry}
\begin{document}
\section{Section}
\begin{minted}[linenos=true,bgcolor=lbcolor,numberblanklines=true,showspaces=false]{java}
int slotADC = 22;// Change CAMAC controller's backpanel jumper, accordingly
int count = 0;
int[] data = new int[1];
int[] offset = {0, 0};
int[] in = {1, 2};
int[] ones = {1,1};
report.setProperty("INSERT", "["+now.format(new Date())+"] Acquisition Started\n");
report.setProperty("INSERT", "["+now.format(new Date())+"] I am set to read "+evSize+" detectors.\n");
Initialize();
\end{minted}
\begin{mdframed}[linecolor=black, topline=true, bottomline=true,
leftline=false, rightline=false, backgroundcolor=lbcolor,userdefinedwidth=\textwidth]
\begin{minted}[fontsize=\normalsize, linenos, frame=lines]{java}
import java.awt.event.*;//for ActionListener
public class Runtime implements KmaxRuntime {
KmaxToolsheet tlsh;//Store a reference to the toolsheet environment
KmaxWidget wSlot;
KmaxWidget wAdd;
KmaxWidget wData;
KmaxWidget dataField;
KmaxWidget countField;
KmaxWidget setSRQ;
KmaxDevice dev;
KmaxHist hist1,hist2,hist3,hist4,hist5,hist6, histoLowX, histoLowY;
KmaxHist dee1;
KmaxWidget report;
KmaxWidget liveTime;
KmaxWidget realTime;
KmaxWidget deadTime;
KmaxWidget progress;
KmaxWidget xcombo, ycombo, offsetButton;
KmaxWidget combo, checkBoxCalib;
/** ADC Levels */
KmaxWidget lld;
KmaxWidget setLLD;
KmaxWidget getLLD;
KmaxWidget lldText;
KmaxWidget uld;
KmaxWidget setULD;
KmaxWidget getULD;
KmaxWidget uldText;
/** Calibration - Check Box(use calibration) */
boolean eventFileOn = true;
int slotADC = 22;// Change CAMAC controller's backpanel jumper, accordingly
int count = 0;
int[] data = new int[1];
int[] offset = {0, 0};
int[] in = {1, 2};
int[] ones = {1,1};
int points = 10;
int[] region = new int[points];
int timeTicks;
int totalTime;
int LiveTime = 0;
int totcount;
int evType = 1; //The Type ID for these kinds of events
SimpleDateFormat today = new SimpleDateFormat("dd/MM/yyyy");
SimpleDateFormat now = new SimpleDateFormat("HH:mm:ss:SSS");
Map<String,KmaxHist> histograms = new HashMap<String,KmaxHist>();
static final int evSize = 6;//The num of parameters per event of this type
static final int BUF_SIZE = evSize*1000;// Buffer size
static final int LP_MEM_TOP = 0xFFFF00;//Memory size 16MB
static final int READ_START = LP_MEM_TOP - BUF_SIZE;//We start the read/write pointer 1 buffer before the end
\end{minted}
%\inputminted[fontsize=\normalsize, linenos, frame=lines]{java}{DAQ.java}%[linenos=true,bgcolor=lbcolor]{java}{DAQ.java}
\end{mdframed}
\end{document}
Line breaking seems to be working fine when using it's built in option for colored background bgcolor.

This isn't the case when using mdframed. For instance text jumps out of the frame and there's a rather annoying identation when detecting a line break. Take a look for instance lines 39 and 60 in the following image

Any idea on how can this be fixed?




mintedhas abreaklinesoption inspired by the answer you referenced. It seems to work fine with your example. The development version also has some options for customizing the break symbol and indent. – G. Poore Sep 09 '14 at 16:00minted.styfrom GitHub and put it in the same directory as your document, it will be used for that document. That would be a good way to check and see if it works for you. Longer term, you could install in texmf-local (see this). Or you could replace theminted.styin/texmf-dist/tex/latex/minted(though that might be frowned on, since it putstexmf-distout of sync with the repository). – G. Poore Sep 09 '14 at 19:00breaklines=truein the optional arguments but it seems that it's not recogized... – Thanos Sep 09 '14 at 19:05minted.sty(not the release download)? Are you usingbreaklinesas an optional argument for themintedenvironment? – G. Poore Sep 09 '14 at 20:57.sty. i used the new one and it seems that is working like a charm. I'll test it in a larger part of a code to check! – Thanos Sep 09 '14 at 21:04breaklinesinsidemdframed(in order to be able to be able to break the code through pages) but not inmintedenvironment but ininputmintedand it seems there are some mulfunctions. I'll edite my question later to ilustrate the problem – Thanos Sep 09 '14 at 21:11