Is there a listing environment?

This might be really obvious, but is there listing environment such as in latex. I have some code that I want to include and need to refer to it later in the code.

There are some environments under Insert -> Program -> Block of code.

You can put the code block inside an algorithm element with a label to refer to it and you can put a numbered tag inside to create line numbering.

It’s not an algorithm, so using an algorithm can be misleading. Is it not possible to have it show as listing or something that looks like figure or table environments ?

If you’re not using algorithm environments elsewhere, you can use the algorithm tag and change the “Algorithm text” in its settings to something like “Code listing”.

I’m actually using it elsewhere. That’s why I don’t want to use it for code that is not algorithm. Do you know how to define a new listing environment. It has to look exactly like a figure environment but has listing instead of figure.

Try this (“paste from TeXmacs” into the header):

<assign|code-listing|<\macro|body|caption>
  <with|figure-text|<macro|<localize|Code listing>>|<\big-figure|<arg|body>>
    <arg|caption>
  </big-figure>>
</macro>>

Thanks man. I appreciate it. I really plan to take some time to learn how to do these things myself after I’m done with my thesis.

Unfortunately, the code listings are now listed in my list of figures. I know I am asking too much, but how can I prevent that?

It’s maybe not the cleanest way, but you can put them in a with-figure-list

<assign|code-listing|<\macro|body|caption>
  <\with-figure-list|code>
    <with|figure-text|<macro|<localize|Code listing>>|<\big-figure|<arg|body>>
      <arg|caption>
    </big-figure>>
  </with-figure-list>
</macro>>

Incidentally, this also allows you to make a “List of code listings”

<\with-figure-list|code>
  <with|list-of-figures-text|<macro|<localize|List of code listings>>|<\list-of-figures|code>
    \;
  </list-of-figures>>
</with-figure-list>

and then refresh.

This one did the trick. Thanks.