I am writing my final thesis and I am not too practical working with LaTeX. In my document, I have to write some algorithms; my professor gave me the following code to put in the preamble:
\newcounter{algo}
\counterwithin{algo}{chapter}
\newcommand{\rs}{\textbf }
\newcommand{\ie}{i.e.\xspace}
\newcommand{\sfrac}[2]{{\textstyle\frac{#1}{#2}}}
\newcommand{\note}[1]{\marginpar{\footnotesize #1}}
\newcommand{\ignore}[1]{}
\newcommand{\diag}{\mathrm{diag}}
\newcommand{\algo}[3]{\refstepcounter{algo}
\begin{figure}[H]
\begin{center}
\framebox[\textwidth]{
\parbox{0.95\textwidth} {\vspace{\topsep}
{\bf Algorithm \thealgo : #2}\label{#1}\\
\vspace*{-\topsep} \mbox{ }\\
{#3} \vspace{\topsep} }}
\end{center}
\end{figure}}
I cannot really understand all the lines: in practice, this allows me to write an algorithm inside a box. Now, I have a few questions to modify some elements (I have checked on the Internet but couldn't find anything):
- how can I add a label to an algorithm defined by
\algo? I would like to cite it during my discussion and also create a list of algorithms at the beginning of the thesis. I don't need a caption, cause the first line of the algorithm already states the algorithm number and the title, I just need the label to refer to it in my document. - How can I center
\algo? I mean, if I have a short\algoand want to put it on a blank page, it doesn't appear centered both orizontally and vertically. I understand this "box" is treated like a figure, but even though in the command there is written\begin{center} ... \end{center}it doesn't manage to do it. I tried to replace it by\centeringbut it still doesn't work.
If you know how to fix this and want to help me, I would really appreciate it. Regards to all.

\textitor\it,\bfseriesor\bf, etc and Will two-letter font style commands (\bf,\it, …) ever be resurrected in LaTeX? – Werner Mar 18 '21 at 18:03