jkuczm / MathematicaCellsToTeX

Convert Mathematica cells to TeX, retaining formatting.
Other
57 stars 10 forks source link

Bug in boxesToString Function #2

Closed baryonicnonsense closed 8 years ago

baryonicnonsense commented 8 years ago

When using FormatType of "Input" or "Code" the output is littered with the useless string wBox. Your example of

testCell = Cell[BoxData[MakeBoxes[Subscript[x, 1] == (-b \[PlusMinus] Sqrt[b^2 - 4 a c])/(2 a)]], "Input"];
testCell // CellPrint
CellToTeX[testCell]

from the Mathematica StackExchange yields

\begin{mmaCell}{Input}
    \mmaSub{wBox[\{"x"}{wBox[\{"1"}wBox[\{"=="\mmaFrac{wBox[\{"-"wBox[\{"b"wBox[\{"\(\pm\)"\mmaSqrt{\mmaSup{wBox[\{"b"}{wBox[\{"2"}wBox[\{"-"wBox[\{"4" wBox[\{"a" wBox[\{"c"}}{wBox[\{"2" wBox[\{"a"}
\end{mmaCell}

The bug is in the boxesToString function at line 1210-1211.

makeStringDefault[str_String] :=
    StringTake[ToString[RowBox[{str}]], {3, -3}];

should read

makeStringDefault[str_String] :=
    StringTake[ToString[RowBox[{str}]], {10, -4}];

This change eliminates the wBox string from the output, as confirmed by the output once changed:

\begin{mmaCell}{Input}
    \mmaSub{x}{1}==\mmaFrac{-b\(\pm\)\mmaSqrt{\mmaSup{b}{2}-4 a c}}{2 a}
\end{mmaCell
jkuczm commented 8 years ago

Thanks for reporting this and digging to exact spot where it occurs.

Described behavior is specific to version 10.2 of Mathematica which is not yet officially supported by CellsToTeX package and not included in automatic testing.

I believe this is a bug in Mathematica v10.2 since ToString stopped supporting documented syntax. I'll report it to WRI and wait with fixes till their response.

jkuczm commented 8 years ago

It turns out this is not a bug, but intentional change in v10.2, that was not properly documented.

I hope you don't mind if I label this issue as a feature request to support v10.2 and not as a bug in CellsToTeX package.

jkuczm commented 8 years ago

Version 0.1.2, with support for Mathematica 10.2, released. @baryonicnonsense Thanks once again for reporting this issue.

baryonicnonsense commented 8 years ago

Your update works perfectly. I'd like to say thanks too, this is a pretty neat utility that's very appreciated.

jkuczm commented 8 years ago

I'm glad someone found it useful.