I want to define a new clause in algorithmic package (sync
in my case), so that the code inside that clause would be indented as it was inside a while
clause for example.
So far I made things work by adding those lines in different places of algorithmic.sty
\newcommand{\algorithmicsync}{\textbf{sync}}
\newcommand{\algorithmicendsync}{\algorithmicend\ \algorithmicsync}
\newenvironment{ALC@syn}{\begin{ALC@g}}{\end{ALC@g}}
\newcommand{\SYNC}[2][default]{\ALC@it\algorithmicsync\ ##2\ %
\ALC@com{##1}\begin{ALC@syn}}
\ifthenelse{\boolean{ALC@noend}}{
\newcommand{\ENDSYNC}{\end{ALC@syn}}
}{
\newcommand{\ENDSYNC}{\end{ALC@syn}\ALC@it\algorithmicendsync}
}
Is there a simpler way to do the job without editing algorithmic.sty
file?
Best Answer
As Werner says in his comment, it is not advisable to modify the
.sty
files directly. You can include your definitions in the document preamble (after loading the required packages); since your commands use the@
character, you will need to use\makeatletter
before the definitions and\makeatother
after them.However, I would suggest you to use the algorithmicx package instead; this package offers you many possibilities to customize the layout of algorithms and gives you an easy way to define a completely new layout for your specific needs. For example (
algpseudocode
internally loadsalgorithmicx
):EDIT: if changing to
algorithmicx
is not an option at the present time, you can still make your definitions in the preamble of your document instead of modifying the.sty
file directly; simply use\renewenvironment
to redefine thealgorithmic
environment and include your new definitions:If you don't want your preamble to look too crowded, you can put the code that goes between
\makeatletter
and\makeatother
in a new document and save this new document as, for example,algorithmic-modified.sty
in your current working directory (or in your local TDS tree). Now this file can be loaded in the standard way in the preamble of your document, after having loadedalgorithmic
(you'll have to be careful, since other users working with the document will also have to have access to this new file):And here's the contents of
algorithmic-modified.sty
: