Warning: Unable to interpret LaTeX string

hi. i want to make a text annotation including this text:
eval(['text1=''\underline{Row #', num2str(j), '}'';'])
annotation('textbox', [a b c d] , 'String', text1, 'VerticalAlignment', 'middle', 'HorizontalAlignment', 'center', 'Color', 'k', 'EdgeColor', 'k', 'BackgroundColor', 'white', 'FontWeight', 'bold', 'FontSize', 15, 'interpreter','latex');
i get an error: Warning: Unable to interpret LaTeX string "\underline{Row #1}"
how can i solve this?
thanks. Noa

5 件のコメント

noa
noa 2012 年 9 月 20 日
nope, i googled it and that is the answer that it gave... how can i underline?
Jan
Jan 2012 年 9 月 20 日
Btw. Please do you the favour and omit the eval(). Simply type:
text1 = sprintf('\underline{Row #%d}', j);
noa
noa 2012 年 9 月 20 日
Warning: Invalid escape sequence appears in format string. See help sprintf for valid escape sequences
Matt Fig
Matt Fig 2012 年 9 月 20 日
編集済み: Matt Fig 2012 年 9 月 20 日
Jan, it should be:
text1 = sprintf('\\underline{Row #%d}', j);
But there is more to it than that. See my answer below.
Jan
Jan 2012 年 9 月 20 日
@noa: And? Did you follow the advice to read "help sprintf" to find out, that a \\ is required to create a \ in the output string? Or do you try that it is my turn to find this out?
@Matt: Thanks.

サインインしてコメントする。

回答 (2 件)

Matt Fig
Matt Fig 2012 年 9 月 20 日
編集済み: Matt Fig 2012 年 9 月 20 日

3 投票

First of all you really should learn to use SPRINTF instead of EVAL. Please look at the help for SPRINTF and do not use EVAL in your code.
J = 5;
text1 = sprintf('$$\\underline{Row\\#\\;%i }$$',J);
text(.5,.5,text1,'interpreter','latex')
Or if J is a floating point number and not an integer:
J = 5.34;
text1 = sprintf('$$\\underline{Row\\#\\;%2.2f }$$',J);
text(.5,.5,text1,'interpreter','latex')
Jan
Jan 2012 年 9 月 20 日
編集済み: Jan 2012 年 9 月 20 日

0 投票

text(0.5, 0.5, '\underline{Hello World}','interp','latex')
I cannot test this currently, but Daniel's answer sounds, like this is not working.

2 件のコメント

noa
noa 2012 年 9 月 20 日
??? Subscript indices must either be real positive integers or logicals.
Jan
Jan 2012 年 9 月 20 日
@noa: This happens, when you use "text" as name of a variable:
clear('text');
text(0.5, 0.5, 'hello');
text = 'any string';
text(0.5, 0.5, 'hello');
Solution: do not use names of Matlab functions as variables.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

タグ

質問済み:

noa
2012 年 9 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by