# Spurious indentation in preformatted code [duplicate]

In this post I pasted some R code:

> r <- eigen(A)
> V <- r$vectors > lam <- r$values
> Lmbd <- diag(lam)


This was entered as

but at the time of this writing gets rendered as

The third line was indented no more than the others, but it gets rendered with four space indentation which the other lines don't have, both in the preview and the saved version.

Could this be some aspect of math rendering involved here, something confused by the dollar signs in there?

• Here is another useful hack. – cardinal Nov 27 '13 at 17:33

It definitely has to do with the MathJax combination.

The same code block causes a problem in preview on Physics.SE, which also uses has MathJax enabled.

But the code block does not cause a problem on TeX.SE, which does not have MathJax enabled.

This is the same issue as occurred in a previous meta question.

It would be annoying to implement in general, but one approach to overcoming this is to use the <pre> tag and replace the dollar signs with their HTML entities:

<pre>
&gt; r &lt;- eigen(A)
&gt; V &lt;- r&#36;vectors
&gt; lam &lt;- r&#36;values
&gt; Lmbd &lt;- diag(lam)
</pre>


produces

> r <- eigen(A)
> V <- r$vectors > lam <- r$values
> Lmbd <- diag(lam)


In this particular case, I also had to replace < and > with their HTML entities because each group (e.g., <- eigen(A) >) was being seen as an invalid HTML tag, and not rendered.

In my answer to the question that I linked to at the start of my post, I didn't have to mess around with HTML entities at all - it seems like the <'s and >'s really put a wrinkle in things.