Publish symbolic equation to Latex with latex(symbolic equation)

조회 수: 10 (최근 30일)
TS
TS 2017년 4월 16일
댓글: An 2017년 12월 30일

How to publish a symbolic equation such as y(x) (see code below) to latex using the Matlab publisher? Or specifically is it possible to generate a dynamic commend or define that a string is interpreted as a latex expression by the publisher?

 %% Demonstration
  %%
  % *Text*
  syms x
  y(x)=sin(x)/pi;
  latex(y)
latex(y)
%%
% $latex(y)$ 

latex(y) prints the latex code for the equation y to the command window. I want to tell the matlab publisher that it shall interpret this as a Latex formated expression (which it is). Ideal would be a solution like latexpublisher(latex(y)).

Please note that i found several workarounds which are all unsuitable imo. I am using Matlab 2016b

  댓글 수: 1
An
An 2017년 12월 30일
Did you find out how to do this? I've spent a while in google, to no avail...

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

답변 (1개)

Sonam Gupta
Sonam Gupta 2017년 4월 19일
I think that the functionality that you are looking for is same as what the text() command provides. It gives you an option to specify the Interpreter as Latex. Below code shows how you can use it:
syms x
y(x)=sin(x)/pi;
str = latex(y);
axis off
text(0.5, 0.5, ['$$' str '$$'], 'Interpreter','latex', 'FontSize',28, ...
'HorizontalAlignment','center', 'VerticalAlignment','middle')
For more information about the text command, you can refer to following documentation link:
Hope this helps!
  댓글 수: 2
TS
TS 2017년 4월 19일

Thanks for the reply, yet text() is not what i am looking for. Using text inserts a latex interpreted text inside a plot. Converting that .m file to latex using the publisher produces (rightfully so, becouse that is, what using text() should do):

    \begin{verbatim}
 syms x
 y(x)=sin(x)/pi;
 str = latex(y);
 axis off
 text(0.5, 0.5, ['$$' str '$$'], 'Interpreter','latex', 'FontSize',28, ...
    'HorizontalAlignment','center', 'VerticalAlignment','middle')
\end{verbatim}
\includegraphics [width=4in]{symbolic_test_01.eps}

Yet the desired output should look like something close to:

   \begin{verbatim}
   syms x
   y(x)=sin(x)/pi;
   str = latex(y);
  \end{verbatim}
  \begin{par}
  $$\frac{\sin\!\left(x\right)}{\pi}$$
  \end{par} \vspace{1em}

Generated by using a function(latex(y)) command to explicit tell the publisher that the EQUATION in function(EQUATION) should be published as an equation (the same way putting the equation into the comments usin

 %%
 % 
 % $$\frac{\sin\!\left(x\right)}{\pi}$$
 %

The problem with the comment solution is, that its static

Sonam Gupta
Sonam Gupta 2017년 4월 21일
As far as I know the ability to replace the variable name with its value from the workspace for latex equations is not there.

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

Community Treasure Hunt

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

Start Hunting!

Translated by