I'm trying to define a new keyword Let ... In ... End for my algorithm, it has two parts, like the keyword Let in this algorithm:


I have tried to define a block, but I found that only the stuffs like While ... End (which has only one block) can be defined.

Sorry for my poor English, but I have no idea how to typesetting this kind of blocks in algorithm2e.

1 Answer 1


algorithm2e defines a command \SetKwBlock which can be used to define new block structures. While the documentation says this command defines two variants, one for blocks with an explicit end-marker and one without, the latter actually doesn't seems to be defined. It could be used to build our let-in-structure from two such blocks.

We thus have to resort to more low-level functions. The following code defines a new block structure \LetIn{<definitions>}{<usage>} based on patterns used by the \SetKwBlock and \SetKwSwitch macros:


    \ifArgumentEmpty{#1}\relax{ #1}%
    \ifArgumentEmpty{#1}\relax{ #1}%

            {true part}
            {false part}
            {definitions part}
            {usage part}


\demo{No line style}\SetAlgoNoLine
\demo{Normal line style}\SetAlgoLined
\demo{Vertical line style}\SetAlgoVlined



enter image description here

  • Thanks a lot! It's very helpful.
    – 3usi9
    Sep 12, 2019 at 3:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.