2

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?

PerroNoob
  • 641
  • 9
  • 23
  • Can you please post a LyX minimal example ? In this case that would be a LyX file with a Local Layout that you pasted in here and that produces the output that you pasted here. – scottkosty Oct 17 '13 at 22:26
  • Hi, here there is an example https://www.dropbox.com/sh/8b4tp1ho94z41ok/9VwyKZjego Remember to put -shell-escape in the pdflatex option in the Tools -> Preferences – PerroNoob Oct 17 '13 at 22:39
  • I put also the layouts file. You must reconfigure LyX after leaving that file in the layouts directory – PerroNoob Oct 17 '13 at 22:43
  • 2
    Thanks for the minimal example. Note that you might be interested to know that you could just put your layout directly in Document > Settings > Local Layout. This is useful when developing your layout (e.g. making a lot of tweaks), useful for document-specific layouts (which this will probably not be), and also useful for minimal examples (no need for reconfigure and just one file). – scottkosty Oct 17 '13 at 23:21
  • Also note (for anyone else) that the pygmentize package can be installed with sudo apt-get install python-pygments on Ubuntu. – scottkosty Oct 17 '13 at 23:22
  • Yes, I know, the local layout directory is in ~/.lyx I already had pygments , that's why it compiles well, but the output is weird. Thanks for the tips – PerroNoob Oct 18 '13 at 09:56
  • 1
    I was giving you advice for how to improve on posting a minimal example. You should always give the prerequisites that are necessary (in this case the pygmentize package). And using LyX's local layout is useful for encapsulating things. I'm not referring to ~/.lyx. That is something different. I'm referring to Document > Settings > Local Layout. If you put the layout in there, everything is self-contained and it makes it easy for someone to come along and try to help. It's also useful for other reasons. – scottkosty Oct 18 '13 at 16:52
  • You might be interested in the matlab-prettifier package; see this answer. – jub0bs Apr 28 '14 at 16:31

1 Answers1

2

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.

scottkosty
  • 13,164