I was trying breqn again to see if I can use it. I found something strange. The same latex file produces different looking output when compiled with TL 2021 on linux vs. earlier TL versions.
I found what seems to confuse it. It is the \left( and \right). Compare this
\documentclass[12pt]{book}
\usepackage{amsmath}
\usepackage{breqn}
\begin{document}
\begin{dgroup}
\begin{dmath}
y_h(x) = \left(x\right)+ y
\end{dmath}
\end{dgroup}
\begin{dgroup}
\begin{dmath}
y_h(x) =(x)+ y
\end{dmath}
\end{dgroup}
\end{document}
Compiled with lualatex gives
The first one is bad due to using \left( and \right). Removing these fixes the problem. But this is auto-generated latex and it uses \left( and \right) everywhere. something changed in latest TL to cause this. Compiling the above with earlier TL version 2020 gives correct output for both cases.
UPDATE oct 19, 2021
The fix proposed in the answer below unfortunately does not fix some other case I just found. I do not know if this below is a new issue and needs to be put in a new question or if it the same problem. But consider this MWE
\documentclass[11pt]{book}
\usepackage{amsmath}
\usepackage{breqn}
%add proposed fix
\AddToHook{env/dgroup/begin}{\csname tex_everypar:D\endcsname{}}
\begin{document}
Substituting the above back into the ode gives
\begin{dmath}
2 x^{2} \left(x^{2}+x +1\right) \left(\sum_{n=0}^\infty \left(n +r \right) \left(n +r -1\right) a_{n} x^{n +r -2}\right)
+x \left(11 x^{2}+11 x +9\right) \left(\sum_{n=0}^\infty \left(n +r \right) a_{n} x^{n +r -1}\right)
+\left(7 x^{2}+10 x +6\right) \left(\sum_{n=0}^\infty a_{n} x^{n +r}\right) = 0
\end{dmath}
\end{document}
When compiling the above using latest TL 2021 it gives this output
>lualatex foo.tex
This is LuaHBTeX, Version 1.13.2 (TeX Live 2021)
restricted system commands enabled.
(./foo.tex
LaTeX2e <2021-06-01> patch level 1
L3 programming layer <2021-10-17>
....
Output written on foo.pdf (1 page, 59924 bytes).
Transcript written on foo.log.
When compiling using TL 2020 instead, and without the fix code in there, this is the output
>lualatex foo.tex
This is LuaHBTeX, Version 1.12.0 (TeX Live 2020)
restricted system commands enabled.
(./foo.tex
LaTeX2e <2020-10-01> patch level 4
L3 programming layer <2021-02-18>
....
Output written on foo.pdf (1 page, 59964 bytes).
Transcript written on foo.log.
As you can see, the fix did not work here. But I do not know if this is a new issue or not. If it is, I can make new question about it.
FYI. Added issue ticket at https://github.com/wspr/breqn/issues/52



