# How to get the output of evaluating in place and append the output to the place

I am trying to use MMA for some engineering calculations, and the text cell contains both descriptive text and mathematical formulas. The example is as follows:

the resistor R1 = ρ×L/S = 1.8*10/2


I can select this part "1.8*10/2" and execute the "Evaluate in Place" menu function to obtain the calculation result, output will directly replace the selected content. The result is as follows

the resistor R1 = ρ×L/S = 9


But I want to keep the original calculation formula, append "=" and output behind the the selected content; My ideal result is as follows.

the resistor R1 = ρ×L/S = 1.8*10/2 = 9


How can I make it work? Any response will be appreciated.

PS: I believe the people who use mathcad will be interested in this.

Thanks for the guidance from @Domen and @wioiw, the following code works for appending output of evaluation in place. hope to provide some help to those who are interested.

MenuItem["Evaluate in &Place(Output Append)", KernelExecute[NotebookWrite[InputNotebook[],
StringRiffle @ (Map[StringTrim, #]&) @ (Apply[Identity, #]&) @
RowBox[{
"=",
}]
];],

• I never use Text cells myself. I do everything in code cell. You could try e=HoldForm[1.8*10/2]; Row[{"the resistor R1 = \[Rho]*L/S = ",e," = ", ReleaseHold[e]}] as an example. But actually the way I do all this is generate Latex from Mathematica and compile to PDF. It takes little more work, but it is the best way to do things :) Mathematica should be just for the computation. The presentation and final report should be left to Latex. Do not use Mathematica like it is Microsoft word. Commented May 6 at 4:12
• @Nasser, Thank you for your help and prompt. The system in engineering calculations is very complex, with a variety of formulas and many variables. Every inference and calculation require adding symbols, relationship descriptions, etc. Otherwise, it may be difficult for me to read it myself. So textual descriptions are necessary for me. Commented May 6 at 4:27
• I understand. As far as I know WRI does not have a product like Mathcad where computation and output automatically presented side by side. So you have to do it "manually". May be someone else can suggest something. For me, I just run the notebook each time I change something, and then compile the Latex and look at the PDF. But may be this workflow is not suitable for everyone. Commented May 6 at 4:35
• mathematica.stackexchange.com/questions/16165/… Commented May 6 at 4:46
• How often do you need to do this? Do you have a whole bunch of similar cells that you want to operate on? Or are you getting string input from a file and you want to operate on strings directly? I ask, because it sounds like you are fine using mouse/keyboard/menu commands, and all you'd need to do is make a copy of the desired expression, paste it to where you want it, and do the evaluate in place there. On the other hand, you tried to make a function to do this, which implies that this needs to be done repeatedly and that the input has a consistent format. Commented May 9 at 17:28

Caution: You'd better back up this file, for unexpected syntax error may cause frontend to break down.

Try appending the below code to $InstallationDirectory/FrontEnd/TextResources/$OperatingSystem/KeyEventTranslations.tr.

This code is only applicable to text cells, i.e. cells with style of "Text", "CodeText", etc.

Item[
KeyEvent["x", Modifiers -> {Control, Shift}],
KernelExecute[NotebookWrite[InputNotebook[],
StringRiffle @ (Map[StringTrim, #]&) @ (Apply[Identity, #]&) @
RowBox[{

• Thank you for your help, but I tried to copy your code into the file ~/Mathematica/14.0/SystemFiles/FrontEnd/TextResources/X/KeyEventTranslations.tr, but pressing "Control+Shift+X" and did not result in any response or output Commented May 10 at 10:01
• yeah, my Operating System is Ubuntu 22.04, and KeyEventTranslations.tr is only in the directory ~/Mathematica/14.0/SystemFiles/FrontEnd/TextResources/X/ and cannot be found elsewhere Commented May 10 at 10:18