Transform variables with underscore symbol into subscripts when exporting to Latex from a Live Script

3 visualizaciones (últimos 30 días)
Hello, I am starting to use Live Scripts, and have been trying to produce nicely formatted output using the export to Latex option. It works in general very well, but I can't get the functions with subscripts written properly. For instance, this short code that I was using in a live script, when exported to Latex will deliver "f_0" written as f with a subscript 0 (which is ok), but "f_1" remains as "f_1". Certainly I can always edit the latex output file and modify it manually, but I wandered if there exists an automated way to get all "_" texts as function subscripts when exporting to Latex from a live script. Also, for instance, expressions such as "f_{max}". Thanks!
Clear the workspace and define MATLAB symbolic variables for independent variables.
clear all; close all;
Define symbolic quantities and declare them to be positive (and implicitly then real not complex).
syms t A B f_0 n positive
Perform symbolic integration catching a symbolic expression.
f_1=f_0+int(A*t^n-B*t,t,0,t)
f_1 = 

Respuestas (1)

Walter Roberson
Walter Roberson el 8 de Jun. de 2025
Editada: Walter Roberson el 8 de Jun. de 2025
The key to this is that the left-hand side of an assignment is never formatted.
syms t A B f_0 f_1 n positive
eqn = f_1 == f_0+int(A*t^n-B*t,t,0,t);
disp(eqn)
latex(eqn)
ans = 'f_{1}=f_{0}-\frac{B\,t^2}{2}+\frac{A\,t^{n+1}}{n+1}'

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by