Here is another version that should typeset and evaluate the way you want. The first step is to use a symbol that supports vertical spanning, and looks like a bar. There are several such symbols, |
, \[VerticalSeparator]
, \[VerticalLine]
, \[VerticalLine]
, \[RightBracketingBar]
and perhaps some others. I think \[VerticalLine]
works best, so I will use that symbol. Next, one needs to restrict the spanning, so that only the selected portion influences the spanning. So, the basic plan is to use the boxes:
RawBoxes @ SubsuperscriptBox[
RowBox[{"\[SelectionPlaceholder]", "\[VerticalLine]"}],
"\[Placeholder]",
"\[Placeholder]"
]

An example:
RawBoxes @ SubsuperscriptBox[
RowBox[{FractionBox[SuperscriptBox["x","2"],"3"],"\[VerticalLine]"}],
"1",
"2"
]

By including the bar inside of a SubsuperscriptBox
, the spanning will only consider whatever is placed inside \[SelectionPlaceholder]
. For example:
RawBoxes @ RowBox[{
FractionBox[SuperscriptBox["x","3"],"4"],
"+",
SubsuperscriptBox[RowBox[{"x","\[VerticalLine]"}],"1","2"]
}]

You will notice that the min size of the bar and the spacing is a bit off, so the following version should look better (I also turned off the SpanSymmetric
option):
CellPrint @ Cell[
BoxData @ SubsuperscriptBox[
RowBox[{
FractionBox[SuperscriptBox["x","2"],"3"],
StyleBox["\[VerticalLine]",
SpanSymmetric->False,
SpanMinSize->1.5
]
}],
RowBox[{"\[MediumSpace]", "1"}],
RowBox[{"\[MediumSpace]", "2"}]
],
"Input"
]

This produces a box structure that should look the way you want. Now, to make it evaluatable, let's define an EvaluatedAt
function:
EvaluatedAt[expr_, Automatic, min_, max_] := EvaluatedAt[
expr,
Replace[Reduce`FreeVariables[expr], {{v_,___}->v, _->None}],
min,
max
]
EvaluatedAt[expr_, x_, min_, max_] := (expr /. x->max) - (expr /. x->min)
A couple examples:
EvaluatedAt[1/x^2, x, 1, 2]
EvaluatedAt[1/x, Automatic, 1, 2]
-3/4
-1/2
In the second example with Automatic
, EvaluatedAt
looks for the first free variable in expr
and then does the desired arithmetic.
Now, we are ready to create an input alias that both typesets as desired, and evaluates as desired:
CurrentValue[EvaluationNotebook[], {InputAliases,"at"}] = TemplateBox[
{"\[SelectionPlaceholder]", "Automatic", "\[Placeholder]", "\[Placeholder]"},
"EvaluatedAt",
DisplayFunction->(
SubsuperscriptBox[
RowBox[{
#1,
StyleBox[
"\[VerticalLine]",
SpanMinSize->1.5,
SpanSymmetric->False
]
}],
RowBox[{"\[MediumSpace]", #3}],
RowBox[{"\[MediumSpace]", #4}]
]&
)
];
And, here's another version where you specify the variable to be replaced:
CurrentValue[EvaluationNotebook[], {InputAliases,"at2"}] = TemplateBox[
{"\[SelectionPlaceholder]", "\[Placeholder]", "\[Placeholder]", "\[Placeholder]"},
"EvaluatedAt",
DisplayFunction->(
SubsuperscriptBox[
RowBox[{
#1,
StyleBox[
"\[VerticalLine]",
SpanMinSize->1.5,
SpanSymmetric->False
]
}],
RowBox[{"\[MediumSpace]", #2, "=", #3}],
RowBox[{"\[MediumSpace]", #4}]
]&
)
];
And here is an animation showing both in action:

Finally, all the necessary code in one code block:
EvaluatedAt[expr_, Automatic, min_, max_] := EvaluatedAt[
expr,
Replace[Reduce`FreeVariables[expr], {{v_,___}->v, _->None}],
min,
max
]
EvaluatedAt[expr_, x_, min_, max_] := (expr /. x->max) - (expr /. x->min)
CurrentValue[EvaluationNotebook[], {InputAliases,"at"}] = TemplateBox[
{"\[SelectionPlaceholder]", "Automatic", "\[Placeholder]", "\[Placeholder]"},
"EvaluatedAt",
DisplayFunction->(
SubsuperscriptBox[
RowBox[{
#1,
StyleBox[
"\[VerticalLine]",
SpanMinSize->1.5,
SpanSymmetric->False
]
}],
RowBox[{"\[MediumSpace]", #3}],
RowBox[{"\[MediumSpace]", #4}]
]&
)
];
CurrentValue[EvaluationNotebook[], {InputAliases,"at2"}] = TemplateBox[
{"\[SelectionPlaceholder]", "\[Placeholder]", "\[Placeholder]", "\[Placeholder]"},
"EvaluatedAt",
DisplayFunction->(
SubsuperscriptBox[
RowBox[{
#1,
StyleBox[
"\[VerticalLine]",
SpanMinSize->1.5,
SpanSymmetric->False
]
}],
RowBox[{"\[MediumSpace]", #2, "=", #3}],
RowBox[{"\[MediumSpace]", #4}]
]&
)
];
r[u_, a_, b_] := u[b] - u[a]
and applying it to replace ruleu[x] /. u[x] -> r[u, a, b]
. It will yield:-u[a] + u[b]
or for different functionu[x] /. u[x] -> r[F, a, b]
it will yield-F[a] + F[b]
$\endgroup$F[x]
, it's just an EXPRESSIONu
. I would want some function likediff[u,{x,a,b}]
more. $\endgroup$First@Differences[expr /. {{x->a}, {x->b}}]
? Or(expr /. x->b) - (expr /. x->a}
? $\endgroup$