latex output to .txt format

17 vues (au cours des 30 derniers jours)
Mohammadfarid ghasemi
Mohammadfarid ghasemi le 24 Juil 2021
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,

Réponses (2)

Daniel Pusicha
Daniel Pusicha le 19 Juil 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);

Yongjian Feng
Yongjian Feng le 24 Juil 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 commentaire
Daniel Pusicha
Daniel Pusicha le 19 Juil 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);
Warning: Escaped character '\m' is not valid. See 'doc sprintf' for supported special characters.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by