Programmatically add annotation with an equation to simulink

Hey all,
I'm trying to add an annotation to a Simulink model which includes an equation using Latex syntax. However, all I get is the plain text.
latexString = 'x = \frac{1}{2}'
h = Simulink.Annotation(gcs, latexString);
How exactly do I do this?
Thanks!

Answers (2)

Hi Cedric,
To add a Latex equation to a Simulink annotation, you need to use the Latex interpreter by setting the 'Interpreter' property of the annotation object to 'latex'. Refer the code below:
latexString = 'x = \frac{1}{2}';
h = Simulink.Annotation(gcs, latexString);
set(h, ' Description', 'latex');
You can also use the function ‘pslinkfun’ to programmatically add annotations to a block in a model.
Please refer to the documentation below for more information.
Hope this helps!!

1 Comment

But there is no option to set the interpreter to latex. There is only off, rich and tex. Also, you changed the description parameter and not the interpreter

Sign in to comment.

Michael
Michael on 22 May 2026 at 10:09
Edited: Michael on 22 May 2026 at 10:16
Hi, I use this approach:
notePath = "Subsystem/BlockName"; % Replace it with the path to your annotation
Text = "$\text{Description:}\\\frac{a}{b}$" % This is the text displayed in the annotation
richText = "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN' 'http://www.w3.org/TR/REC-html40/strict.dtd'><html><head><meta name=""qrichtext"" content=""1""/><style type=""text/css"">p, li { white-space: pre-wrap; }</style></head><body align=""left"" style="" font-family:'Helvetica'; font-size:10px; font-weight:400; font-style:normal;""><p align=""left"" style="" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;""><math style=""font-size:10px;"">" + Text + "</math></p></body></html>";
Position = [0 0 20 20]; % Specify the location
% Finaly create the annotation
h = add_block('built-in/Note', notePath, ...
'Interpreter', 'rich', ...
'Text', richText, ...
'Position', Position);
Then you get a tex formated annotation.

Categories

Products

Release

R2021a

Asked:

on 13 Feb 2023

Edited:

on 22 May 2026 at 10:16

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!