When I try to post Matlab code, there are some formatting problems.

For example, an apostrophe is used in Matlab to transpose a matrix. But when this is posted, it is interpreted as the beginning of a string, and the rest of the code turns red.

Also, comments in Matlab begin with the percentage sign. Words after this sign turn blue.

Is there a way to avoid these problems?

  • \$\begingroup\$ When in doubt, just turn all formatting off. \$\endgroup\$ – Mast Oct 31 '16 at 16:44
  • \$\begingroup\$ You could try to make the code highlighting vanish with <-- language : none --> before a code block. .. see also relevant meta post on mso \$\endgroup\$ – Vogel612 Oct 31 '16 at 16:47

Thanks for bringing it up.

The tag had no syntax highlighting language associated to it.

I've modified the tag settings to use lang-matlab, which should fix the automatic syntax highlighting in that language.

  • 2
    \$\begingroup\$ What? We have the power to do this? \$\endgroup\$ – Simon Forsberg Oct 31 '16 at 17:18
  • \$\begingroup\$ @SimonForsberg yup \$\endgroup\$ – Mathieu Guindon Oct 31 '16 at 17:21

You can specify the used language by inserting the following in your post. Thanks to Mat's Mug you can now use:

<!-- language: lang-matlab -->

This particular example makes SE think all the code blocks in the question are MATLAB code.

If your language is not supported, simply turn it off:

<!-- language: lang-none -->
  • 2
    \$\begingroup\$ The language meta-comment was required prior to setting up the tag's syntax highlighting; now it should work the same as any other language. Also if you don't specify language-all the meta-instruction only applies to the next code block, not "all code blocks in the question" - that's useful for e.g. formatting a XAML or T-SQL snippet in an otherwise C# post. \$\endgroup\$ – Mathieu Guindon Oct 31 '16 at 16:55
  • \$\begingroup\$ @Mat'sMug True, however, languages are not always properly recognized. Marking them explicit like I did does fix that. Marking all code blocks the same language doesn't work in multiple format questions, no. That's most of the time not an issue but it's good you mention it. \$\endgroup\$ – Mast Nov 1 '16 at 9:07

You must log in to answer this question.

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