7
$\begingroup$

The instruction :

DisplayForm[RowBox[List[0,1,Superscript[2,3],Superscript[1,2],a]]]

displays a gap between the first two items of the list

enter image description here

but if one is careful not to have two consecutive integers, there is no gap

DisplayForm[RowBox[List[0,a,1,Superscript[2,3],Superscript[1,2],a]]]

enter image description here

I would like to know if there is a way to disable (locally) the space inserted by Mathematica between two integers in this case to have something like that:

enter image description here

I would like the result to stay a TagBox or InterpretationBox, easy to copy/paste, if possible.

$\endgroup$
3
  • $\begingroup$ Out of upvotes for another 5 hours, otherwise +1, it's an interesting question. $\endgroup$
    – rcollyer
    Commented Jan 18, 2012 at 18:24
  • 1
    $\begingroup$ @rcollyer Let me do that for you. I have some left ;-) $\endgroup$ Commented Jan 18, 2012 at 18:33
  • $\begingroup$ @SjoerdC.deVries, I just needed a little patience. I've got 40 more upvotes to burn, who wants them? $\endgroup$
    – rcollyer
    Commented Jan 19, 2012 at 2:54

3 Answers 3

6
$\begingroup$

Why not use ToBoxes (or MakeBoxes) to construct boxes, instead of doing it yourself?

DisplayForm[
 ToBoxes[Row[List[0, 1, Superscript[2, 3], Superscript[1, 2], a]]]]

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ You are right, this is the correct way in general. The trouble was that I created these expressions incrementally, wanting to keep an easy way to retrieve the data into it, and got lost in the process. $\endgroup$
    – ogerard
    Commented Jan 18, 2012 at 22:35
6
$\begingroup$

This is caused by the AutoMultiplicationSymbol option in the front end.

SetOptions[$FrontEnd, AutoMultiplicationSymbol -> False]

Will make the space disappear.

$\endgroup$
5
  • 2
    $\begingroup$ or just use Style rather than set it globally: DisplayForm[ Style[RowBox[List[0, 1, Superscript[2, 3], Superscript[1, 2], a]], AutoMultiplicationSymbol -> False]] $\endgroup$ Commented Jan 18, 2012 at 22:22
  • $\begingroup$ I agree that setting the options globally for a FrontEnd or a Notebook is not what is wanted in general. @mike : Or one can define/use a style with this option turned false. $\endgroup$
    – ogerard
    Commented Jan 18, 2012 at 22:38
  • $\begingroup$ @ragfield : your answer is correct and welcome because it outlines the mechanism causing the space in the first place. But Brett's answer is the one I will accept as it points out a more idiomatic way of producing the kind of objects I wanted initially. $\endgroup$
    – ogerard
    Commented Jan 18, 2012 at 22:42
  • 2
    $\begingroup$ You can also interpose "\[InvisibleSpace]" between arguments, which instructs the FE that we are definitely not doing multiplication. The advantage to "\[InvisibleSpace]" is that it can be applied more selectively. If you look at how the Row typesets in Brett's solution, you'll see that's what it's doing. $\endgroup$
    – John Fultz
    Commented Feb 6, 2012 at 17:17
  • $\begingroup$ @John More specifically: 2\[InvisibleSpace]3 is interpreted as multiplication by the FrontEnd but is shown as 23 instead of 2×3. $\endgroup$ Commented Apr 9, 2012 at 9:44
2
$\begingroup$

I thought it might have to do with reserving space for an invisible plus sign. In that case wrapping the 1 in NumberForm would get rid of this nagging space (adding an explicit NumberSigns isn't necessary as NumberForm already has the correct default value for this option).

DisplayForm[RowBox[List[0, NumberForm[1], Superscript[2, 3], Superscript[1, 2], a]]]

Mathematica graphics

But this leaves me wondering why the space isn't there when you precede it with a character 'a'.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.