recently I found LyX is good for writing notes. But I don't know how to add a piece of algorithm pseudocode in Lyx environment. Could you please help give some advice? Thanks!

How could I implement the following algorithmic pseudocode? Could you please give the complete operations on LyX 2.1.1?

enter image description here

  • @scottkosty,thank you for improving the post.
    – mining
    Nov 17, 2014 at 4:27

3 Answers 3


I have found the answer:

  1. add the \usepackage{algorithm,algpseudocode} into the premble
  2. insert a algorithm block (Insert --> Floating --> Algorithm)
  3. insert the tex code in the algorithm block (Insert --> Tex Code)
  4. add the following latex code

    \Require{$\rho \geq 1$}
    \While{not converged}
    \State{Solve $X_{k+1}=\min_{X} L(X,Y_k, \mu_k)$}
    \State{$Y_{k+1}=Y_k+\mu_k h(X_{k+1})$}
    \State{$\mu_{k+1}=\rho \mu_k$}
  • Do you need to use raw latex in this inside block or can you use lyx formatting?
    – Colin D
    Dec 10, 2017 at 22:20
  • Hi, yes, I used the raw latex as posted. But I'm not familiar with the lyx formatting.
    – mining
    Dec 11, 2017 at 0:18
  • Thanks for your help. I am using LyX Version 2.3.2 and everything works fine. The only problem is that the line numbering starts at line 3 e.g. with \While{not converged}. Any hints how to fix this? Mar 19, 2019 at 11:58

LyX Version 10) (14 February 2020)

  1. Insert->float->Algorithm
  2. Change Environment choice box (in this version it is just below file menu) from Standard to LyX-code
  3. Type the pseudo-code inside the box as you would in an editor. Math formatting works as usual. To highlight keywords select text and press Ctrl+b. An example.
  • Thanks a lot for your kind sharing!
    – mining
    Mar 9, 2021 at 12:29

You can also use Insert > Program listing then paste the code.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .