# Syntax Highlighting MATLAB code in forum posts?

**URL:** <https://psychtoolbox.discourse.group/t/syntax-highlighting-matlab-code-in-forum-posts/3036>\
**Category:** Site Feedback\
**Created:** [February 12, 2020, 7:19am UTC](https://psychtoolbox.discourse.group/t/syntax-highlighting-matlab-code-in-forum-posts/3036 "2020-02-12T07:19:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ian-Max-Andolina](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ian-max-andolina/32/4_2.png) [@Ian-Max-Andolina](https://psychtoolbox.discourse.group/u/Ian-Max-Andolina)\
**Post date:** [February 12, 2020, 7:19am UTC](https://psychtoolbox.discourse.group/t/syntax-highlighting-matlab-code-in-forum-posts/3036/1 "2020-02-12T07:19:51Z")

</div>

Discourse can syntax highlight several different coding languages (it uses `highlightjs` to do so) which can be specified if you use the backtick blocks, however it isn’t syntax highlight MATLAB syntax yet, so I was wondering if you could try to enable it in the discourse settings panel (there is an option for this apparently)?

```auto
% this is a test of MATLAB syntax highlighting, only generic things like strings 
% and numbers are highlighted, this comment is not, suggesting wrong language used
if a > b
    c = unint32(12);
else
    c = 'Char array';
end

```

```ruby
# Ruby code for comparison, note comments are coloured etc.
class Greeter
  def initialize(name)
    @name = name.capitalize
  end

  def salute
    puts "Hello #{@name}!"
  end
end

# Create a new object
g = Greeter.new("world")

# Output "Hello World!"
g.salute

```

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [February 12, 2020, 10:01am UTC](https://psychtoolbox.discourse.group/t/syntax-highlighting-matlab-code-in-forum-posts/3036/2 "2020-02-12T10:01:58Z")

</div>

For testing, the code from [here](https://highlightjs.org/static/demo/):

```matlab
n = 20; % number of points
points = [random('unid', 100, n, 1), random('unid', 100, n, 1)];
len = zeros(1, n - 1);
points = sortrows(points);
%% Initial set of points
plot(points(:,1),points(:,2));
for i = 1: n-1
    len(i) = points(i + 1, 1) - points(i, 1);
end
while(max(len) > 2 * min(len))
    [d, i] = max(len);
    k = on_margin(points, i, d, -1);
    m = on_margin(points, i + 1, d, 1);
    xm = 0; ym = 0;
%% New point
    if(i == 1 || i + 1 == n)
        xm = mean(points([i,i+1],1))
        ym = mean(points([i,i+1],2))
    else
        [xm, ym] = dlg1(points([k, i, i + 1, m], 1), ...
            points([k, i, i + 1, m], 2))
    end

    points = [points(1:i, :); [xm, ym]; points(i + 1:end, :)];
end

%{
    This is a block comment. Please ignore me.
%}

function [net] = get_fit_network(inputs, targets)
    % Create Network
    numHiddenNeurons = 20; % Adjust as desired
    net = newfit(inputs,targets,numHiddenNeurons);
    net.trainParam.goal = 0.01;
    net.trainParam.epochs = 1000;
    % Train and Apply Network
    [net,tr] = train(net,inputs,targets);
end

foo_matrix = [1, 2, 3; 4, 5, 6]''';
foo_cell = {1, 2, 3; 4, 5, 6}''.'.';

cell2flatten = {1,2,3,4,5};
flattenedcell = cat(1, cell2flatten{:});

```

Ok, can’t say the highlighting is particularly informative, but it works (i’ve changed the setting). Thanks for the report!

---

<div class="post-metadata">

**Author:** ![Ian-Max-Andolina](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ian-max-andolina/32/4_2.png) [@Ian-Max-Andolina](https://psychtoolbox.discourse.group/u/Ian-Max-Andolina)\
**Post date:** [February 12, 2020, 11:09am UTC](https://psychtoolbox.discourse.group/t/syntax-highlighting-matlab-code-in-forum-posts/3036/3 "2020-02-12T11:09:48Z")

</div>

Thanks Dee, possibly another highlighting style would be a bit clearer, but I think that is good enough!
