If I've understood correctly, you are trying to format html for human readability, and you don't want to use "pre" tags to force tidy to preserve whitespace because you will be running the output of tidy through htmlspecialchars before outputting it to the browser.
Why don't you just remove those "pre" tags after cleaning? It would look like this:
$config = array('show-body-only' => true, 'indent' => true);
$HTMLcodeOutput = tidy_repair_string('<pre>'.$HTMLcode.'</pre>', $config);
$HTMLcodeOutput = substr($HTMLcodeOutput, 5, -6);