For space consideration, I wish to condense my pseudocode.
I find it a bit annoying to me to always have a \EndIf or \EndFor at the end of every block, especially when inside the block only lies one statement. e.g.
\documentclass[a4paper]{article}
\usepackage{algorithmicx}
\usepackage{algorithm} % http://ctan.org/pkg/algorithms
\usepackage{algpseudocode} % http://ctan.org/pkg/algorithmicx
\newcommand*{\Let}[2]{\State #1 $\gets$ \parbox[t]{\linegoal}{#2\strut}}
\algnewcommand\algorithmicinput{\textbf{INPUT: }}
\algnewcommand\Input{\item[\algorithmicinput]}
\algnewcommand\algorithmicoutput{\textbf{OUTPUT: }}
\algnewcommand\Output{\item[\algorithmicoutput]}
\begin{document}
\begin{algorithm}
\begin{algorithmic}[1]
\Procedure{A}{}
\ForAll{$a\in A$}
\If{$a\geq b$}
\State\Return $a$
\EndIf
\EndFor
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}
To save the space, I wish to remove them, although it may be non-standard.
Once I do it, the code cannot be compiled due to errors.
Is there any "illegal" trick to kinda remove them from the output PDF?
Best Answer
Preventing end keywords from being typeset
Simply pass the
noend
option to thealgpseudocode
package: substitute\usepackage[noend]{algpseudocode}
for\usepackage{algpseudocode}
in your code and you getTo avoid having to use
\EndIf
and\Endfor
in your input file(After clarification by the OP, this turns out to be off-topic.)
Missing
\EndIf
and\EndFor
will generate errors; you cannot simply omit them in your input file. If you want to save yourself the hassle of having to use those macros in your input file in order to close control-flow statements, you can always define a macro that combines\If
and\EndIf
, another that combines\ForAll
and\EndFor
, etc.