3

I learnt from another question that best way to include code was to make a child document with a program listing, which is great.

My question is how do I correctly label the program listing?

For a chapter it is chap:Name and for subsection it is sub:Name, so what is it for program listing?

Justification is when I cross reference I want the equivalent formating like when I reference a section ... section 2.1 ... when referenced. (I'm not actually writing "section" that is auto generated by lyx, I want the same for listing).

1 Answer 1

3

There isn't really a 'correct' answer, as you have to define this yourself. LyX uses the refstyle packages for such formatted references, and this does not, as far as I can tell, have definitions for program listings.

So what you would do is I think to add such a definition to your preamble, in Document --> Settings --> LaTeX preamble. A simple example is

\newref{lst}{
   name   = listing~,
   names  = listing~,
   Name   = Listing~,
   Names  = Listings~,
   rngtxt = {~to~},
   lsttxt = { and }}

With this definition you should use lst: as a the prefix in the labels. If you want some other prefix, change the lst in \newref{lst} to the prefix of your choice.

Note however, that as long as you don't use ERTs, I think you just need \newref{lst}{name = listing~}, as LyX simply doesn't have support for the other reference formats, unless I'm mistaken.

A final note: generally there is no correct way of writing labels for chapters, sections etc. either. The use of chap, sec, eq and so on is just a convention, it not something you need to do. Unless you use the refstyle package. This does actually need to have the right string as prefixes to figure out what type of object is referred to. The cleveref package is cleverer in this sense, as it figures stuff out on its own.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.