9

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)

Related

6

Solution

Do not mix lst: with Algorithm floats. The previous solution used \newcommand{\algorithmname}{Listing}, but this could result in LaTeX Error: Command \algorithmname already defined. Instead, apply the following changes:

  1. Rename lst: to alg:.
  2. Change the preamble to:
    \usepackage{float}
    \floatname{algorithm}{Listing}
    \renewcommand{\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".

| improve this answer | |
4

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.

| improve this answer | |
2

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

\renewcommand{\listofalgorithms}{ 
  \begingroup 
    \listof{algorithm}{List of Listings} 
  \endgroup 
}
| improve this answer | |

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.