V 12.1 on windows.
I am trying to use nice function from a recent post How to directly get the TeXForm of each steps from Rubi?
ps. to run MWE code below, requires Rubi package, which if you do not have it installed, the command to install it is
PacletInstall["https://rulebasedintegration.org/Rubi-4.16.1.0.paclet"]
Now, Here it the function I am trying to use, the same exact code from the above post link written by wuyudi
SetAttributes[IntWithStepsOfTeXForm, {HoldFirst}];
IntWithStepsOfTeXForm[j_] :=
With[{TeX2Str = Convert`TeX`ExpressionToTeX},
Steps[j, RubiPrintInformation -> False] //
Flatten //
Most //
Select[Head@# =!= RubiRule &] //
# /. RubiIntermediateResult[x_] -> x & //
(*ToString@*TeXForm is OK*)
Map["=&" <> (TeX2Str[HoldForm @@ #]) <> "\\\\" &] //
# /. {a___} -> {
"\\begin{aligned}",
TeX2Str@HoldForm@j,
a,
"\\end{aligned}"} & // StringRiffle
]
This is meant to be called as follows, and it works fine this way:
<<Rubi`
<<MaTeX` (*needed just for formating the result*)
(*Not needed to see the problem, just makes it easier to see*)
result = IntWithStepsOfTeXForm[ Int[Log[1 + x], x ] ];
MaTeX[result, Magnification -> 2]
The problem is, I have my integrands in a long list, and my program runs as loop, reading the integrands from the list, so when doing the following, the call no longer works
lst = {{Log[1 + x], x}}; (*very long list of integrands to process*)
result = IntWithStepsOfTeXForm[ Int[ lst[[1,1]], lst[[1,2]] ] ];
MaTeX[result, Magnification -> 2]
Because of the HoldFirst
, the function does not see that lst[[1,1]]=Log[1 + x]
and that lst[[1,2]]=x
.
And I tried numbers of things, but have not found workaround so far. For example, I tried
lst = {{Log[1 + x], x}};
f = lst[[1, 1]];
x = lst[[1, 2]];
result = IntWithStepsOfTeXForm[ Int[ f, x ] ]
Removing the HoldFirst
on the function also did not work, it broke it. Also changing Steps[j, RubiPrintInformation -> False]
to Steps[Evaluate@j, RubiPrintInformation -> False]
broke it as well.
Any suggestion for a work around to allow calling the above function using list as above?
IntWithStepsOfTeXForm[Int[#, x]] & /@ {Sin[x], Cos[x]/x^2, Sin[x]/x^2} // MaTeX
$\endgroup$ – wuyudi May 10 '20 at 4:03lst = {{Log[1 + x], x}}; result = IntWithStepsOfTeXForm[ Int[#1, lst[[1, 2]]]] & /@ {lst[[1, 1]]}
it did not work. Then I triedresult = MapThread[ IntWithStepsOfTeXForm[Int[#1, #2]] & , {lst[[1, 1]], lst[[1, 2]]} ]
and this also did not work. Btw, I will be calling your function on each integral one at a time. Not on the whole list at once as you show. $\endgroup$ – Nasser May 10 '20 at 4:27MapThread
did not work here? Is it possible to make your function where one can call it giving it the integrand expression and also the variable of integrations, as separate parameters? i.e. have your API like this:IntWithSteps[ integrand_, var_]
and then inside your function you can call Rubi any way then. Instead of current APIIntWithSteps[ Int[integrand, var] ]
and having to useHoldFirst
? This might make it easier to use. $\endgroup$ – Nasser May 10 '20 at 4:28