I think it's running into a problem when the line length is greater than
BufSize - in your example above, the equation is a little > 4000 chars long,
and
[readAllBuffer](https://github.com/nim-lang/Nim/blob/master/lib/system/sysio.nim#L171)
is ultimately what's called.
I don't see obvious bugs, but I'm getting weird output for a test program:
let buf = readAll(stdin)
stdout.write(buf)
with pasting in your sample program as input when running ^^^ manually. I'll
check again this weekend - if I can find the issue I'll make a PR, if not I"ll
create an issue on the Github.