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.
Asked
Active
Viewed 399 times
1 Answers
1
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}
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.
marv
- 2,099
- 1
- 7
- 26
-
Thanks! This works beautifully and even retains the code highlightings in overleaf :) – JDS Jan 20 '22 at 14:31
-
@JDS if this was helpfull, you can upvote and/or except the answer in the top left of this post (upwards arrow for upvote and checkmark for accept). – marv Jan 20 '22 at 15:13
-

\verb|..|environment and mention line numbers in the MATLAB code for the audience to follow the demonstration. – AboAmmar Jan 20 '22 at 12:32