LaTex Interpreter does not work correctly?

조회 수: 61 (최근 30일)
Thomas Lex
Thomas Lex 2022년 12월 29일
댓글: Cameron 2022년 12월 30일
Dear Helpers,
I'd like to plot some data and annotate the YAxis according to the following code using the latex interpreter:
plot(Tx',drhodT','LineWidth',1.5)
legend(LoF,'Location','eastoutside')
grid on
xlabel('Temperature [K]')
ylabel('$\frac{\partial\rho}{\partial T}$ [kg/m³/K]','Interpreter','latex')
When plot appears, also following error message is enclosed.
I wonder why the error message shows two backslashed instead of one single backslash which I coded.How to rectify this problem.
Looking forward to receiving your suggestions.
Best regards
Tom

채택된 답변

Walter Roberson
Walter Roberson 2022년 12월 29일
ylabel('$\frac{\partial\rho}{\partial T} [kg/m^3/K]$','Interpreter','latex')
The ³ character is not accepted for latex
To correct for that you need to use ^ but that is only accepted inside $$
You should probably rewrite the unit using frac
  댓글 수: 3
Cameron
Cameron 2022년 12월 29일
이동: Walter Roberson 2022년 12월 29일
Walter's answer works for me.
plot(1:20,rand(1,20),'LineWidth',1.5)
legend('data','Location','eastoutside')
grid on
xlabel('Temperature [K]')
ylabel('$\frac{\partial\rho}{\partial T} [kg/m^3/K]$','Interpreter','latex')
Which version of MATLAB are you using?
Walter Roberson
Walter Roberson 2022년 12월 29일
편집: Walter Roberson 2022년 12월 29일
Let us experiment:
figure()
subplot(1,4,1)
ylabel('\frac{\partial\rho}{\partial T} kg/ m³', 'interpreter', 'latex'); title('A1');
subplot(1,4,2)
ylabel('$\frac{\partial\rho}{\partial T} kg/ m³$', 'interpreter', 'latex'); title('A2');
subplot(1,4,3);
ylabel('\frac{\partial\rho}{\partial T} kg/ $m³$', 'interpreter', 'latex'); title('A3');
subplot(1,4,4);
ylabel('$\frac{\partial\rho}{\partial T} kg/$ m³', 'interpreter', 'latex'); title('A4');
Warning: Error updating Text.

String scalar or character vector must have valid interpreter syntax:
$\frac{\partial\rho}{\partial T} kg/$ m³
figure()
ylabel('m³', 'interpreter', 'latex'); title('AA1');
Warning: Error updating Text.

String scalar or character vector must have valid interpreter syntax:

figure()
ylabel('$m³$', 'interpreter', 'latex'); title('AA2');
Warning: Error updating Text.

String scalar or character vector must have valid interpreter syntax:
$m³$
figure()
ylabel('m^3', 'interpreter', 'latex'); title('AA3')
Warning: Error updating Text.

String scalar or character vector must have valid interpreter syntax:
m^3
figure()
subplot(1,4,1)
ylabel('\frac{\partial\rho}{\partial T} kg/ m^3', 'interpreter', 'latex'); title('B1');
subplot(1,4,2)
ylabel('$\frac{\partial\rho}{\partial T} kg/ m^3$', 'interpreter', 'latex'); title('B2');
subplot(1,4,3)
ylabel('\frac{\partial\rho}{\partial T} kg/ $m^3$', 'interpreter', 'latex'); title('B3');
subplot(1,4,4)
ylabel('$\frac{\partial\rho}{\partial T} kg/$ m^3', 'interpreter', 'latex'); title('B4');
Warning: Error updating Text.

String scalar or character vector must have valid interpreter syntax:
$\frac{\partial\rho}{\partial T} kg/$ m^3
figure();
subplot(1,4,1)
ylabel('\frac{\partial\rho}{\partial T} kg/ m³', 'interpreter', 'tex'); title('C1');
subplot(1,4,2)
ylabel('$\frac{\partial\rho}{\partial T} kg/ m³$', 'interpreter', 'tex'); title('C2');
subplot(1,4,3)
ylabel('\frac{\partial\rho}{\partial T} kg/ $m³$', 'interpreter', 'tex'); title('C3');
subplot(1,4,4)
ylabel('$\frac{\partial\rho}{\partial T} kg/$ m³', 'interpreter', 'tex'); title('C4');
Warning: Error updating Text.

String scalar or character vector must have valid interpreter syntax:
$\frac{\partial\rho}{\partial T} kg/$ m³
figure();
subplot(1,4,1)
ylabel('\frac{\partial\rho}{\partial T} kg/ m^3', 'interpreter', 'tex'); title('D1');
subplot(1,4,2)
ylabel('$\frac{\partial\rho}{\partial T} kg/ m^3$', 'interpreter', 'tex'); title('D2');
subplot(1,4,3)
ylabel('\frac{\partial\rho}{\partial T} kg/ $m^3$', 'interpreter', 'tex'); title('D3');
subplot(1,4,4)
ylabel('$\frac{\partial\rho}{\partial T} kg/$ m^3', 'interpreter', 'tex'); title('D4');
Warning: Error updating Text.

String scalar or character vector must have valid interpreter syntax:
$\frac{\partial\rho}{\partial T} kg/$ m^3
You can see from AA1 and AA2 that you can include the ³ character in latex, and it will give you the ³ output, but that it will generate the warning message regardless of being inside $$ or not.
You can see that the only one of these that works as you would hope is B2: $\frac{\partial\rho}{\partial T} kg/ m^3$ intepreter latex.
You can see from the A series that when the ³ character is included, that the entire string goes uninterpreted and is just put up (some as if you used interpreter 'none')
You can also see that when you use ^ to get the raised 3, then that can work -- but only if you are inside $$

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Thomas Lex
Thomas Lex 2022년 12월 30일
Hello Walter, hello Cameron,
thanks for your contributions.
Interesting insights. Obiously Matlab is very sensitive on what is written within the '...' when Interpreter ist activated for LaTex Following label worked fine
ylabel('Dichteaenderung $\, \left.\frac{\partial\rho}{\partial T}\right|_{x=0} [kg/m^3/K]$','Interpreter','latex')
But the line
ylabel('Dichteänderung $\, \left.\frac{\partial\rho}{\partial T}\right|_{x=0} [kg/m^3/K]$','Interpreter','latex')
did not work even though the word Dichteänderung ist not inside the $ $ environment. Which is obviouly due to the ä and which is the case for the ³. Both are non standard ascii characters.
Thanks a lot to you guys, who helped me to improve my Matlab knowledge!
My conclusion: When Latex-Interpreter is activated for text, labels, tilles etc., never use any non standard ascii character inside the inverted commas ' ' .
I would be happy to see this statement in the correspondent Matlab Help Center pages.
Best regards
Tom
  댓글 수: 1
Cameron
Cameron 2022년 12월 30일
This worked for me.
ylabel('$Dichte\ddot{a}nderung \, \left.\frac{\partial\rho}{\partial T}\right|_{x=0} [kg/m^3/K]$','Interpreter','latex')

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by