jkuczm / MathematicaCellsToTeX

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

TemplateBox with RowDefault tag is unsupported #30

Open vsht opened 4 years ago

vsht commented 4 years ago

It appears that a TemplateBox containing a "RowDefault" tag cannot be processed properly. Cf. e.g. this typesetting code from https://mathematica.stackexchange.com/questions/174627/writing-partial-differentiation-in-a-subscript/174630#174630

Derivative /: MakeBoxes[
    Derivative[n_Integer?NonNegative, m_Integer?NonNegative][f_], form_
] := SubscriptBox[
    MakeBoxes[f, form],
    TemplateBox[Join[ConstantArray["x", n], ConstantArray["y", m]],"RowDefault"]
]

When trying to apply CellToTeX to

Derivative[1, 0][f][x, y]

as in

CellToTeX[
 Cell[BoxData[
   FormBox[RowBox[{SubscriptBox["f", 
       TemplateBox[{"x"}, "RowDefault"]], "(", 
      RowBox[{"x", ",", "y"}], ")"}], TraditionalForm]], "Output"]]

the function fails.

According to

https://mathematica.stackexchange.com/questions/55363/incompatibility-of-row-and-texform/182382#182382

"RowDefault" was introduced in Mma 9. Indeed I can workaround the issue if I generate my cells in Mma 8, where no such tags arise.

jkuczm commented 4 years ago

Similarly to linked answer, workaround for this problem is to replace internal function, used by CellsToTeXto convert TemplateBoxes, with builtin one:

CellsToTeX`Internal`templateBoxDisplayBoxes = BoxForm`TemplateBoxToDisplayBoxes;

I guess I was not aware of existence of BoxForm`TemplateBoxToDisplayBoxes function, when I started this package, so I created my own imperfect version.

vsht commented 4 years ago

Great, many thanks for this fix. I really appreciate all your work on this package. Over the years it saved me a lot time in getting MMa output into LaTeX.

BTW, what would be the preferred way to cite CellsToTeX in a publication? Is there perhaps a Zenodo-DOI ? https://guides.github.com/activities/citable-code/