I'm writing a tech note in Mathematica, and would like to include some key combination shortcuts. For example, Ctrl+/ for entering fractions. How do I typeset key combinations so that they look like the ones in the Mathematica documentation?
2 Answers
The specific boxes you ask for are:
TemplateBox[{"ctrl", "/"}, "Key1", BaseStyle -> {"ExampleText", FontWeight -> "Plain", FontFamily -> "Source Sans Pro"}]
Unfortunately, it doesn't seem like the style definitions for this template box exists in a normal notebook:
If you evaluate the same code in a documentation notebook it does work:
I might be able to figure out what DisplayFunction
is being used to achieve this typesetting.
Edit
Ah, found it. If you go into a documentation notebook and evaluate:
CurrentValue[InputNotebook[], {StyleDefinitions, "Key1", TemplateBoxOptions}]
you get the display function for the "Key1"
TemplateBox
. You can copy-paste that to a normal notebook and assign it to a variable. You can then use these options in the TemplateBox
expression from earlier:
boxOpts = {BaseStyle -> {}, DefaultBaseStyle -> {},
DisplayFunction -> (FrameBox[
TagBox[GridBox[{{ItemBox[
TemplateBox[{"\[ThickSpace]", #1, "\[ThickSpace]"},
"RowDefault"],
Background -> GrayLevel[0.9333333333333333],
StripOnInput -> False],
ItemBox[TemplateBox[{"\[ThickSpace]", #2, "\[ThickSpace]"},
"RowDefault"], Background -> GrayLevel[1],
StripOnInput -> False]}},
GridBoxAlignment -> {"Columns" -> {{Center}},
"Rows" -> {{Baseline}}}, AutoDelete -> False,
GridBoxDividers -> {"ColumnsIndexed" -> {2 -> GrayLevel[
0.8352941176470589]}, "Rows" -> {{None}}},
GridBoxItemSize -> {"Columns" -> {{All}},
"Rows" -> {{1.45`}}},
GridBoxSpacings -> {"Columns" -> {{0}}},
BaselinePosition -> {{1, 1}, Baseline}], "Grid"],
RoundingRadius -> 4,
Background -> GrayLevel[0.9333333333333333],
FrameMargins -> {{0, 0}, {-1, -1}},
FrameStyle -> {GrayLevel[0.8352941176470589],
AbsoluteThickness[1]}, BaselinePosition -> Baseline,
StripOnInput -> False] &), InterpretationFunction -> Automatic,
CopyFunction -> Automatic, EditingHighlightStyle -> {},
DefaultEditingHighlightStyle -> {},
EditingHighlightArgumentStyle -> {},
DefaultEditingHighlightArgumentStyle -> {},
EditingHighlightBackgroundMargins -> Automatic,
EditingHighlightArgumentBackgroundMargins -> Automatic,
Editable -> Automatic, Selectable -> Automatic,
SyntaxForm -> Automatic, StripWrapperBoxes -> False,
Inactive -> False, InactiveStyle -> "InactiveStyle",
Tooltip -> None, TooltipStyle -> {},
DefaultTooltipStyle -> "TooltipLabel", TooltipDelay -> 0.`};
TemplateBox[{"ctrl", "/"},
"Key1",
BaseStyle -> {"ExampleText", FontWeight -> "Plain",
FontFamily -> "Source Sans Pro"},
boxOpts
] // RawBoxes
You should now be able to put different things in the first argument of the template box to get different shortcuts. You can copy-paste the output to put it where you need it.
You might want to use a button. This you can do as follows: First, you start writing a text within a text cell: "Enter in 2D form using "
Then you make Ctrl+9 which creates an inline mathematics and type:
Button["Ctrl+/",FrontEndExecute[FrontEndToken["Fraction"]]]
Second, you select this command and go to Menu/Evaluation/EvaluateInPlace. Then, you may or may not enter a further text.
This is what you get on the screen:
The fraction template appears upon pressing the button.
Hope it helps. Have fun!
-
$\begingroup$ I'm sorry, but OP isn't asking about this. $\endgroup$– xzczdCommented Jul 5 at 2:10
commands = {{"ctrl", "/"}};
$$ $$TextGrid[commands, Frame -> All, Background -> {{LightGray, White}}]
$$ $$ This doesn't have the beveled edges. I'll update if I can find something better. One thing I noticed that may be helpful though: if you copy the key combination box and paste into a notebook, it pastes as` Key1[ctrl,/]` with red text. If you hover over this it saysThe TemplateBox was unable to use the specified display function, or it was unable to locate the display function possibly because style sheet is missing
$\endgroup$TemplateBox
commands have to look likeTemplateBox[{ctrl, return}, Key1, BaseStyle -> "HowToText" ...]
(if you type this into google minus the ellipses and search verbatim you will see this is how it's written in the documentation). I don't know where thisBaseStyle
comes from and I don't really have any experience with boxes, but maybe someone will see this who can help. $\endgroup$Pane["ctrl",FrameMargins->0]
and similarly for the other key. $\endgroup$Panel
, notPane
... Here's my corrected suggestion:Panel["ctrl", FrameMargins -> 0, BaselinePosition -> Baseline]
. You can copy the output into your text. $\endgroup$