I´m using the Matlab-prettifier package to include Matlab-code in my Latex-file, and it generally works, i.e, when I´m using the custom environment from the package:
\begin{lstlisting}[style=Matlab-editor]
format long
f=@(x) x^5 + x-1;
fzero(f, 1), hm(f, 0, 1, 0.5*10^-8)
ans =
0.754877666246693
ans =
0.754877667874098
\end{lstlisting}
So this works, but since this is an environment I use a lot, I would like to rename it to something shorter, and I´ve tried this:
\newenvironment{matlab}
{\begin{lstlisting}[style=Matlab-editor]}
{\end{lstlisting}}
That way I could just write
\begin{matlab}
Matlab-code here
\end{matlab}
to typeset the Matlab-code, but this doesn´t work, and I get a long and -- at least for me - incomprehensible error message, with a lot about undefined control sequences. Can anybody help me out with this? Thanks in advance!
Best answer (for me): enclosing a lstlisting environment inside my own environment using matlab-prettifier
\newenvironment{matlab}definition? – Sep 17 '17 at 12:16\VerbatimEnvironment, for example, see here: https://tex.stackexchange.com/questions/171702/seemingly-trivial-verbatim-newenvironment-and-colorbox – CarLaTeX Sep 17 '17 at 12:17\lstnewenvironmentmacro. You're running into a problem similar to the verbatim environment answer above, but the listings package has already solved it. – Mike Renfro Sep 17 '17 at 12:41{}icon to convert a region into indented format making it rendered as code. I will suppress the blank lines. – Sep 17 '17 at 12:46