It looks like there is something (probably an environment variable) which makes mimetex.cgi think that it is a web server, ie. that it is talking directly to the client browser, rather than being called by a script. Take a look at the mimetex source code and look for that content header. Strip out that code (e.g. replace it by the empty string) and recompile it.
Alternatively one can add extra code to the algebra filter to strip out the content header after mimetex is called.
Mathematics tools
Maths in Moodle using Tex
This discussion has been locked so you can no longer reply to it.