1

I wan to show which command line I have used for some specific result. for example i want to show this line 'for i=1:100' in between text.

I am using listing environement.

\documentclass[hidelinks, 12pt, a4paper, oneside]{book}
\usepackage[]{listings}
\usepackage{color} %red, green, blue, yellow, cyan, magenta, black, white
\definecolor{mygreen}{RGB}{28,100,0} % color values Red, Green, Blue
\definecolor{mylilas}{RGB}{170,55,241}
\lstset{literate=%
    {Ö}{{\"O}}1
    {Ä}{{\"A}}1
    {Ü}{{\"U}}1
    {ß}{{\ss}}1
    {ü}{{\"u}}1
    {ä}{{\"a}}1
    {ö}{{\"o}}1
    {~}{{\textasciitilde}}1
}
\lstset{language=Matlab,%
    basicstyle={\linespread{0.9}\small\ttfamily},
    linewidth=470,
    xleftmargin=25,
    xrightmargin=10,
    breaklines=true,%
    morekeywords={matlab2tikz},
    keywordstyle=\color{black},%
    morekeywords=[2]{1}, keywordstyle=[2]{\color{black}},
    identifierstyle=\color{black},%
    stringstyle=\color{mylilas},
    commentstyle=\color{mygreen},%
    showstringspaces=false,%without this there will be a symbol in the places where there is a space
    numbers=left,%
    numberstyle={\small \ttfamily\color{black}},% size of the numbers
    numbersep=9pt, % this defines how far the numbers are from the text
    emph=[1]{for,end,break},emphstyle=[1]\color{blue}, %some words to emphasise
    %emph=[2]{word1,word2}, emphstyle=[2]{style},    
}
\renewcommand{\ttdefault}{pcr}

Can anyone please help? Thank you for looking into it. :)

2 Answers 2

2

Instead of manually defining styles, you can do the following:

\documentclass[hidelinks, 12pt, a4paper, oneside]{book}

\usepackage{listings}
\usepackage[framed , numbered]{matlab-prettifier}

\begin{document}

\begin{lstlisting}[style=Matlab-editor]
%This is a MATLAB environment
for i = 1:1:100
\end{lstlisting}

\end{document}
2
1

You can use inline with matlab-prettifier. Here is an example. Below, the character (`) states the beginning of inline.

\documentclass[11pt]{article}
\usepackage[margin=1.2in]{geometry}

\usepackage{textcomp}           % To use with matlab-prettifier
\usepackage{listings}
\usepackage{matlab-prettifier}  % Matlab Prettifier

\lstMakeShortInline[style=Matlab-editor]`

\begin{document}
This statement `for n = 1:100,display(n),end` shows the variable `n`.
\end{document}

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .