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?
3 Answers
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
-
$\begingroup$ +1 Compact, I like the poor man's operator form of
Button
. $\endgroup$ Jan 15, 2015 at 13:14
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] &
-
$\begingroup$ +1 for the
>>
menus. IsSetting
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$ Jan 15, 2015 at 12:54
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"
];
Writing Assistant
palette (available on thePalettes
menu)? $\endgroup$