4
$\begingroup$

I am trying to make a new Palette with some buttons on it called, for example, "Arial", "Bookman" etc. plus some other buttons specifying sizes(12,14,..) and some prefered Colors for the fonts. I think this is a faster method than creating new styles and using them. Could you please help me with a simple code to start with?

$\endgroup$
  • 3
    $\begingroup$ Why not using the Writing Assistant palette (available on the Palettes menu)? $\endgroup$ – kglr Nov 12 '14 at 3:26
  • $\begingroup$ @kguler I don't want a big palette with many fonts, sizes, colors! Just a few mouse clicks! As i said, I think this method is more faster and more flexible than a new style or stylesheet.. Thanks for your interest! $\endgroup$ – kornaros Nov 12 '14 at 3:38
  • $\begingroup$ This is essentially the same as your previous question and should probably be asked within that context. @kguler has the right idea, and perhaps if someone can share how to access the underlying code of the writing palette you can get the answer you are looking for. $\endgroup$ – bobthechemist Nov 12 '14 at 3:39
  • $\begingroup$ @bobthechemist I don't know how to simpify the Writting Assistant pallette. Any help extremelly appreciated! $\endgroup$ – kornaros Nov 12 '14 at 3:47
  • $\begingroup$ @kornaros There is supposed to be a menu item Generate Notebook from Palette -- unfortunately it seems broken in v10. This menu item would let you easily look at and modify the code for that palette. $\endgroup$ – Mr.Wizard Jan 14 '15 at 23:43
5
$\begingroup$

Here you go:

button[tok_][par_] := Button[par, FrontEndTokenExecute[tok, par]]

Row /@ {
    button["FontFamily"] /@ {"Arial", "Bookman", "Times"},
    button["FontColor"] /@ {Red, Green, Blue, Brown, Black, White},
    button["FontSize"] /@ Range[10, 20, 2]
  } // Column // CreatePalette

enter image description here

$\endgroup$
  • $\begingroup$ +1 Compact, I like the poor man's operator form of Button. $\endgroup$ – István Zachar Jan 15 '15 at 13:14
2
$\begingroup$

Few modifications of @Mr.Wizard's elegant answer to (1) make it work in Version 9, (2) add additional buttons to invoke font-related dialogs, and (3) eliminate the Save dialog when the palette is closed:

button[tok_][] :=Button["  \[GreaterGreater] ", FrontEndTokenExecute[tok], 
                       Appearance -> "Frameless"]
button[tok_][par_] := Button[par, FrontEndTokenExecute[tok, Setting@par]]


Row /@ {Append[button["FontFamily"] /@ {"Arial", "Bookman", "Times", "Calibri"},
              button["FontPanel"][]], 
    Append[button["FontColor"] /@ ColorSetter /@ {Red, Green, Blue, Brown, Black, White}, 
           button["FontColorDialog"][]], 
    Append[button["FontSize"] /@ Range[10, 40, 4], button["FontSizeDialog"][]]} //
  Column // CreatePalette[#, WindowTitle -> "Fonts...", Saveable -> False] &

enter image description here

$\endgroup$
  • $\begingroup$ +1 for the >> menus. Is Setting the change needed for v9? Also it is IMHO desirable to have the Save dialog as that lets you save the palette for future use; this way you have to run this creation code every time. $\endgroup$ – Mr.Wizard Jan 15 '15 at 12:54
0
$\begingroup$

You can try something like this which will create a floating palette and the buttons will be applied to the entire text cell.

CreatePalette[
  {
   Button["Arial",
    SetOptions[NotebookSelection[InputNotebook[]],
     FontFamily -> "Arial"]
    ],
   Button["Courier",
    SetOptions[NotebookSelection[InputNotebook[]],
     FontFamily -> "Courier New"]
    ],
   Button["Size 12",
    SetOptions[NotebookSelection[InputNotebook[]],
     FontSize -> 12]
    ],
   Button["Size 14",
    SetOptions[NotebookSelection[InputNotebook[]],
     FontSize -> 14]
    ],
   Button["Blue",
    SetOptions[NotebookSelection[InputNotebook[]],
     FontColor -> Blue]
    ],
   Button["Black",
    SetOptions[NotebookSelection[InputNotebook[]],
     FontColor -> Black]
    ]
   },
  WindowTitle -> "Set Style"
  ];
$\endgroup$

Your Answer

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

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