Why is my code in Matlab Answers not colorful?
Show older comments
I started using Matlab Answers a few days ago and this is probably a dumb question, but it's starting to bother me.
If I write a code block, whether in a question, comment, or answer, the colors show up normally in the Editor:

But when I actually make the post, all of the colors go away:

I see other people posting their blocks of code with the usual colors. What am I doing wrong?
10 Comments
Bjorn Gustavsson
on 13 Apr 2023
The reason (as far as I've bothered to understand) is that the answers editor doesn't support syntax highlighting. If users copy the code into an editor of their choise they get their selected syntax highlighting. This is not that much of a problem, the code-snippets published aren't that large. Sure, it would be neat, but I'd trade that improvement for any efficiency improvement in computations, regardless of how small.
Dyuman Joshi
on 13 Apr 2023
Edited: Dyuman Joshi
on 13 Apr 2023
That's weird, paired with the fact that it shows 2 levels simultaneously for your Answers Activity.
@Bjorn, Answers editor does support syntax highlighting, even if one copies code from somewhere else.
figure
hold on
%Comment
function y = trig(x,r);
if r==1
y=sin(x);
elseif r==0
y=cos(x);
end
end
I'm unable to tag @Rena Berman (Answers Dev) here, I hope they see this comment and provide some info about this.
"the answers editor doesn't support syntax highlighting"
??? After submitting, this code:
% hello
for k = 1:3
disp('world')
end
looks like this (Chrome, Win10):

@Ran Yang: contact TMW and give them feedback on this. The volunteers cannot fix or debug this forum.
Bjorn Gustavsson
on 13 Apr 2023
@Ran Yang: does your OS use two-byte characters by default? I am wondering if this is related to character encoding.
% comment
for loop
'string';
end
!yellow
Ran Yang
on 13 Apr 2023
Ran Yang
on 13 Apr 2023
Walter Roberson
on 13 Apr 2023
Even stranger: when I use my editor powers to edit your "one last try" post, the preview shows up color coded!
The code will not, if I recall, show up color coded in the case that the Answers editor thinks you are using Mobile. But in that case, you get a quite different editor, with a tab named Draft and a tab named Preview, rather than having the tool ribbon with "TEXT", "CODE", "INSERT", "RUN", "HELP" sections.
And if it thinks you are using mobile, then the editor you get then does not have explicit text blocks: you just have to know that to get a code block you need to leave a (completely) empty line and then have the first line after that indented by at least one space.
Accepted Answer
More Answers (2)
Cris LaPierre
on 13 Apr 2023
1 vote
Not sure who you sent the email to, but please report this here: https://www.mathworks.com/support/contact_us.html
1 Comment
Kayln
on 23 Feb 2024
0 votes
I had the same issue. I ended up having to uninstall one of my debuggers and it seemed to come back.
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
