TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to define a new environment that uses the algorithm environment from algorithm2e. I want to use a separate caption counter for this new environment. As of now, this is what I have, but I don't know how to \def or \renewcommand the caption variable with the hdps counter?

\renewcommand*{\algorithmcfname}{ASM Spec.}%

Help is much appreciated.

share|improve this question
Do you want your algorithms to be sequentially numbered with a chapter, or section, or just have a number on their own? – Werner Aug 21 '11 at 22:06
Sequentially numbered. Thanks. – Hiren Aug 21 '11 at 22:15
up vote 2 down vote accepted

You could use something like this:

    \renewcommand*{\algorithmcfname}{ASM Spec.}%

EDIT: of course, this approach will only work as expected if \caption is used consistently in the algorithm and asm environments.

share|improve this answer
Great. This works. Thanks =) – Hiren Aug 21 '11 at 22:19
To get the float placement to work properly, I'd make a minor change: \newcounter{hdps} \newenvironment{asm} {\refstepcounter{hdps}% \renewcommand*{\algorithmcfname}{ASM Spec.}% \renewcommand\thealgocf{\arabic{hdps}}\begin{algorithm}} {\end{algorithm}\addtocounter{algocf}{-1}} – Hiren Aug 22 '11 at 8:16

Using an environment within an environment is sometimes problematic. See the related post Defining environments based on other ones: What's the right way?. In that sense, rather than defining a new environment and using a separate counter, I suggest using the counter provided by the algorithm environment: algocf, and modify both the algorithm name (from Algorithm to ASM Spec.) and the counter style (if needed). For example,

\renewcommand*{\algorithmcfname}{ASM Spec.}% Algorithm name
\usepackage{dcounter}% http://ctan.org/pkg/dcounter
\DeclareDynamicCounter{algocf}% <- algocf will be 'dynamic' within <section>

will reset the algocf counter within <section> (which could be any sectional unit that you specify, for example chapter, or section, or subsection, or subsubsection). This also redefines the presentation of the counter to be \the<section>.\arabic{algocf}.

Of course, this will not work if you want two different style algorithms (say named Algorithm and ASM Spec.).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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