Are there limitations in length of latex interpreted - expression in msgbox?

조회 수: 2 (최근 30일)
krissk
krissk 2016년 8월 23일
댓글: Jon White 2020년 9월 22일
This might be just a bit of a curiosity regarding the latex interpreter in msgbox.
I have an expression I want to display (mess_stringequiv), but am not able to get it right. I get a blank box and the message "Unable to interpret TeX string", when I include this one.
However, if I modify it slightly (e.g. mess_stringequiv5), it is no problem. The code under illustrates some trial of workarounds. Is there a way to get the string in mess_stringequiv to be displayed in a messagebox?
If not, is this due to the textwrap length setting in the msgbox (and is it possible to change that one)?
% code
clear all
clc
sz = get( 0, 'Screensize' );
CreateStruct.Interpreter = 'latex';
CreateStruct.WindowStyle = 'modal';
mess_stringequiv = ['$e= \frac{2}{\sqrt{3}} \ln((1 + \frac{\gamma^2}{2})^{0.5} + \frac{\gamma}{2}):$'];
mess_stringequiv2 = ['$e= 2/\sqrt{3}$',' ','$\ln((1 + \frac{\gamma^2}{4})^{0.5} + \frac{\gamma}{2})$: '];
mess_stringequiv3 = ['$e= \frac{2}{3}$',' ','$\ln((1 + \frac{\gamma^2}{4})^{0.5} + \frac{\gamma}{2})$: '];
mess_stringequiv4 = ['$e= \frac{2}{\sqrt{3}} \ln\left((1 + \frac{\gamma^2}{2})^{0.5}\right):$'];
mess_stringequiv5 = ['$e= \frac{2}{\sqrt{3}} \ln((1 + \frac{\gamma^2}{2})^{0.5} + \gamma/2):$'];
h = msgbox({mess_stringequiv2;mess_stringequiv3;mess_stringequiv4;mess_stringequiv5},'Success',CreateStruct);
ah = get( h, 'CurrentAxes' );
ch = get( ah, 'Children' );
set( ch, 'FontSize', 12 );
set(h, 'position', [(sz(3)-300)/2 (sz(4)-300)/2 300 300] ); %makes box bigger
waitfor(h)
close all
I am using MATLAB R2009a.
Thanks!

답변 (1개)

Natch Ruengsakulrach
Natch Ruengsakulrach 2016년 9월 1일
There is a bug in the way that "msgbox" always automatically wraps the text at 75 characters, regardless of which Interpreter is used. This may modify your LaTeX string into something which is no longer valid LaTeX syntax.
I have attached “mymsgbox.m” as a workaround. I work for MathWorks and have forwarded this feedback to the appropriate product team.
mess_stringequiv = ['$e= \frac{2}{\sqrt{3}} \ln((1 + \frac{\gamma^2}{2})^{0.5} + \frac{\gamma}{2}):$ '];
mess_stringequiv2 = ['$e= 2/\sqrt{3}$',' ','$\ln((1 + \frac{\gamma^2}{4})^{0.5} + \frac{\gamma}{2})$: '];
mess_stringequiv3 = ['$e= \frac{2}{3}$',' ','$\ln((1 + \frac{\gamma^2}{4})^{0.5} + \frac{\gamma}{2})$: '];
mess_stringequiv4 = ['$e= \frac{2}{\sqrt{3}} \ln\left((1 + \frac{\gamma^2}{2})^{0.5}\right):$'];
mess_stringequiv5 = ['$e= \frac{2}{\sqrt{3}} \ln((1 + \frac{\gamma^2}{2})^{0.5} + \gamma/2):$'];
h = mymsgbox({mess_stringequiv;mess_stringequiv2;mess_stringequiv3;mess_stringequiv4;mess_stringequiv5},'Success',CreateStruct);
  댓글 수: 3
Juan Estrella-Martínez
Juan Estrella-Martínez 2020년 6월 19일
Hey mate! I'm writing a script and would like to use the attached code. How should I credit you? Didn't see your info in the code.
Jon White
Jon White 2020년 9월 22일
Same here. Thank you for sharing!

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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by