Text FormattingFormatting Matlab file with lstlsting

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
bearniva
Posts: 1
Joined: Fri Jan 03, 2020 12:28 pm

Formatting Matlab file with lstlsting

Post by bearniva »

Hello!
I included a Matlab file, and it worked fine. The colors changed and it looked nice. Suddenly Latex doesn't change the colors of the code, except of the background color. Is something wrong with my code? Or is there a possibility that a included package is disturbing the code?
Thank you very much for answering!


Code: Select all

\documentclass[12pt, xcolor=dvipsnames]{scrartcl}

\usepackage{listings}
\usepackage[dvipsnames]{xcolor}

\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{mygreen}{RGB}{28,172,0} 
\definecolor{mylilas}{RGB}{170,55,241}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\begin{document}

\lstdefinestyle{mystyle}{
    backgroundcolor=\color{backcolour},   
    commentstyle=\color{codegreen},
    keywordstyle=\color{blue},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{codepurple},
    basicstyle=\ttfamily\scriptsize,
    breakatwhitespace=false,         
    breaklines=true,                 
    captionpos=b,                    
    keepspaces=true,                 
    numbers=left,                    
    numbersep=5pt,                  
    showspaces=false,                
    showstringspaces=false,
    showtabs=false,                  
    tabsize=2,
    aboveskip=\medskipamount
}
\lstset{style=mystyle}

\lstinputlisting{adj.m}
\end{document}
Attachments
Pdf output
Pdf output
Bildschirmfoto 2020-01-03 um 11.31.48.png (106.82 KiB) Viewed 2485 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Bartman
Posts: 369
Joined: Fri Jan 03, 2020 2:39 pm

Formatting Matlab file with lstlsting

Post by Bartman »

You have not selected the language you want to use. Add language=Matlab to your style definition.
Post Reply