I also have another problem/question:
At the bottom of each code snippet that i included in my LaTeX document, there is a "Listing 1:", "Listing 2:", etc and i want to change this or remove it, if possible? I can only add a caption to it, but i would like to change it to "Source code" instead of "Listing". Also, how to make the numbers match the chapter/section instead of currently just incrementing integers?
Code: Select all
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{minted}
\usepackage{xcolor}
\definecolor{LightGray}{gray}{0.9}
%\definecolor{DarkGray}{gray}{0.1}
%\pagecolor{DarkGray}
\usemintedstyle{borland}
%New colors defined below
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\title{Code Listing}
\author{someone}
\date{ }
\begin{document}
\maketitle
\section{Code examples}
\begin{listing}[ht]
\begin{minted}{python}
import numpy as np
def incmatrix(genl1,genl2):
m = len(genl1)
n = len(genl2)
M = None #to become the incidence matrix
VT = np.zeros((n*m,1), int) #dummy variable
#compute the bitwise xor matrix
M1 = bitxormatrix(genl1)
M2 = np.triu(bitxormatrix(genl2),1)
for i in range(m-1):
for j in range(i+1, m):
[r,c] = np.where(M2 == M1[i,j])
for k in range(len(r)):
VT[(i)*n + r[k]] = 1;
VT[(i)*n + c[k]] = 1;
VT[(j)*n + r[k]] = 1;
VT[(j)*n + c[k]] = 1;
if M is None:
M = np.copy(VT)
else:
M = np.concatenate((M, VT), 1)
VT = np.zeros((n*m,1), int)
return M
\end{minted}
\caption{Minimal working example}
\label{listing:1}
\end{listing}
\clearpage
%Python code highlighting
\begin{listing}[ht]
\begin{minted}
[
frame=lines,
framesep=2mm,
baselinestretch=1.2,
bgcolor=LightGray,
fontsize=\footnotesize,
linenos
]
{python}
import numpy as np
def incmatrix(genl1,genl2):
m = len(genl1)
n = len(genl2)
M = None #to become the incidence matrix
VT = np.zeros((n*m,1), int) #dummy variable
#compute the bitwise xor matrix
M1 = bitxormatrix(genl1)
M2 = np.triu(bitxormatrix(genl2),1)
for i in range(m-1):
for j in range(i+1, m):
[r,c] = np.where(M2 == M1[i,j])
for k in range(len(r)):
VT[(i)*n + r[k]] = 1;
VT[(i)*n + c[k]] = 1;
VT[(j)*n + r[k]] = 1;
VT[(j)*n + c[k]] = 1;
if M is None:
M = np.copy(VT)
else:
M = np.concatenate((M, VT), 1)
VT = np.zeros((n*m,1), int)
return M
\end{minted}
\caption{Example with line numbers enabled}
\end{listing}
\clearpage
The next code will be directly imported from a file:
%Importing code from file
\begin{listing}[ht]
\inputminted{octave}{BitXorMatrix.m}
\caption{Example from external file}
\label{listing:3}
\end{listing}
\clearpage
One-line code formatting also works with minted. For instance, a simple html sample like this:
\mint{html}|<h2>Something <b>here</b></h2>|can be properly
formatted.
\clearpage
\renewcommand\listoflistingscaption{List of source codes}
\listoflistings
\end{document}