To do this sort of thing properly you need to use a table. I have attached a problem file that does this. The key section is the following:
if ($displayMode eq 'TeX') { $integral = '\[\int_{'.ans_rule(4).'}^{'.ans_rule(4).'}'. ans_rule(35).'\,dx\]'; } else { $integral = $PAR. $BCENTER. BeginTable(). Row(['\(\displaystyle \int\)', ans_rule(4).$BR.$BR.ans_rule(4), ans_rule(35), '\(dx\).'],separation=>2). EndTable(). $ECENTER; }which uses the Union library's table macros to set up an integral with answer rules like you suggest. When hardcopy is requested ('TeX' mode), the layout is done without the table so that it formats a bit better.
Later, when you do the output of the problem, you simply use the variable $integral where you want this integral to appear.
Hope that helps.
Davide