We have a string that has "tab" symbol between letters "B" and "C" and "newline" symbol between letters "C" and "D":


"A B\tC\nD"


enter image description here

The output is formatted accordingly to special symbols used.

But when I export the same string to LaTeX, the special symbols \n and \t are interpreted literally like so:


ExportString["A b\tc\nd", "TeXFragment"]


\[\text{A b$\backslash $tc$\backslash $newlined}\]

If you put this Latex code into some TeX file the document will display literally "A B\tC\nD" and without "tab" and "newline" symbols.

How to tell the Mathematica to export the special symbols into LaTeX accordingly?

  • 1
    $\begingroup$ Why don't you use "Text" as the format since you don't need any special TeX markup? $\endgroup$
    – Somos
    Nov 23, 2020 at 22:43
  • $\begingroup$ Because I want to save it into TeX file - that is why I exported it into TeXFragment. $\endgroup$ Nov 23, 2020 at 22:57
  • 1
    $\begingroup$ Okay. What do you want the Mathematica output string result to be? Please include that information in your question. $\endgroup$
    – Somos
    Nov 23, 2020 at 23:06
  • 1
    $\begingroup$ Do you see the first output? That is what I want but not inside mathematica but inside TeX document. You can use instead ExportString["A B\tC\nD", "TeX"] then save the output string to file.tex then open that file and you will see that the output in the TeX file is without tab and newline. $\endgroup$ Nov 23, 2020 at 23:25
  • 1
    $\begingroup$ A "TeX" or "LaTeX" file is just a file with text characters except there are conventions on how to interpret those text characters. Thus, in your case, what is the string of text characters that you want to be in the file? You need to specify that in your question. This seems to be a TeX question and not a Mathematica question. $\endgroup$
    – Somos
    Nov 23, 2020 at 23:30

1 Answer 1


Does this work for you?

txt =
 A b\tc\nd
ExportString[txt, "Text"]


  • $\begingroup$ This seem to work. But it is just a manual workaround. Why it does not work with Mathematica's original functions that are built for exporting to TeX files? Why they interpret "\t" literally as "\t" and not as "TAB" when Mahtmeatica itself interprets it is "TAB"? $\endgroup$ Nov 24, 2020 at 9:05
  • $\begingroup$ @azerbajdzan. I can't answer that. I'm just another Mathematica user. You could try asking Wolfram tech support. $\endgroup$
    – m_goldberg
    Nov 24, 2020 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.