# How can I convert a formatted text cell to latex code?

I have a formatted text cell, I want to export it as latex. How can I do that? Since copy as LaTeX doesn't work, I thought of pasting it into a string and exporting, but it's a no go:

 ExportString["Let M be a TM and let \!$$\*FormBox[\(A \[SubsetEqual] \ \*SuperscriptBox[\({0, 1}$$, $$*$$]\),
TraditionalForm]\). We say that \!$$\*FormBox[\(M decides A$$,
TraditionalForm]\) if \!$$\*FormBox[\(\[ForAll] \\\ x \[Element] \ \*SuperscriptBox[\({0, 1}$$, $$*$$]\),
TraditionalForm]\), \!$$\*FormBox[\(x \[Element] A\\\ \[Implies] \\\ \ M(x) = 1$$,
TraditionalForm]\), \!$$\*FormBox[\(x \[NotElement] A\\\ \[Implies] \ M(x) = 0.$$,
TraditionalForm]\) We say that  \!$$\*FormBox[\(A \[SubsetEqual] \ \*SuperscriptBox[\({0, 1}$$, $$*$$]\),
TraditionalForm]\) is \!$$\* StyleBox[\"decidable\",\nFontWeight->\"Bold\"]$$ if there is a TM \
that accepts it.", "TeX"]

-
Just to get the correct string before programming anything: I guess you're missing $$ before the second M and $$ after the following A. – einbandi Nov 20 '12 at 15:21

str3 = StringReplace[str2,
RegularExpression["»(.*?)«"] :>
If[StringLength["$1"] == 0, "", "\$$1\$"]] //
StringReplace[#, {"«" -> "", "»" -> ""}] &


Then Copy As -> Plain Text:

Past into SE editor:

Let $M$ be a TM and let $A\subseteq \{0,1\}^*$. We say that $M$ decides $A$ if $\forall x\in \{0,1\}^*$, $x\in A\Rightarrow M(x)=1$, $x\notin A\Rightarrow M(x)=0$. We say that $A\subseteq \{0,1\}^*$ is decidable if there is a TM that accepts it. And here is an inline complicated formula: $\sum _{k=1}^n \frac{1}{f(k)}\int_{\alpha }^{\beta } \sqrt{g(x)} \, dx$, but need some text after it.

Though looks working, this procedure is very primary and buggy. e.g. The $TM$s in the original Text` Cell are actually in math-mode (i.e. inputted after a Ctrl+9), but they were converted to text-mode when copy as LaTeX. And when the paragraph ends with a formula, it should be take care of with special rule.

-
Thanks @silvia for your solution, but I feel that the other one is simpler... – M.R. Nov 26 '12 at 18:50
@M.R. of course~ I absolutely agree with you :) – Silvia Nov 27 '12 at 15:03