# Rename “Algorithm” to “Listing”

## Background

Syntax-highlighted source code image listings are being used as Algorithm floats with the lst: prefix for captions.

## Problem

The following LaTeX code in the preamble renames the caption for the Algorithm float to Listing, as desired:

\usepackage{float}
\floatname{algorithm}{Listing}


However, the cross-reference label using the following command remains "Algorithm" (should be "Listing"):

\ref{lst:Internationalization-Look-up-Method}


Essentially, I am trying to rename Algorithm floats to Listing floats. (The book will have no algorithms.) LyX has Algorithm, Figure, and Table as floats to insert. If there was a way to configure and add Listing to the same menu (Insert >> Float >> Listing), that would also be a great solution.

## Ideas

The following failed:

\usepackage{caption}
\usepackage{listings}
\renewcommand{\lstlistlistingname}{Listings}
\renewcommand{\lstlistingname}{Listing}


The following eliminated the word "Algorithm" for the reference label altogether:

\usepackage{caption}
\usepackage{listings}
\renewcommand\lstlistingname{Listing}
\renewcommand\lstlistlistingname{Listings}
\def\lstlistingautorefname{Listing}


I have not yet looked into the babel package.

## Question

How can you rename "Algorithm" to "Listing" everywhere, including:

• Caption
• Label reference
• In the front matter (i.e., List of Listings rather than List of Algorithms)

-

## Solution

Do not mix lst: with Algorithm floats.

1. Rename lst: to alg:.
2. Change the preamble to:
\usepackage{float}
\floatname{algorithm}{Listing}
\newcommand{\algorithmname}{Listing}


This does not change the "List of Algorithms" to "List of Listings". The text is found in "stdfloats.inc":

Float
Type                  algorithm
GuiName               Algorithm
Placement             tbp
Extension             loa
NumberWithin          none
Style                 ruled
ListName              "List of Algorithms"
LaTeXBuiltin          false
End


The improper way to fix this is:

1. Edit stdfloats.inc.
2. Change "List of Algorithms" to "List of Listings".
3. Click Tools >> Reconfigure.
4. Restart LyX.

At this point, "List of Algorithms" will read "List of Listings".

-
When I inserted an algorithm float with this preamble, I got "LaTeX Error: Command \algorithmname already defined." unless I made the third line "\renewcommand{\algorithmname}{Listing}". It works now, although I wonder how to get the caption formatting to work like regular figure and table floats instead of the line above the listing. –  FvD Sep 16 '13 at 18:10

Fora separate doc add in Document > Settings > Local Layout:

Float
Type                  listing
GuiName               Code Listing
Placement             tbp
Extension             lol
NumberWithin          none
Style                 ruled
ListName              "List of Listings"
LaTeXBuiltin          false
End


Then you can insert this with menu Insert > Float > Listing. This makes the choice document-specific and allows you to use both, rather than change the entire Lyx install.

-

I changed the List of Algorithms to List of Listings with:

\renewcommand{\listofalgorithms}{
\begingroup
\listof{algorithm}{List of Listings}
\endgroup
}

-