5
$\begingroup$

This question already has an answer here:

In an answer of mine on CV I have the following code chunk, indicated via indentation by 4 spaces at the start of the line.

> AIC(gam_example$lme)
[1] -2.136317
> AIC(gamm_example$lme)
[1] -1286.448

(Note that to illustrate this I have wrapped the above in HTML <pre> tags - the layout above is how it was entered in the edit window in the Answer.)

The displayed code block is rendered as

> AIC(gam_example$lme)
    [1] -2.136317
    > AIC(gamm_example$lme)
[1] -1286.448

(Again, here this is wrapped in <pre> in the editor, but only to show the problem.)

Clearly the alignment in the code block is wrong. I wonder if this is something to do with MathJax (note the $ in both chunks). Compare these two blocks, both entered without <pre> tags in the editor:

> AIC(gam_example$lme)
[1] -2.136317
> AIC(gamm_example$lme)
[1] -1286.44

and

> AIC(gam_example$lme)
[1] -2.136317
> AIC(gamm_example)
[1] -1286.44

The first chunk of these two is a live example of the problem I report here. Note the lack of a second $ in the second code block allows this to render with the correct, intended alignment.

Is there anything that can be done about this, or is it an unfortunate clash of R syntax and MathJax? Or something else?

$\endgroup$

marked as duplicate by gung, Gavin Simpson, whuber Sep 20 '13 at 16:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ @smillig sigh, I thought I'd done my due diligence and checked related Qs. Thanks for doing that job properly for me and pointing out the original. I've voted to close. (+1) $\endgroup$ – Gavin Simpson Sep 20 '13 at 14:57
  • 1
    $\begingroup$ ... and I actually answered that duplicate and had forgotten it existed. $\endgroup$ – whuber Sep 20 '13 at 16:09
9
$\begingroup$

Yes, it looks like a clash of markup procedures. The only workaround I have found is to add a comment containing an odd number of $\$$ after each offending line. For example,

> AIC(gam_example$lme)
    [1] -2.136317
    > AIC(gamm_example$lme)
[1] -1286.44

becomes

> AIC(gam_example$lme) #$
[1] -2.136317
> AIC(gamm_example$lme) #$
[1] -1286.44
$\endgroup$
  • 1
    $\begingroup$ Thanks; I supposed one could also render using <pre>, as I did above, but that begs the question why this fails for the rendered code blocks and not for code added in <pre> tags. This seems to be something specific to code blocks and how they are rendered from the MD into HTML. $\endgroup$ – Gavin Simpson Sep 19 '13 at 19:59
  • 2
    $\begingroup$ Thanks for this workaround. I've run into this problem many times and sometimes managed to get it to go away, but this is a better solution than any I managed. $\endgroup$ – Glen_b Sep 19 '13 at 21:23

Not the answer you're looking for? Browse other questions tagged .