I want to include inline code examples such as if i < n then i++ and else i–. I'm using the following LaTeX:
\documentclass{article}
\usepackage{algorithmic}
\usepackage{algorithm2e}
\begin{document}
Inline code examples such as \lIf{i < n}{i++} and \lElse{i--} but
line breaks are being injected.
\end{document}
Which produces:
Inline code examples such as if i < n then i++;
and else i–;
but line breaks are being injected.
Rather than what I would expect:
Inline code examples such as if i < n then i++; and else i–; but line breaks are being injected.
How do I prevent linebreaks?
Best Answer
One is expected to use all
algorithm2e
macros inside analgorithm
environment to write pseudocode. If you want to use it inline in text, then you need to remove the insertion of\par
, which most structural pseudocode statements issue.Below I defined
\llIf
and\llElse
which remove this line-break issuing via a scope-limiting\let\par\relax
:Both macros lack the formal definition (which includes comments), but those aren't needed in inline usage, I assume.
Finally, don't mix the use of
algorithmic
withalgorithm2e
. They are two separate packages and shouldn't be used together.