# Saved notebook in .tex format: how to recover?

I accidentally saved my notebook in the .tex format. Question, how can I get the original text back?

• I have never used this feature before, but having looked at the output it produces, I'm afraid to say that recovering the original Mathematica inputs and outputs looks like it will be very awkward and fraught with error. It may be best to produce a PDF from the TeX file and then copy and paste the code into a new notebook. – Oleksandr R. Nov 21 '15 at 23:04

As described in the Mathematica documentation for LaTex, it is possible to Import a .tex file into a notebook. Suppose we File>Save...

CircleTimes[a, b] := Times[a, b]
CircleTimes[b, a] := q Times[a, b]
CircleTimes[z_, z_] := Times[z, z]
CircleTimes[z__] := Module[{zz = {z}, tem}, tem = CircleTimes @@ zz[[-2 ;; -1]];
(CircleTimes @@ Join[zz[[1 ;; -3]], {First@tem}]) Rest@tem]


from Question 99970 to C:/Temp/99970.tex. Then, it can be retrieved into a new notebook by

Import["C:/Temp/99970.tex", "NotebookObject"]


After Cell>Convert To>InputForm, the result is recognizable as close to the original code

CircleTimes [a,b]:==Times [a,b]
CircleTimes [b,a]:==q Times [a,b]
CircleTimes [z _,z _]:==Times [z,z]
CircleTimes [z __]:==Module[{zz=={z},tem},tem==CircleTimes@@zz[[-2;;-1]];
(CircleTimes@@Join [zz [[1;;-3]],{First@tem}])Rest@tem]


but requires copying to a new notebook and modest editing, after which it executes as well as the original code. I wish I could say that all code can be recovered so easily. Code containing superscripts and subscripts is particularly messy. Perhaps, others with greater experience than I in low-level coding can improve on this answer.