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:

format long
f=@(x) x^5 + x-1;
fzero(f, 1), hm(f, 0, 1, 0.5*10^-8)
ans =

ans =

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:


That way I could just write

Matlab-code here

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

| improve this question | | | | |
  • 1
    do you really have blank lines in \newenvironment{matlab} definition? – user4686 Sep 17 '17 at 12:16
  • 3
    Use \VerbatimEnvironment, for example, see here: tex.stackexchange.com/questions/171702/… – CarLaTeX Sep 17 '17 at 12:17
  • @jfbu No, I don´t have a blank line in the definition, I just wanted each argument to be on a new line. Thanks for the edit! – Niels Petter Liset Sep 17 '17 at 12:24
  • 3
    If you're using listings, see section 5.14 of the package documentation for the \lstnewenvironment macro. 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
  • You can use the {} icon to convert a region into indented format making it rendered as code. I will suppress the blank lines. – user4686 Sep 17 '17 at 12:46