4
$\begingroup$

How to overwrite the display function of TemplateBox? For example, if I have:

NotebookWrite[InputNotebook[], ToBoxes@Quantity[3, "Meters"]] 

how do I overwrite the DisplayFunction to make the out put display differently, without changing the actual value of the output?

$\endgroup$

1 Answer 1

5
$\begingroup$

Boxes are just like any other expression when they are evaluated by the kernel, so one way to achieve this is with replacement rules:

ToBoxes@Quantity[3, "Meters"] /. (DisplayFunction -> _) -> (DisplayFunction -> (RowBox@{#1, " метра"} &)) // RawBoxes 

3 метра

$\endgroup$
1
  • $\begingroup$ This no longer works with TemplateBoxes. Now it's unclear how to change the specific DisplayFunction of some (possibly deep) style without modifying the stylesheet. $\endgroup$ Commented Nov 12, 2024 at 17:52

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.