3
$\begingroup$

If I type out, in my notes, a series of transformations, I often like to convert the very last step to a Framed equation:

enter image description here

I'm currently doing this by:

  1. selecting the last expression,
  2. copying it,
  3. pasting it in a new field,
  4. adding Framed[ … ] and evaluating,
  5. copying the result,
  6. pasting it back in the original field.

Is there a hotkey or quick way for me to apply a transformation to a selection, replacing it with the result? (Or something like that.)

Thanks!

$\endgroup$
1
  • $\begingroup$ Ctrl+Shift+Enter is the keyboard shortcut for "evaluate in place", which you press after highlighting an expression; this should ease your task. $\endgroup$ Commented Sep 6, 2017 at 16:13

2 Answers 2

5
$\begingroup$

Ctrl+Shift+Enter is the keyboard shortcut for "evaluate in place", which you press after highlighting an expression; this should ease your task. – J. M.♦ 2 mins ago

enter image description here

Notice I used Defer, it holds its arguments and is stripped when boxes are created. Exactly what we need keep e.g. 1 + 1 in this form.

Related:

How can I change mouse hover behavior for hyperlinks in a notebook?

$\endgroup$
2
  • 1
    $\begingroup$ Didn't have a computer, so thanks for following through! $\endgroup$ Commented Sep 6, 2017 at 16:20
  • $\begingroup$ This is excellent, especially with the .gif! Truly concise, helpful answer. <3 $\endgroup$ Commented Sep 9, 2017 at 18:03
2
$\begingroup$

You could also use InputAliases. For example:

CurrentValue[EvaluationNotebook[], InputAliases] = {
    "fr" -> FrameBox[
        "\[SelectionPlaceholder]",
        BaselinePosition->Baseline,
        Background->LightGray
    ],
    ParentList
};

Here is a short animation using the alias:

enter image description here

Addendum

The nice thing about this approach compared to the accepted answer is that the added frame is transparent to the evaluation process. Here's an animation comparing the two approaches:

enter image description here

Explanation

One further comment. The difference between the two cases is that the evaluate in place approach used Framed, which by default has the option StripOnInput->False. Using:

10 == Framed[Defer[11-1], StripOnInput->True]

would produce a wrapper that is transparent to evaluation

$\endgroup$

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.