# “Vanishing” sample code

When I post this answer I must see my code vanishing when I click on "Save answer". While editing the answer the code was displayed correctly before I clicked "Save". The code block background remains but there are no characters visible at all. Even copy to clipboard doesn't show anything. But the characters are there as I can see, when I try to edit the answer.

The problem might be that the code sample is in Lilypond syntax. There are some strange constructs with << >> \\ and so on. I used the Ctrl-K method (inserting four characters in front of each line) to format the code. Could I use different markup tokens to show such code?

Here is the code in question:

\relative c' {
<< { c4 c c c8 c c4 bes8 aes4. aes8 aes } \\
{ g8( aes f g4) aes f8 aes8( g f s8 \once\hideNotes aes2) } >>
<< { bes8 bes2 \stemDown aes8( g f <f ees>4.) } \\
{ f8( g ees f4) s s8 } >>
g8( des' f \clef treble as bes)
}


Even if I prepend the code with the language hint <!-- language: lang-none --> the behavior doesn't change.

The browser I use is Chrome 31.0.1650.63 m.

The answer has been reformatted meanwhile with some ugly workarounds. To get the simple code entry you need to look at the history. (Thanks to Martijn for the hint).

• Erm, I suspect it is being interpreted as MathJax, perhaps. – Martijn Pieters Jan 2 '14 at 20:12
• what browser are you using? it is possible that the browser you are using doesn't like the Javascript that is going on when this code is input. – Malachi Jan 2 '14 at 20:14
• @MartijnPieters How tell I stackoverflow that it's not MathJax but Lilypond or Schemer? – harper Jan 2 '14 at 20:14
• @Malachi: I can certainly reproduce the problem by looking at original first revision; the code block is replaced by a SVG object. – Martijn Pieters Jan 2 '14 at 20:16
• There is a precedent for there being Music.SE-specific problems. Perhaps this is a new one. – Josh Darnell Jan 2 '14 at 21:20
• @harper see for instance these questions (and make sure to upvote the first) meta.music.stackexchange.com/questions/240/… meta.music.stackexchange.com/questions/404/… – Ulf Åkerstedt Jan 6 '14 at 0:56

After a quick glance at https://music.stackexchange.com/content/js/third-party/jtab/jtab.js, I've noticed that it attempts to transform anything within a <pre><code> block that contains an uppercase A, B, C, D, E, F or G (thanks to this line). Your snippet is gobbled because of the "D" in "\stemDown".

A work-around to this issue is to wrap your text in <pre> (for the monospace formatting and whitespace preservement) and replace "<" with &lt;. Then you will get the desired formatting:

# Input

<pre>\relative c' {
&lt;&lt; { c4 c c c8 c c4 bes8 aes4. aes8 aes } \\
{ g8( aes f g4) aes f8 aes8( g f s8 \once\hideNotes aes2) } >>
&lt;&lt; { bes8 bes2 \stemDown aes8( g f &lt;f ees>4.) } \\
{ f8( g ees f4) s s8 } >>
g8( des' f \clef treble as bes)
}
</pre>


# Output

\relative c' {
<< { c4 c c c8 c c4 bes8 aes4. aes8 aes } \\
{ g8( aes f g4) aes f8 aes8( g f s8 \once\hideNotes aes2) } >>
<< { bes8 bes2 \stemDown aes8( g f <f ees>4.) } \\
{ f8( g ees f4) s s8 } >>
g8( des' f \clef treble as bes)
}


To verify that this works, just paste it at the editor on music.stackexchange.com, open the JavaScript console and run jtab.renderimplicit(null). You'll see that your formatting is preserved.

# Tool

Manually replacing all those <s with &lt;s might be a bit tedious. The next tool will do this task for you. Simply paste the text in the top textbox, click on the button, and you will see the result at the second text field: http://jsfiddle.net/JYA6w/show/

• How is jtab related to the music.stackwyxchange.com? -- Why must << be transcribed with &lt; but not >>? – harper Jan 3 '14 at 13:46
• @harper jtab is used to render chords. SE sites can have custom modules to format the content of the specific site, such as MathJax, Google Code Prettify, and apparently also jtab. I found jtab when I viewed the source code of music.stackexchange.com. < starts a HTML tag, > closes a HTML tag. Without an opening HTML tag, the closing > has no meaning. If you want to be really strict, then you should also encode > as &gt;. However, it makes the text less readable without added benefit, so I usually omit them from my posts on the Stack Exchange. – Rob W Jan 3 '14 at 13:49

Use quadruple-space indentation, preceded by the following hint to specify no language, per here:

To specify that you don't want any syntax highlighting for all following code blocks, use <!-- language-all: lang-none -->.

\relative c' {
<< { c4 c c c8 c c4 bes8 aes4. aes8 aes } \\
{ g8( aes f g4) aes f8 aes8( g f s8 \once\hideNotes aes2) } >>
<< { bes8 bes2 \stemDown aes8( g f <f ees>4.) } \\
{ f8( g ees f4) s s8 } >>
g8( des' f \clef treble as bes)
}


I guess the << and \\ are running into a Stackexchange bug.

• Despite the quote tells me that it should work it doesn't. – harper Jan 2 '14 at 20:42
• This seems to work for me in Chrome and SeaMonkey now that I have edited language to language-all. – MarkDBlackwell Jan 2 '14 at 20:49
• Nope, "language-all: lang-none doesn't" help. – harper Jan 2 '14 at 20:53
• Interesting. I'm familiar with LilyPond syntax, and on Windows I'm seeing the same source code in my answer source as displayed in my browsers. In fact when I go to edit through history your original source, it shows (to me) correctly in the preview area. You're seeing only a blank area, is that right? – MarkDBlackwell Jan 2 '14 at 21:00
• The code is visible only while editing. After saving it's still visible for half a second and "vanishes" thereafter. Although the background is colored gray with a dotted vertical line at the left side. – harper Jan 2 '14 at 21:06
• Is it also here, or only in your music.stackexchange.com answer that it shows blank to you? – MarkDBlackwell Jan 2 '14 at 21:06
• I added <!--language-all: lang-none--> with a space line after it, while temporarily editing the original version of your music.stackexchange.com answer, and the preview stopped being blank (for me). – MarkDBlackwell Jan 2 '14 at 21:10
• I could enter the code here. Looks like music.stackexchange.com specific. The code formatting differes at stackexchange sites. – harper Jan 2 '14 at 21:10
• Yes, the preview looks okay, but this is not visible to my readers. Therefore I rejected the proposed edit of a user (you?), – harper Jan 2 '14 at 21:11
• Yes, it goes blank after editing; so, it's an error in music.stackexchange.com system code. I hope my test edits of your answer will be rejected (as I requested)! – MarkDBlackwell Jan 2 '14 at 21:23
• I rejected it as author. I added an answer for experiments. – harper Jan 2 '14 at 21:29