Class that outputs text with formulas in livesript
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
I know that symbolic expressions are nicely displayed, but there are heavy limitations I cannot live with.
To name one: What if I want my symbolic variable ddtheta to show as . No way.
As there is no way to change the output behaviour of the symbolic toolbox up to this point,. I would like to write my own class, that outputs nicely formated formulas as desired.
I dont want a work arround as to use a msgbox displaying the formula.
This should not be that difficult, as symbolic classes have a natural ouput in this direction.
Can you point me to the right direction for implementation?.
I belive this is an important feature, is Mathworks going to implement something aroun this line?, like, forexample, extending disp allowing to include $a encapsulated formula$.
Thanks in advance.
댓글 수: 0
답변 (2개)
arushi
2023년 10월 5일
편집: Walter Roberson
2023년 10월 5일
Hi Javier,
I understand that you would like to write a customized class that outputs nicely formatted formulas as desired.
You can define a custom class in MATLAB and override the "disp" method to control the display behaviour. Here is an example of a custom class which displays formulas as the desired:
classdef CustomFormula
properties
formula % Store the formula as a property
end
methods
% Constructor
function obj = CustomFormula(formula)
if nargin > 0
obj.formula = formula;
end
end
% Override disp method for custom display
function disp(obj)
% Format the formula as desired
formattedFormula = obj.formatFormula();
% Display the formatted formula
disp(formattedFormula);
end
% Custom method to format the formula
function formattedFormula = formatFormula(obj)
% Implement your own formatting logic here
% You can use string manipulation or LaTeX formatting
% Example: Replace ddtheta with \ddot{\theta}
formattedFormula = strrep(obj.formula, "ddtheta", "$\ddot{\theta}$");
end
end
end
In this example, the "CustomFormula" class is defined with a formula property to store the formula. The "disp" method is overridden to control the display behaviour. Inside the "disp" method, you can implement your own formatting logic in the "formatFormula" method.
You can customize the "formatFormula" method to apply your desired formatting rules to the formula string. In the example, it uses "strrep" to replace the string 'ddtheta' with the LaTeX representation '\ddot{\theta}'.
Once you have defined the "CustomFormula" class, you can create instances of it and display them using the "disp" function.
% Create a CustomFormula object
formulaObj = CustomFormula('ddtheta + 2 * theta');
% Display the formatted formula
disp(formulaObj);
I hope this helps you create a customized class.
댓글 수: 2
Walter Roberson
2023년 10월 5일
Is the task to emit latex code because you intend to copy it to somewhere else?
Is the task to emit latex code with the intention that livescript will render the latex code?
Is the task to dynamically emit something that will get rendered in livescript ?
Walter Roberson
2023년 10월 5일
What if I want my symbolic variable ddtheta to show as
syms ddtheta x
f = sin(x) + ddtheta
subs(f, ddtheta, sym('theta_ddot'))
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!