[Tex/LaTex] Lyx minted environment layout

lyxlyx-layoutsminted

Before I resolved a problem to set up a minted environment in LaTeX.
Now, I would like to add this environment as a LyX layout.
I have tried with

Style MatlabCode
Category              MainText
Margin                Static
LatexType             Environment
LatexName             matlabcode
NextNoIndent          1
LeftMargin            MMM
RightMargin           MMM
ParIndent             MM
ParSkip               0
ItemSep               0
TopSep                0.5
BottomSep             0.5
ParSep                0
Align                 Block
AlignPossible         Block, Left, Right, Center
Preamble
    \usepackage{minted}
    \newminted{matlab}{mathescape,linenos=true}
EndPreamble

End

Everything works and pdflatex gives me a nice PDF. The problem is that, when I use the environment, which is similar to a quotation layout in LyX, in the output I get blank lines, like this

enter image description here

And those weird brackets, since it should be just [2;3]

Does anyone know about this?

Best Answer

You need to add the following lines:

PassThru                      1
ParbreakIsNewline             1

PassThru tells LyX "don't escape my input. It's not LaTeX".

`ParbreakIsNewline tells LyX not to start a new paragraph for line breaks in this layout.

This gives the following layout:

Style MatlabCode
Category              MainText
Margin                Static
LatexType             Environment
LatexName             matlabcode
NextNoIndent          1
LeftMargin            MMM
RightMargin           MMM
PassThru              1
ParbreakIsNewline             1
ParIndent             MM
ParSkip               0
ItemSep               0
TopSep                0.5
BottomSep             0.5
ParSep                0
Align                 Block
AlignPossible         Block, Left, Right, Center
Preamble
        \usepackage{minted}
        \newminted{matlab}{mathescape,linenos=true}
    EndPreamble
End

Please read Help > Customization for more information.

Related Question