# [Tex/LaTex] How to define default ‘program listing’ title and parameters in Lyx

listingslyxpython

I'm using LyX software and need to embed python code snippets and the option I found is to put snippet in a file and then use: insert> file> Child Document —-> choose the snippet file —-> set include type to "Program Listing", set label to e.g. py:xx and caption to e.g. "My Python code" and define parameters such as backgroundcolor etc.

Firstly, how can I change the title of the object from Listing 1: to e.g. Snippet 1?

Secondly, how can I set parameters globally for all Program listing widgets so that I won't have to redefine them every time?

Thirdly, please let me know if you know of a better way to embed Python code (I'm using PyDev on Eclipse IDE for python programming).

1. From karlkoeller's comment: Document --> Settings --> LaTeX preamble, add

\AtBeginDocument{\renewcommand{\lstlistingname}{Snippet}}


The \AtBeginDocument is necessary because LyX 2.1 adds \usepackage{listings} after the stuff that is added to Document --> Settings --> LaTeX preamble, so \lstlistingname is not defined at that time. You could alternatively do

\usepackage{listings}
\renewcommand{\lstlistingname}{Snippet}


though this means listings is loaded twice.

2. Caption and label has to be set for each listing of course, but the general style can be defined in Document --> Settings --> Listings: