Code: Select all
\documentclass[10pt,a4paper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[italian]{babel}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage[
left=2cm, % inner
right=2cm, % outer
top=2cm,
bottom=2cm,
%showframe,
]{geometry}
\usepackage{listings}
\lstnewenvironment{MatlabCodeWithListing}
{\lstset{
language=Matlab,
basicstyle=\small\ttfamily,
frame=single,
keywordstyle=\color[RGB]{0,0,255},
commentstyle=\color[RGB]{34,139,34},
stringstyle=\color[RGB]{160,32,240},
keepspaces,
morecomment=[l][\color{blue}]{...},
frameround=tttt,
backgroundcolor=\color{gray!10!white},
%rulecolor=\color{gray!20!white}
}}{}
\usepackage{matlab-prettifier}
\lstnewenvironment{MatlabCodeWithPrettifier}
{\lstset{
language=Matlab,
basicstyle=\small\ttfamily,
frame=single,
keywordstyle=\color[RGB]{0,0,255},
commentstyle=\color[RGB]{34,139,34},
stringstyle=\color[RGB]{160,32,240},
keepspaces,
morecomment=[l][\color{blue}]{...},
frameround=tttt,
backgroundcolor=\color{gray!10!white},
style=Matlab-editor,
mlsectiontitlestyle=\bfseries\color{red},
%rulecolor=\color{gray!20!white}
}}{}
\begin{document}
\chapter*{My errors}
\section*{What I use now}
With the \textit{MatlabCodeWithListing} I have:
\begin{MatlabCodeWithListing}
%% First section
h = L/N;
%{
comment line
comment line
%}
x = linspace(0,L,N+1);
%% Second section
L = 1;
N = 100;
A = [1 2 3; ...
3 5 6];
% Solution
[x,uh] = upwind(L);
\end{MatlabCodeWithListing}
There are three problems:
\begin{enumerate}
\item No bold section title
\item No $\%\{\quad \%\}$ comment
\item The box around the code is squared, but it has round corners, so the backgroundcolor overflows the round corners
\end{enumerate}
\section*{What I tried}
So i read about \textit{matlab-prettifier}:
\begin{MatlabCodeWithPrettifier}
%% First section
h = L/N;
%{
comment line
comment line
%}
A = [1 2 3; ...
3 5 6];
\end{MatlabCodeWithPrettifier}
\begin{enumerate}
\item The title section is not bold (but i could change the color)
\item The $\%\{\quad \%\}$ comment is correct
\item The box around the code is as before
\item I have an extra hookright (and a white line) in the definition of the matrix $A$
\end{enumerate}
\end{document}
1. No bold section title
2. No %{ %} comment
3. The box around the code is squared, but it has round corners, so the backgroundcolor overflows the round corners
So i read about matlab-prettifier and now:
1. The title section is not bold (but i could change the color)
2. The %{ %} comment is correct
3. The box around the code is as before
4. I have an extra hookright (and a white line) in the definition of the matrix A
Thanks for help guys