Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Getting stylized text with a palette button

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28563] Re: Getting stylized text with a palette button
  • From: paulh at wolfram.com (P.J. Hinton)
  • Date: Fri, 27 Apr 2001 03:56:17 -0400 (EDT)
  • Organization: Wolfram Research, Inc.
  • References: <9c7ned$sep@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 25 Apr 2001 19:43:09 -0400, Raul Martinez <rmartinez at vrinc.com>
wrote:

> I would like to define a palette with buttons that produce stylized text
> in a notebook Text cell. The following is a specific example.  While in
> a Text cell, I want to click a button that produces the symbol x[n] in
> Times font and with the x and n in italics.
> 
> So I produced a palette with a single button containing x[n] with the
> Times font and the desired italics. The results are puzzling. When I
> click the button while in a Text cell I get x[n] in plain Courier font.
> But I get the x[n] I want when I click the button while in an Input
> cell. Changing the Input cell to a Text cell causes x[n] to change from
> Times/italics to Courier/plain, which is of course the same result I get
> by starting in a Text cell.

Here is button that will accomplish what you desire.

ButtonBox[
  FormBox[
    StyleBox[RowBox[{"x", "[", "n", "]"}], "TR"], 
    TraditionalForm
  ],
  ButtonEvaluator -> None,
  ButtonFunction :> (NotebookWrite[FrontEnd`InputNotebook[], #2] &),
  ButtonData ->
    Cell[
     BoxData[FormBox[RowBox[{"x", "[", "n", "]"}], TraditionalForm]]
    ]
] // DisplayForm

Some things to note about this approach:

1) We use a TraditionalForm FormBox wrapper around the content to
obtain italicized single letters.  This is because the TraditionalForm
format type is has the option setting SingleLetterItalics -> True.

2) The "TR" is one of many inline styles that can be used to force the
choice of a font.  Here, we use it to set the "x" and "n" in the
button contents in Times-Roman.

3) The ButtonData option has a complete cell.  The use of an inline
cell prevents the formatting from being stripped out when pasted in a
text edit cell.

-- 
P.J. Hinton
User Interface Programmer                         paulh at wolfram.com
Wolfram Research, Inc.


  • Prev by Date: Re: A tough Integral
  • Next by Date: Re: A SubListQ function?
  • Previous by thread: Getting stylized text with a palette button
  • Next by thread: Q: How can I force ListPlot to show all data in graphics?