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

1 次查看(过去 30 天)
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
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
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by