MATLAB-typeset command within LaTeX paragraph

MATLAB

I would like to know if there is a way to include a MATLAB command within a sentence in LaTeX such that the command is in the MATLAB typeset format. I have seen examples using the matlab_prettifier package but that was for whole sections of code and no examples were given such that bits of code can be included within a normal sentence. I am describing a section of code for my thesis and I just need to include a single command within/in-line with one of my sentences.

Best Answer

You can write \lstinline[style=Matlab-editor]{<command>} to typeset commands inline with MATLAB editor style.

\documentclass{article}

\usepackage{matlab-prettifier}

\begin{document}

An example of an inline command is \lstinline[style=Matlab-editor]{d = rand(n,1)}. More text

\end{document}

inline matlab command

Somehow, this confuses the code highlighting in many editors (including this site). Therefore I would recommend to define a command

\newcommand{\lstinlineMatlab}[1]{\lstinline[style=Matlab-editor]{#1}}

and use \lstinlineMatlab{d = rand(n,1)} instead.