1

I am wondering is it possible instead of Algorithm 1" it could be something else, like "Code 1" without modifying other algorithms in my latex file (or without globally changing things).

I see this question has been asked many times but all of the solutions are either using different algorithm package or globally modify algorithm properties.

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage[a4paper, total={6in, 8in}]{geometry} \usepackage{algorithm} \usepackage{algpseudocode} \usepackage{amsmath,amssymb} \usepackage{amsthm}

\begin{document}

\begin{algorithm}[h] \caption{Rule evaluator for classical attribute grammar}\label{alg:ag-eval} \begin{algorithmic} \Procedure{\texttt{AG_EVAL}}{$r, Val$} \If{$r \equiv v_0 \texttt{=} g( v_1, \dots, v_n)$} \State $Val(v_0) \gets g( Val(v_1), \dots, Val(v_n))$ \EndIf \EndProcedure \end{algorithmic} \end{algorithm}

\end{document}

enter image description here

Node.JS
  • 685

1 Answers1

1

The trick was using { } or group to wrap the algorithm to prevent changing global settings and use floatname command to update the name.

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage[a4paper, total={6in, 8in}]{geometry} \usepackage{algorithm} \usepackage{algpseudocode} \usepackage{amsmath,amssymb} \usepackage{amsthm}

\begin{document}

{ % opening curly braces \floatname{algorithm}{Code} % replacing "Algorithm" with "Code" \begin{algorithm}[h] \caption{Rule evaluator for classical attribute grammar}\label{alg:ag-eval} \begin{algorithmic} \Procedure{\texttt{AG_EVAL}}{$r, Val$} \If{$r \equiv v_0 \texttt{=} g( v_1, \dots, v_n)$} \State $Val(v_0) \gets g( Val(v_1), \dots, Val(v_n))$ \EndIf \EndProcedure \end{algorithmic} \end{algorithm} } % closing curly braces

\end{document}

Credit

Reference

Node.JS
  • 685
  • 1
    Great :) // However, if you'd edit your answer and emphasize the two lines of code like {% << and }% << it would be evident on-the-fly. Thanks – MS-SPO Sep 15 '21 at 15:21
  • This is referred to as scoping. The {...} defines a group, where changes within the group is only temporary unless explicitly states as being global. – Werner Sep 15 '21 at 19:09