MATLAB Answers

How to use the latex interpreter properly in appdesigner figures?

68 views (last 30 days)
Part 1:
I'm trying to print LaTeX text which is partly in math mode and partly in text mode to a figure in appdesigner. However, when I put text mode after math mode in the same string, only the text in math mode is displayed. Specifically, the line
text(app.UIAxes, .2, .5, '$test1$ test2', 'Interpreter', 'latex');
plots 'test1' in app.UIAxes and ignores 'test2'. When I take a look at app.UIAxes.Children.String, it does show the entire string I specified.
The same happens when I try to do it for figure titles or axis labels in appdesigner. It doesn't happen when I do it in a separate figure in a new window.
text(figure(1), .2, .5, '$test1$ test2', 'Interpreter', 'latex');
works fine).
text(app.UIAxes, .2, .5, 'test1 test2', 'Interpreter', 'latex');
text(app.UIAxes, .2, .5, '$test1 test2$', 'Interpreter', 'latex');
text(app.UIAxes, .2, .5, 'test1 $test2$', 'Interpreter', 'latex');
all work well.
What could cause this to happen?
A workaround could be to plot two strings separately, i.e., something like
text1 = text(app.UIAxes, .2, .5, '$test1$', 'Interpreter', 'latex');
text(app.UIAxes, text1.Extent(1)+text1.Extent(3), text1.Extent(2)+text1.Extent(4)/2, 'test2', 'Interpreter', 'latex');
but I'm wondering if it can be done in one line, as that would be much more convenient.
Part 2:
Similar to part 1, I'm trying to use a tabular in appdesigner, i.e.,
text(app.UIAxes, .2, .5, '\begin{tabular}{cc}1&2\\3&4\end{tabular}', 'Interpreter', 'latex');
but this results in '\begintabularcc1&2\3&4' being plotted. Again, it works fine if I do it in a separate figure. How to do this properly? I suppose a similar workaround as in Part 1 could apply but that seems very tedious.

  1 Comment

Ralf Hillebrand
Ralf Hillebrand on 8 Oct 2019
Part 1.:
You found a problem in the LaTeX parser of the equation renderer, which is used here. The text behind the equation part gets indeed lost. A shorter workaround would be to move text2 into the equation: $test1 \text{test2}$
Part 2:
The tabular environment is not part of the TeX commands supported by the equation renderer. Please check for the list of supported commands. The array environment is supported though and should do what you want: \begin{array}{cc}1&2\\3&4\end{array}

Sign in to comment.

Accepted Answer

Divya Yerraguntla
Divya Yerraguntla on 19 Sep 2019
Hi Rick,
I have brought this issue to the notice of our developers. They will investigate the matter further.


Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!