latex output to .txt format
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mohammadfarid ghasemi
el 24 de Jul. de 2021
Respondida: Daniel Pusicha
el 19 de Jul. de 2022
Hi,
I transfered some equations into latex and want to save the output as .txt format, can anyone tell me how can I do it?
thanks,
0 comentarios
Respuestas (2)
Daniel Pusicha
el 19 de Jul. de 2022
As Yongjian Feng suggested, the expression can be written to a .txt file using the fprint function. First we have to create a LaTeX character array from a symbolic expression:
syms test
formula = latex(test); % This produces the output '\mathrm{test}'
LaTeX expressions in general contain commands which are denoted by a backslash. However, the function that is used to write strings to .txt file uses the backslah for formatting. Replacing the backslash with a double backslash solves this problem:
formula = strrep(formula, '\', '\\');
Finally, the character array can be written to the file:
fid = fopen('test_file.txt','wt');
fprintf(fid, formula);
fclose(fid);
0 comentarios
Yongjian Feng
el 24 de Jul. de 2021
So you convert some equations into latex as a string, right? Then you can just follow this to write the string into a .txt file:
https://www.mathworks.com/matlabcentral/answers/110573-write-string-in-text-file
1 comentario
Daniel Pusicha
el 19 de Jul. de 2022
I think there is at least one further step necessary as the latex expression will certainly contain some backslashes however fprintf() interprets a backslash as some formatting command.
syms test
formula = latex(test); % This produces the output '\mathrm{test}'
fid = fopen('test_file.txt','wt');
fprintf(fid, formula);
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!