I want to use the algorithm2e package in LyX (version 2.2.3). There is a LyX module that makes this task simple. However, I would like to adjust the arguments with which the package is imported.

The LaTeX code generated by LyX reads


What I want is something like

\usepackage[lined, algonl, boxed]{algorithm2e}

As pointed out in this post, the options with which a package imported by a module is loaded can be changed by going to Document > Settings > Local Layout and entering package options like

PackageOptions algorithm2e lined

This adds the line


to the source code before the import of algorithm2e. Accordingly, I have tried to pass multiple arguments:

PackageOptions algorithm2e lined
PackageOptions algorithm2e algonl
PackageOptions algorithm2e boxed

However, only the last PackageOptions line is considered in the code, which reads


This might be wanted behaviour (or not - I do not know whether PassOptionsToPackage can be applied multiple times). Nevertheless, the question remains: How can I add multiple package options?

I have tried to import algorithm2e in the "Latex-Preamble" in the document settings of LyX. However, this results in a conflict with the internal LyX solution. I get an error stating Command \algorithm already defined.

Would it be an option to write a new LyX module with adjusted import? How could I do this? The LyX documentation on modules is not detailed. I looked at the code of the algorithm2e module but did neither understand it completely nor find a line that I could adjust accordingly.

2 Answers 2


Load the algorithm2e module from Document > Settings... > Modules and then add the following to your Local Layout:

Format 60
PackageOptions algorithm2e "lined, algonl, boxed"

This ensures that all 3 options are passed to algorithm2e when loaded.


Werner's is the correct solution.

However, as an alternative, you could do the following.

Do not add the predefined module.

Go to Document > Settings > LaTeX Preamble and add directly:

\usepackage[lined, algonl, boxed]{algorithm2e}

The drawback of this solution is that, afterwards, you have to insert your algorithm by ERT code directly:

enter image description here

because, not having loaded its module, LyX doesn't know you're using that package.

  • This does not work, because it interferes with the builtin algorithm environment in LyX. I described this in my post above.
    – Samufi
    Oct 3, 2017 at 2:26
  • Thanks, @CarLaTeX. It still does not work, though - even with "Provides algorithm 1".
    – Samufi
    Oct 3, 2017 at 2:46
  • @Samufi My original solution works, but you have to write your algorithm with ERT. Werner's answer is better.
    – CarLaTeX
    Oct 3, 2017 at 4:34
  • I see... I guess, if I would have gone with ERT in the first place, the whole issue would not have come up. Thanks for researching, though @CarLaTeX!
    – Samufi
    Oct 3, 2017 at 6:21
  • @Samufi You're welcome! We're here to help. However, Werner's answer is more convenient, because you don't need to use ERT. :)
    – CarLaTeX
    Oct 3, 2017 at 6:37

You must log in to answer this question.

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