# Minted: Different 'firstnumbers' for each code piece

I use minted to view my bash script. But i have to split my code into 4 pieces. My problem is, that every code piece begins now with the number 1. i.e. i want, that piece 1 is from number 1 till number 10, piece 2 from number 11 till number 25 [...] and so on. I know, that this is possible with firstnumber=# But where have i to write this in my code? Of course, when i write this in \newmintedfile then all of my code pieces begins with this number. So i have to put this somewhere in

\bashscript{code/script.sh}


But what is here the correct syntax?

\documentclass[11pt,a4paper]{article}
\setlength{\parindent}{0pt}
\usepackage[english, ngerman]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage{minted}
\usepackage{caption}
\usepackage{tcolorbox}
\tcbuselibrary{skins, breakable}
\usemintedstyle{perldoc}
\definecolor{mintedbackground}{rgb}{0.95,0.95,0.95}

\newmintedfile[bashscript]{bash}{
firstnumber=2,
bgcolor=mintedbackground,
fontfamily=tt,
linenos=true,
numberblanklines=true,
numbersep=5pt,
gobble=0,
frame=leftline,
framerule=0.4pt,
framesep=2mm,
funcnamehighlighting=true,
tabsize=4,
obeytabs=false,
mathescape=false
samepage=true, %with this setting you can force the list to appear on the same page
showspaces=false,
showtabs =false,
texcl=false,
}

\begin{document}

\bashscript{code/script1.sh}

\bashscript{code/script2.sh}

\end{document}


You can use the fancyvrb option firstnumber=last

Here an example:

\RequirePackage{filecontents}
\begin{filecontents}{script1.sh}
#!/bin/bash
# Simple line count example, using bash
#
#
# Usage: ./line_count.sh file
# -----------------------------------------------------------------------------

# Link filedescriptor 10 with stdin
exec 10<&0
# stdin replaced with a file supplied as a first argument
exec < $1 # remember the name of the input file in=$1

# init
file="current_line.txt"
let count=0

# this while loop iterates over all lines of the file
do
# increase line counter
((count++))
# write current line to a tmp file with name $file (not needed for counting) echo$LINE > $file # this checks the return code of echo (not needed for writing; just for demo) if [$? -ne 0 ]
then echo "Error in writing to file ${file}; check its permissions!" fi done \end{filecontents} \begin{filecontents}{script2.sh} echo "Number of lines:$count"
echo "The last line of the file is: cat ${file}" # Note: You can achieve the same by just using the tool wc like this echo "Expected number of lines: wc -l$in"

# restore stdin from filedescriptor 10
# and close filedescriptor 10
exec 0<&10 10<&-
\end{filecontents}
\documentclass[11pt,a4paper]{article}
\setlength{\parindent}{0pt}
\usepackage[english, ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage{minted}
\usepackage{caption}
\usepackage{tcolorbox}
\tcbuselibrary{skins, breakable}
\usemintedstyle{perldoc}
\definecolor{mintedbackground}{rgb}{0.95,0.95,0.95}

\newmintedfile[bashscript]{bash}{
firstnumber=2,
bgcolor=mintedbackground,
fontfamily=tt,
linenos=true,
numberblanklines=true,
numbersep=5pt,
gobble=0,
frame=leftline,
framerule=0.4pt,
framesep=2mm,
funcnamehighlighting=true,
tabsize=4,
obeytabs=false,
mathescape=false
samepage=true, %with this setting you can force the list to appear on the same page
showspaces=false,
showtabs =false,
texcl=false,
}

\begin{document}

\bashscript{script1.sh}

\bashscript[firstnumber=last]{script2.sh}

\end{document}

• Thanks, firstnumber=last is doing the trick – ipo Mar 23 '17 at 13:13