Insert programming code in a Lyx document

后端 未结 3 1522
暖寄归人
暖寄归人 2021-01-30 00:04

What is the best way of inserting python/C++ code in a Lyx document? The code is small examples less than 20 lines.

My Lyx document is using the Book document class.

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-30 00:48

    I prefer to insert the listings as a child document, so the code is grabbed directly from a file that you can further edit and keep updated (you avoid to duplicate an information and maintenance is a lot easier). To do this in Lyx:
    Insert->File->Child document
    Then in the window that will appear change the type to program listing and configure it as you need, for example you could want to enter the parameter language=Python (you can type a ? to view all the parameters).
    A set of parameters I usually use is:

    breaklines=true //--> breaks lines to margin
    captionpos=b  //--> caption at the bottom of the listing (default is "t")
    frame=tb  //--> frame at the top and at the bottom of the listing
    language=Python  //--> syntax highlighting for python
    

提交回复
热议问题