4
$\begingroup$

In order to produce square bracketed matrices I execute the following code at the bottom of my notebook, then copy and paste it into the text cell where I'm composing:

TemplateBox[{
  GridBox[{{"a", "b"}, {"c", "d"}}]}
  , "Identity"
  , DisplayFunction -> 
    (RowBox[{
      StyleBox["[", SpanMaxSize -> \[Infinity]]
      , #1
      , StyleBox["]", SpanMaxSize -> \[Infinity]]
  }] &)] // DisplayForm

I then manipulate the content of the matrix, and the brackets resize as desired. This is fairly cumbersome. Is there a way to accomplish the same thing using keyboard shortcuts?

Mathematica 10.4.0.0 under Windows 10.

$\endgroup$
1

1 Answer 1

4
$\begingroup$

You could use InputAliases (or InputAutoReplacements) to make this easier. For instance:

CurrentValue[EvaluationNotebook[], InputAliases] = DeleteDuplicates @ Append[
    CurrentValue[EvaluationNotebook[], InputAliases],
    "bmat" -> RowBox[{
        StyleBox["[", SpanMaxSize->Infinity],
        GridBox[{{"\[SelectionPlaceholder]","\[Placeholder]"},{"\[Placeholder]","\[Placeholder]"}}],
        StyleBox["]",SpanMaxSize->Infinity]
    }]
];

Here is an animation of the alias in action:

enter image description here

$\endgroup$
1
  • $\begingroup$ I find that when esc-bmat-esc is entered into a text box, Woll's method produces a non-standard font with very thin brackets and dot-centred 0's. Reformatting it as text has no effect. How would one fix that? $\endgroup$
    – Gary
    Sep 14, 2021 at 18:46

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.