4
$\begingroup$

Before sending its output to the FrontEnd the Kernel converts it into boxes by applying MakeBoxes. But it is not the whole story. FrontEnd not just displays the box expression sent by the Kernel but preliminarily converts in into another box expression (usually even more verbose) apparently by applying something like its own internal analog of MakeBoxes.

In the Kernel we can access the conversion rules via FormatValues.

I have two questions:

  1. Is it possible to get the FrontEnd's conversion rules in any form?

  2. It seems that one way to get the final box expresison is

    ImportString[ExportString[expr, "NB"], "NB"][[1, 1, 1, 1]]
    

    Is there a more direct way?

$\endgroup$
  • $\begingroup$ I was using what you show in 2. $\endgroup$ – Kuba Mar 20 '17 at 7:02
  • $\begingroup$ Can you provide an example of such transformation on a front end side? $\endgroup$ – Kuba Apr 4 '17 at 14:34
  • $\begingroup$ @Kuba Everything related to GridBox undergoes such transformation, one practical example was discussed in this thread. $\endgroup$ – Alexey Popkov Apr 4 '17 at 14:44
  • $\begingroup$ I see, btw. I think even this method is not enough as a FrontEnd renames some symbols in cell expressions (DynamicModuleBox etc) based on current $Context and CellContext. It won't be reflected here. The only way I know is to really create such cell, e.g. CreateDocument and NotebookRead/Get from there. $\endgroup$ – Kuba Apr 10 '17 at 8:22
  • $\begingroup$ @Kuba It seems the ImportString/ExportString method does exactly this under the hood. It is easy to implement oneself though: toFinalBoxes[expr_]:=Module[{nb,nbObj=CreateDocument[expr,Visible->False]},nb=NotebookGet[nbObj];NotebookClose[nbObj];nb[[1,1,1,1]]]. $\endgroup$ – Alexey Popkov May 30 '17 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.