Here I define the expression and integrate it term by term using Distribute
. Then I differentiate each term but with a Defer
wrapping it, so the derivatives aren't actually carried out. FInally, I replace the terms that weren't integrated by the original function:
expression = -Sin[t] + g[t]
(* ==> g[t] - Sin[t] *)
integrals = Distribute[Integrate[expression, t]]
(* ==> Cos[t] + \[Integral]g[t] \[DifferentialD]t *)
original =
Map[Defer[D[#, t]] &, integrals] /.
Defer[D[Integrate[f_, __], _]] :> f
$\partial_t \text{Cos}[t] + \text{g}[t]$
The reason I used Defer
is that it allows you to copy the output and evaluate it by pasting it in a new cell. You could alternatively replace Defer
with HoldForm
if you want a more "stable" output. Then you have to explicitly use ReleaseHold
if you want to evaluate the derivatives in the output expression.