Our subfiles.sty binding is a little brave/simple and it only goes so far. To fix the reported issue, I think the key bit was processing the main/outer {document} as usual, while only redefining the environment on secondary uses (in the dependent files).
So I deferred the redefinition, allowing the reported example to work as expected. An even nicer test is to move the algorithm to a standalone file and use a main.tex:
Fixes #2323
Our subfiles.sty binding is a little brave/simple and it only goes so far. To fix the reported issue, I think the key bit was processing the main/outer
{document}
as usual, while only redefining the environment on secondary uses (in the dependent files).So I deferred the redefinition, allowing the reported example to work as expected. An even nicer test is to move the algorithm to a standalone file and use a main.tex:
which is a little closer to the package intention.