Get LaTeX form from step by step solutionIncompatibility of Row and TeXFormoverriding the format of 'copy-as' latex?How can I convert a formatted text cell to latex code?How to convert the following list into a LaTeX table?Parallel and perpendicular symbol from Mathematica to $LaTeX$Compiling Mathematica script in LatexConvert a selection to TeXForm, then copy to clipboardNeed help translating Mathematica code to LaTeXHow to use $LaTeX$ in Mathematica textWhat functions can Mathematica convert from LaTeX?Mathematica to $LaTeX$ in a for loop
In The Incredibles 2, why does Screenslaver's name use a pun on something that doesn't exist in the 1950s pastiche?
If absolute velocity does not exist, how can we say a rocket accelerates in empty space?
Which are the methodologies for interpreting Vedas?
Idiom for 'person who gets violent when drunk"
In Pandemic, why take the extra step of eradicating a disease after you've cured it?
Can an open source licence be revoked if it violates employer's IP?
Can I get a photo of an Ancient Arrow?
Boss making me feel guilty for leaving the company at the end of my internship
Harley Davidson clattering noise from engine, backfire and failure to start
What do you call the action of "describing events as they happen" like sports anchors do?
Is plausible to have subspecies with & without separate sexes?
Undocumented incompatibility between changes and siunitx?
How can powerful telekinesis avoid violating Newton's 3rd Law?
Why would a home insurer offer a discount based on credit score?
Are skill challenges an official option or homebrewed?
What class is best to play when a level behind the rest of the party?
Jam with honey & without pectin has a saucy consistency always
What did the 8086 (and 8088) do upon encountering an illegal instruction?
Which game is this?
Why is the concept of the Null hypothesis associated with the student's t distribution?
Does the UK delegate some immigration control to the Republic of Ireland?
How to represent jealousy in a cute way?
Part of my house is inexplicably gone
What publication claimed that Michael Jackson died in a nuclear holocaust?
Get LaTeX form from step by step solution
Incompatibility of Row and TeXFormoverriding the format of 'copy-as' latex?How can I convert a formatted text cell to latex code?How to convert the following list into a LaTeX table?Parallel and perpendicular symbol from Mathematica to $LaTeX$Compiling Mathematica script in LatexConvert a selection to TeXForm, then copy to clipboardNeed help translating Mathematica code to LaTeXHow to use $LaTeX$ in Mathematica textWhat functions can Mathematica convert from LaTeX?Mathematica to $LaTeX$ in a for loop
$begingroup$
If I want to copy block as latex I do copy as LaTeX. But when I write:
WolframAlpha["integrate (sin(x))^4 dx"]
How can I copy step by step solution as latex?
latex
$endgroup$
add a comment |
$begingroup$
If I want to copy block as latex I do copy as LaTeX. But when I write:
WolframAlpha["integrate (sin(x))^4 dx"]
How can I copy step by step solution as latex?
latex
$endgroup$
add a comment |
$begingroup$
If I want to copy block as latex I do copy as LaTeX. But when I write:
WolframAlpha["integrate (sin(x))^4 dx"]
How can I copy step by step solution as latex?
latex
$endgroup$
If I want to copy block as latex I do copy as LaTeX. But when I write:
WolframAlpha["integrate (sin(x))^4 dx"]
How can I copy step by step solution as latex?
latex
latex
asked May 28 at 11:34
VirtualUserVirtualUser
1545
1545
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
$begingroup$
content = WolframAlpha["integrate (sin(x))^4 dx", "IndefiniteIntegral", 2, "Content",
PodStates -> "IndefiniteIntegral__Step-by-step solution"][[1]];
BoxForm`$UseTemplateSlotSequenceForRow = False;
TeXForm[Column@(MakeExpression[content //. StyleBox[a_, ___] :> a,
StandardForm] /. a_, b_, c___ :> Column[HoldForm[a], HoldForm[b, c]],
r_Row :> HoldForm[r])[[1, All, 1]]]
$smallbeginarrayl
beginarrayl
textTake the integral: \
int sin ^4(x) , dx \
endarray
\
beginarrayl
textUse textthe textreduction textformula, int sin ^m(x) , dx
text= -fraccos (x) sin ^m-1(x)m text+ fracm-1mint sin
^-2+m(x) , dx, textwhere m=4: \
text= -frac14 sin ^3(x) cos (x)+frac34 int sin ^2(x) , dx \
endarray
\
beginarrayl
textWrite sin ^2(x) textas frac12-frac12 cos (2 x): \
text= -frac14 sin ^3(x) cos (x)+frac34 int
left(frac12-frac12 cos (2 x)right) , dx \
endarray
\
beginarrayl
textIntegrate textthe textsum textterm textby textterm textand
textfactor textout textconstants: \
text= -frac14 sin ^3(x) cos (x)-frac38 int cos (2 x) ,
dx+frac3 int 1 , dx8 \
endarray
\
beginarrayl
textFor textthe textintegrand cos (2 x), textsubstitute u=2 x
textand du=2, dx: \
text= -frac14 sin ^3(x) cos (x)-frac316 int cos (u) ,
du+frac3 int 1 , dx8 \
endarray
\
beginarrayl
textThe textintegral textof cos (u) textis sin (u): \
text= -frac116 (3 sin (u))-frac14 sin ^3(x) cos (x)+frac3 int
1 , dx8 \
endarray
\
beginarrayl
textThe textintegral textof 1 textis x: \
text= left(-frac116 (3 sin (u))+frac3 x8-frac14 sin ^3(x)
cos (x)right)+textconstant \
endarray
\
beginarrayl
textSubstitute textback textfor u=2 x: \
text= left(frac3 x8-frac14 sin ^3(x) cos (x)-frac38 sin (x)
cos (x)right)+textconstant \
endarray
\
beginarrayl
textWhich textis textequal textto: \
fbox$left(
beginarraycc
textAnswer: & \
text & text= frac132 (12 x-8 sin (2 x)+sin (4 x))+textconstant \
endarray
right)$ \
endarray
\
endarray$
$endgroup$
5
$begingroup$
nice :) Now I am sure all students will thank you for writing their HW's in Latex much easier than before.
$endgroup$
– Nasser
May 28 at 13:11
$begingroup$
When I copy your input to my notebook I get:Further output of TeXForm::unspt will be suppressed during this calculation.TeXForm::unspt: TeXForm of TemplateSlotSequence[1,] is not supported.and broken output
$endgroup$
– VirtualUser
May 28 at 13:18
$begingroup$
@VirtualUser, I added the line needed for makingTeXFormwork withRow. (see also: Incompatibility of Row and TeXForm
$endgroup$
– kglr
May 28 at 13:30
1
$begingroup$
You have a spurious set of parentheses in the Answer box.
$endgroup$
– Carl Woll
May 28 at 16:44
1
$begingroup$
Your code doesn't work for the input "integrate 1/(1+x^2) dx".
$endgroup$
– Carl Woll
May 28 at 21:23
|
show 2 more comments
$begingroup$
You can just apply TeXForm to the content returned by WolframAlpha, although you will encounter 3 issues:
Some of the StyleBoxes use options that
TeXFormdoesn't recognize. TeXForm will issue messages and ignore them, so you can either useQuietor strip out those options.The
TeXFormproduced has empty lines. This causes problems for the MathJax engine.Some spaces get removed.
So, one could do the following:
content = WolframAlpha[
"integrate (sin(x))^4 dx",
"IndefiniteIntegral",2,"Content",
PodStates->"IndefiniteIntegral__Step-by-step solution"
];
StringReplace[Quiet @ ToString[content, TeXForm], "n" ~~ Whitespace ~~ "n" -> "n"]
which will fix the first 2 issues above. However, it is also possible to fix the internal code. The 3 specific problems with the internal code:
- Some spaces need to have a text wrapper so that they don't disapper.
- The internal code has a bug when Style uses lists of options.
- The internal code tosses in some superfluous carriage returns ("n") that break MathJax.
I will provide code to fix these issues at the bottom of my answer. After running that code, simply using TeXForm produces the desired output:
TeXForm @ WolframAlpha[
"integrate (sin(x))^4 dx",
"IndefiniteIntegral",2,"Content",
PodStates->"IndefiniteIntegral__Step-by-step solution"
]
$beginarrayl
beginarrayl
textTake the integral: \
int sin ^4(x) , dx \
endarray
\
hline
beginarrayl
textUse textthe textreduction textformula, int sin ^m(x) , dxtext text= -fraccos (x) sin ^m-1(x)mtext text+
fracm-1mint sin ^-2+m(x) , dx,text textwhere m=4: \
text text= -frac14 sin ^3(x) cos (x)+frac34int sin ^2(x) , dx \
endarray
\
beginarrayl
textWrite sin ^2(x)text textas frac12-frac12 cos (2 x): \
text text= -frac14 sin ^3(x) cos (x)+frac34int left(frac12-frac12 cos (2 x)right) , dx \
endarray
\
beginarrayl
textIntegrate textthe textsum textterm textby textterm textand textfactor textout textconstants: \
text text= -frac14 sin ^3(x) cos (x)-frac38int cos (2 x) , dx+frac38int 1 , dx \
endarray
\
beginarrayl
textFor textthe textintegrand cos (2 x),text textsubstitute u=2 xtext textand du=2, dx: \
text text= -frac14 sin ^3(x) cos (x)-frac316int cos (u) , du+frac38int 1 , dx \
endarray
\
beginarrayl
textThe textintegral textof cos (u)text textis sin (u): \
text text= -frac3 sin (u)16-frac14 sin ^3(x) cos (x)+frac38int 1 , dx \
endarray
\
beginarrayl
textThe textintegral textof 1text textis x: \
text text= -frac3 sin (u)16+frac3 x8-frac14 sin ^3(x) cos (x)+textconstant \
endarray
\
beginarrayl
textSubstitute textback textfor u=2 x: \
text text= frac3 x8-frac14 sin ^3(x) cos (x)-frac38 sin (x) cos (x)+textconstant \
endarray
\
beginarrayl
textWhich textis textequal textto: \
fbox$beginarrayll
textAnswer: & \
text & text text= frac132 (12 x-8 sin (2 x)+sin (4 x))+textconstant \
endarray
$ \
endarray
\
endarray$
As a comparison with kglr's answer, there is no need to use MakeExpression, no spurious parentheses get introduced (his answer has spurious parentheses in the "Answer" box), the spacing issue gets fixed (note the missing space in the line "the integral of 1is x:"), and the output is correct even when a step-by-step solution has only 1 step.
Now, for the code. Note that the usual caveats apply to the following code, which modifies the internal code used by Mathematica:
(* force autoloading of TeXForm code *)
TeXForm
(* the following modification just flattens out options *)
System`Convert`TeXFormDump`maketex[(StyleBox|Cell)[System`Convert`CommonDump`str_,System`Convert`CommonDump`sty_String:"",System`Convert`CommonDump`opts__?OptionQ]] := Module[
System`Convert`TeXFormDump`fv,System`Convert`TeXFormDump`und,System`Convert`TeXFormDump`fw,System`Convert`TeXFormDump`fs,System`Convert`CommonDump`pre="",System`Convert`CommonDump`post="",System`Convert`TeXFormDump`mid,
System`Convert`TeXFormDump`fv=FontVariations/. Flatten@System`Convert`CommonDump`opts/. FontVariations->;
System`Convert`TeXFormDump`und="Underline"/. System`Convert`TeXFormDump`fv/. "Underline"->False;
System`Convert`TeXFormDump`fw,System`Convert`TeXFormDump`fs=FontWeight,FontSlant/. Flatten@System`Convert`CommonDump`opts/. FontWeight;
System`Convert`TeXFormDump`mid=System`Convert`TeXFormDump`MakeTeX[StyleBox[System`Convert`CommonDump`str,System`Convert`CommonDump`sty]];
If[System`Convert`TeXFormDump`fs==="Italic",System`Convert`TeXFormDump`mid=If[StringMatchQ[System`Convert`TeXFormDump`mid,"\text*"],StringTake[System`Convert`TeXFormDump`mid,7,-2],"$"<>System`Convert`TeXFormDump`mid<>"$"];System`Convert`CommonDump`pre="\text\textit"<>System`Convert`CommonDump`pre;System`Convert`CommonDump`post=System`Convert`CommonDump`post<>"";];
If[System`Convert`TeXFormDump`und,System`Convert`CommonDump`pre="\underline"<>System`Convert`CommonDump`pre;System`Convert`CommonDump`post=System`Convert`CommonDump`post<>"";];
If[System`Convert`TeXFormDump`fw==="Bold",System`Convert`CommonDump`pre="\pmb"<>System`Convert`CommonDump`pre;System`Convert`CommonDump`post=System`Convert`CommonDump`post<>"";];
System`Convert`CommonDump`pre<>System`Convert`TeXFormDump`mid<>System`Convert`CommonDump`post
]
(* the following modification just removes the initial "n" *)
System`Convert`TeXFormDump`maketex[GridBox[System`Convert`TeXFormDump`grid_,System`Convert`CommonDump`opts___?OptionQ]] := Module[
System`Convert`TeXFormDump`colaln,System`Convert`TeXFormDump`rowdivs,System`Convert`TeXFormDump`outstr,System`Convert`TeXFormDump`i,System`Convert`TeXFormDump`cols,System`Convert`TeXFormDump`rows,
System`Convert`CommonDump`DebugPrint["------------------------------------"];
System`Convert`CommonDump`DebugPrint["maketex[GridBox[grid_, opts___?OptionQ]]"];
System`Convert`CommonDump`DebugPrint["grid: ",System`Convert`TeXFormDump`grid];
System`Convert`TeXFormDump`cols=Dimensions[System`Convert`TeXFormDump`grid][[2]];
System`Convert`TeXFormDump`rows=Dimensions[System`Convert`TeXFormDump`grid][[1]];
System`Convert`TeXFormDump`colaln=System`Convert`TeXFormDump`processColumnOptions[System`Convert`CommonDump`opts,System`Convert`TeXFormDump`cols];
System`Convert`TeXFormDump`rowdivs=System`Convert`TeXFormDump`processRowOptions[System`Convert`CommonDump`opts,System`Convert`TeXFormDump`rows];
System`Convert`TeXFormDump`outstr="\beginarray"<>System`Convert`TeXFormDump`colaln<>""<>"n";
For[System`Convert`TeXFormDump`i=1,System`Convert`TeXFormDump`i<=System`Convert`TeXFormDump`rows,System`Convert`TeXFormDump`i++,If[System`Convert`TeXFormDump`rowdivs[[System`Convert`TeXFormDump`i]]==True,System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>"\hline"<>"n"];System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>System`Convert`TeXFormDump`MakeRow[System`Convert`TeXFormDump`grid[[System`Convert`TeXFormDump`i]]];];
If[Last[System`Convert`TeXFormDump`rowdivs]==True,System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>"\hline"<>"n"];
System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>"\endarray"<>"n";
System`Convert`TeXFormDump`outstr
]
(* The following modification prevents some spaces from getting lost *)
System`Convert`TeXFormDump`maketex["" ""] = "\text "
$endgroup$
add a comment |
$begingroup$
I tried to do this before, I could not find an option.
Alternative is to use "Plaintext" option, then copy the plain text to your latex editor and do some (lots) of manually clean up and editing
r = WolframAlpha[
"Integrate[x Sin[x],x,0,Pi]", "Input", 2, "Plaintext",
PodStates -> "Input__Step-by-step solution"]
gives
Compute the definite integral:
integral_0^[Pi] x sin(x) dx
For the integrand x sin(x), integrate by parts, integral f dg = f g - integral g df, where
f = x, dg = sin(x) dx, df = dx, g = -cos(x):
= (-x cos(x)) right bracketing bar _0^[Pi] + integral_0^[Pi] cos(x) dx
Evaluate the antiderivative at the limits and subtract.
(-x cos(x)) right bracketing bar _0^[Pi] = (-[Pi] cos([Pi])) - (-0 cos(0)) = [Pi]:
= [Pi] + integral_0^[Pi] cos(x) dx
Apply the fundamental theorem of calculus.
The antiderivative of cos(x) is sin(x):
= [Pi] + sin(x) right bracketing bar _0^[Pi]
Evaluate the antiderivative at the limits and subtract.
sin(x) right bracketing bar _0^[Pi] = sin([Pi]) - sin(0) = 0:
Answer: |
| = [Pi]
Then clean it to become
documentclassarticle
usepackageamsmath
begin document
Compute the definite integral:
$int_0^pi x sin(x) ,dx$
For the integrand $x sin(x)$, integrate by parts, $int f dg = f g - int g df$, where
$f = x, dg = sin(x) dx, df = dx, g = -cos(x) = (-x cos(x))$
Evaluate the antiderivative at the limits and subtract. etc...
end document
When done cleaning it by hand, compile it

I could not find a "TeXForm" option to Wolfram Alpha output.
$endgroup$
add a comment |
$begingroup$
[See here][1]: not $LaTeX$ but a good start:
WolframAlpha["integrate (sin(x))^4 dx", "PodPlaintext",
PodStates -> "IndefiniteIntegral__Step-by-step solution"]
= 1/32 (12 x - 8 sin(2 x) + sin(4 x)) + constant", "(3 x)/8 + 1/8
sin(x) cos^3(x) - 1/8 sin^3(x) cos(x) - 1/2 sin(x) cos(x) +
constant", "(3 x)/8 - 1/8 i e^(-2 i x) + 1/8 i e^(2 i x) + 1/64 i
e^(-4 i x) - 1/64 i e^(4 i x) + constant", "(3 x)/8 - 1/4 sin(2 x) +
1/32 sin(4 x) + constant", "x^5/5 - (2 x^7)/21 + x^9/45 - (34
x^11)/10395 + O(x^13)
(Taylor series)", "integral_0^π sin^4(x) dx = (3 π)/8
≈1.1781", "integral_0^(2 π) sin^4(x) dx = (3 π)/4
≈2.35619", "integral_0^(2 π) (sin^8(x))/(2 π) dx
= 35/128≈0.273438"```
$endgroup$
$begingroup$
AfterWolframAlpha["integrate (sin(x))^4 dx"]we can just click "show step by step" but I still have doubts how to copy that solution to latex.
$endgroup$
– VirtualUser
May 28 at 11:54
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f199245%2fget-latex-form-from-step-by-step-solution%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
content = WolframAlpha["integrate (sin(x))^4 dx", "IndefiniteIntegral", 2, "Content",
PodStates -> "IndefiniteIntegral__Step-by-step solution"][[1]];
BoxForm`$UseTemplateSlotSequenceForRow = False;
TeXForm[Column@(MakeExpression[content //. StyleBox[a_, ___] :> a,
StandardForm] /. a_, b_, c___ :> Column[HoldForm[a], HoldForm[b, c]],
r_Row :> HoldForm[r])[[1, All, 1]]]
$smallbeginarrayl
beginarrayl
textTake the integral: \
int sin ^4(x) , dx \
endarray
\
beginarrayl
textUse textthe textreduction textformula, int sin ^m(x) , dx
text= -fraccos (x) sin ^m-1(x)m text+ fracm-1mint sin
^-2+m(x) , dx, textwhere m=4: \
text= -frac14 sin ^3(x) cos (x)+frac34 int sin ^2(x) , dx \
endarray
\
beginarrayl
textWrite sin ^2(x) textas frac12-frac12 cos (2 x): \
text= -frac14 sin ^3(x) cos (x)+frac34 int
left(frac12-frac12 cos (2 x)right) , dx \
endarray
\
beginarrayl
textIntegrate textthe textsum textterm textby textterm textand
textfactor textout textconstants: \
text= -frac14 sin ^3(x) cos (x)-frac38 int cos (2 x) ,
dx+frac3 int 1 , dx8 \
endarray
\
beginarrayl
textFor textthe textintegrand cos (2 x), textsubstitute u=2 x
textand du=2, dx: \
text= -frac14 sin ^3(x) cos (x)-frac316 int cos (u) ,
du+frac3 int 1 , dx8 \
endarray
\
beginarrayl
textThe textintegral textof cos (u) textis sin (u): \
text= -frac116 (3 sin (u))-frac14 sin ^3(x) cos (x)+frac3 int
1 , dx8 \
endarray
\
beginarrayl
textThe textintegral textof 1 textis x: \
text= left(-frac116 (3 sin (u))+frac3 x8-frac14 sin ^3(x)
cos (x)right)+textconstant \
endarray
\
beginarrayl
textSubstitute textback textfor u=2 x: \
text= left(frac3 x8-frac14 sin ^3(x) cos (x)-frac38 sin (x)
cos (x)right)+textconstant \
endarray
\
beginarrayl
textWhich textis textequal textto: \
fbox$left(
beginarraycc
textAnswer: & \
text & text= frac132 (12 x-8 sin (2 x)+sin (4 x))+textconstant \
endarray
right)$ \
endarray
\
endarray$
$endgroup$
5
$begingroup$
nice :) Now I am sure all students will thank you for writing their HW's in Latex much easier than before.
$endgroup$
– Nasser
May 28 at 13:11
$begingroup$
When I copy your input to my notebook I get:Further output of TeXForm::unspt will be suppressed during this calculation.TeXForm::unspt: TeXForm of TemplateSlotSequence[1,] is not supported.and broken output
$endgroup$
– VirtualUser
May 28 at 13:18
$begingroup$
@VirtualUser, I added the line needed for makingTeXFormwork withRow. (see also: Incompatibility of Row and TeXForm
$endgroup$
– kglr
May 28 at 13:30
1
$begingroup$
You have a spurious set of parentheses in the Answer box.
$endgroup$
– Carl Woll
May 28 at 16:44
1
$begingroup$
Your code doesn't work for the input "integrate 1/(1+x^2) dx".
$endgroup$
– Carl Woll
May 28 at 21:23
|
show 2 more comments
$begingroup$
content = WolframAlpha["integrate (sin(x))^4 dx", "IndefiniteIntegral", 2, "Content",
PodStates -> "IndefiniteIntegral__Step-by-step solution"][[1]];
BoxForm`$UseTemplateSlotSequenceForRow = False;
TeXForm[Column@(MakeExpression[content //. StyleBox[a_, ___] :> a,
StandardForm] /. a_, b_, c___ :> Column[HoldForm[a], HoldForm[b, c]],
r_Row :> HoldForm[r])[[1, All, 1]]]
$smallbeginarrayl
beginarrayl
textTake the integral: \
int sin ^4(x) , dx \
endarray
\
beginarrayl
textUse textthe textreduction textformula, int sin ^m(x) , dx
text= -fraccos (x) sin ^m-1(x)m text+ fracm-1mint sin
^-2+m(x) , dx, textwhere m=4: \
text= -frac14 sin ^3(x) cos (x)+frac34 int sin ^2(x) , dx \
endarray
\
beginarrayl
textWrite sin ^2(x) textas frac12-frac12 cos (2 x): \
text= -frac14 sin ^3(x) cos (x)+frac34 int
left(frac12-frac12 cos (2 x)right) , dx \
endarray
\
beginarrayl
textIntegrate textthe textsum textterm textby textterm textand
textfactor textout textconstants: \
text= -frac14 sin ^3(x) cos (x)-frac38 int cos (2 x) ,
dx+frac3 int 1 , dx8 \
endarray
\
beginarrayl
textFor textthe textintegrand cos (2 x), textsubstitute u=2 x
textand du=2, dx: \
text= -frac14 sin ^3(x) cos (x)-frac316 int cos (u) ,
du+frac3 int 1 , dx8 \
endarray
\
beginarrayl
textThe textintegral textof cos (u) textis sin (u): \
text= -frac116 (3 sin (u))-frac14 sin ^3(x) cos (x)+frac3 int
1 , dx8 \
endarray
\
beginarrayl
textThe textintegral textof 1 textis x: \
text= left(-frac116 (3 sin (u))+frac3 x8-frac14 sin ^3(x)
cos (x)right)+textconstant \
endarray
\
beginarrayl
textSubstitute textback textfor u=2 x: \
text= left(frac3 x8-frac14 sin ^3(x) cos (x)-frac38 sin (x)
cos (x)right)+textconstant \
endarray
\
beginarrayl
textWhich textis textequal textto: \
fbox$left(
beginarraycc
textAnswer: & \
text & text= frac132 (12 x-8 sin (2 x)+sin (4 x))+textconstant \
endarray
right)$ \
endarray
\
endarray$
$endgroup$
5
$begingroup$
nice :) Now I am sure all students will thank you for writing their HW's in Latex much easier than before.
$endgroup$
– Nasser
May 28 at 13:11
$begingroup$
When I copy your input to my notebook I get:Further output of TeXForm::unspt will be suppressed during this calculation.TeXForm::unspt: TeXForm of TemplateSlotSequence[1,] is not supported.and broken output
$endgroup$
– VirtualUser
May 28 at 13:18
$begingroup$
@VirtualUser, I added the line needed for makingTeXFormwork withRow. (see also: Incompatibility of Row and TeXForm
$endgroup$
– kglr
May 28 at 13:30
1
$begingroup$
You have a spurious set of parentheses in the Answer box.
$endgroup$
– Carl Woll
May 28 at 16:44
1
$begingroup$
Your code doesn't work for the input "integrate 1/(1+x^2) dx".
$endgroup$
– Carl Woll
May 28 at 21:23
|
show 2 more comments
$begingroup$
content = WolframAlpha["integrate (sin(x))^4 dx", "IndefiniteIntegral", 2, "Content",
PodStates -> "IndefiniteIntegral__Step-by-step solution"][[1]];
BoxForm`$UseTemplateSlotSequenceForRow = False;
TeXForm[Column@(MakeExpression[content //. StyleBox[a_, ___] :> a,
StandardForm] /. a_, b_, c___ :> Column[HoldForm[a], HoldForm[b, c]],
r_Row :> HoldForm[r])[[1, All, 1]]]
$smallbeginarrayl
beginarrayl
textTake the integral: \
int sin ^4(x) , dx \
endarray
\
beginarrayl
textUse textthe textreduction textformula, int sin ^m(x) , dx
text= -fraccos (x) sin ^m-1(x)m text+ fracm-1mint sin
^-2+m(x) , dx, textwhere m=4: \
text= -frac14 sin ^3(x) cos (x)+frac34 int sin ^2(x) , dx \
endarray
\
beginarrayl
textWrite sin ^2(x) textas frac12-frac12 cos (2 x): \
text= -frac14 sin ^3(x) cos (x)+frac34 int
left(frac12-frac12 cos (2 x)right) , dx \
endarray
\
beginarrayl
textIntegrate textthe textsum textterm textby textterm textand
textfactor textout textconstants: \
text= -frac14 sin ^3(x) cos (x)-frac38 int cos (2 x) ,
dx+frac3 int 1 , dx8 \
endarray
\
beginarrayl
textFor textthe textintegrand cos (2 x), textsubstitute u=2 x
textand du=2, dx: \
text= -frac14 sin ^3(x) cos (x)-frac316 int cos (u) ,
du+frac3 int 1 , dx8 \
endarray
\
beginarrayl
textThe textintegral textof cos (u) textis sin (u): \
text= -frac116 (3 sin (u))-frac14 sin ^3(x) cos (x)+frac3 int
1 , dx8 \
endarray
\
beginarrayl
textThe textintegral textof 1 textis x: \
text= left(-frac116 (3 sin (u))+frac3 x8-frac14 sin ^3(x)
cos (x)right)+textconstant \
endarray
\
beginarrayl
textSubstitute textback textfor u=2 x: \
text= left(frac3 x8-frac14 sin ^3(x) cos (x)-frac38 sin (x)
cos (x)right)+textconstant \
endarray
\
beginarrayl
textWhich textis textequal textto: \
fbox$left(
beginarraycc
textAnswer: & \
text & text= frac132 (12 x-8 sin (2 x)+sin (4 x))+textconstant \
endarray
right)$ \
endarray
\
endarray$
$endgroup$
content = WolframAlpha["integrate (sin(x))^4 dx", "IndefiniteIntegral", 2, "Content",
PodStates -> "IndefiniteIntegral__Step-by-step solution"][[1]];
BoxForm`$UseTemplateSlotSequenceForRow = False;
TeXForm[Column@(MakeExpression[content //. StyleBox[a_, ___] :> a,
StandardForm] /. a_, b_, c___ :> Column[HoldForm[a], HoldForm[b, c]],
r_Row :> HoldForm[r])[[1, All, 1]]]
$smallbeginarrayl
beginarrayl
textTake the integral: \
int sin ^4(x) , dx \
endarray
\
beginarrayl
textUse textthe textreduction textformula, int sin ^m(x) , dx
text= -fraccos (x) sin ^m-1(x)m text+ fracm-1mint sin
^-2+m(x) , dx, textwhere m=4: \
text= -frac14 sin ^3(x) cos (x)+frac34 int sin ^2(x) , dx \
endarray
\
beginarrayl
textWrite sin ^2(x) textas frac12-frac12 cos (2 x): \
text= -frac14 sin ^3(x) cos (x)+frac34 int
left(frac12-frac12 cos (2 x)right) , dx \
endarray
\
beginarrayl
textIntegrate textthe textsum textterm textby textterm textand
textfactor textout textconstants: \
text= -frac14 sin ^3(x) cos (x)-frac38 int cos (2 x) ,
dx+frac3 int 1 , dx8 \
endarray
\
beginarrayl
textFor textthe textintegrand cos (2 x), textsubstitute u=2 x
textand du=2, dx: \
text= -frac14 sin ^3(x) cos (x)-frac316 int cos (u) ,
du+frac3 int 1 , dx8 \
endarray
\
beginarrayl
textThe textintegral textof cos (u) textis sin (u): \
text= -frac116 (3 sin (u))-frac14 sin ^3(x) cos (x)+frac3 int
1 , dx8 \
endarray
\
beginarrayl
textThe textintegral textof 1 textis x: \
text= left(-frac116 (3 sin (u))+frac3 x8-frac14 sin ^3(x)
cos (x)right)+textconstant \
endarray
\
beginarrayl
textSubstitute textback textfor u=2 x: \
text= left(frac3 x8-frac14 sin ^3(x) cos (x)-frac38 sin (x)
cos (x)right)+textconstant \
endarray
\
beginarrayl
textWhich textis textequal textto: \
fbox$left(
beginarraycc
textAnswer: & \
text & text= frac132 (12 x-8 sin (2 x)+sin (4 x))+textconstant \
endarray
right)$ \
endarray
\
endarray$
edited May 28 at 16:37
answered May 28 at 13:09
kglrkglr
197k10222445
197k10222445
5
$begingroup$
nice :) Now I am sure all students will thank you for writing their HW's in Latex much easier than before.
$endgroup$
– Nasser
May 28 at 13:11
$begingroup$
When I copy your input to my notebook I get:Further output of TeXForm::unspt will be suppressed during this calculation.TeXForm::unspt: TeXForm of TemplateSlotSequence[1,] is not supported.and broken output
$endgroup$
– VirtualUser
May 28 at 13:18
$begingroup$
@VirtualUser, I added the line needed for makingTeXFormwork withRow. (see also: Incompatibility of Row and TeXForm
$endgroup$
– kglr
May 28 at 13:30
1
$begingroup$
You have a spurious set of parentheses in the Answer box.
$endgroup$
– Carl Woll
May 28 at 16:44
1
$begingroup$
Your code doesn't work for the input "integrate 1/(1+x^2) dx".
$endgroup$
– Carl Woll
May 28 at 21:23
|
show 2 more comments
5
$begingroup$
nice :) Now I am sure all students will thank you for writing their HW's in Latex much easier than before.
$endgroup$
– Nasser
May 28 at 13:11
$begingroup$
When I copy your input to my notebook I get:Further output of TeXForm::unspt will be suppressed during this calculation.TeXForm::unspt: TeXForm of TemplateSlotSequence[1,] is not supported.and broken output
$endgroup$
– VirtualUser
May 28 at 13:18
$begingroup$
@VirtualUser, I added the line needed for makingTeXFormwork withRow. (see also: Incompatibility of Row and TeXForm
$endgroup$
– kglr
May 28 at 13:30
1
$begingroup$
You have a spurious set of parentheses in the Answer box.
$endgroup$
– Carl Woll
May 28 at 16:44
1
$begingroup$
Your code doesn't work for the input "integrate 1/(1+x^2) dx".
$endgroup$
– Carl Woll
May 28 at 21:23
5
5
$begingroup$
nice :) Now I am sure all students will thank you for writing their HW's in Latex much easier than before.
$endgroup$
– Nasser
May 28 at 13:11
$begingroup$
nice :) Now I am sure all students will thank you for writing their HW's in Latex much easier than before.
$endgroup$
– Nasser
May 28 at 13:11
$begingroup$
When I copy your input to my notebook I get:
Further output of TeXForm::unspt will be suppressed during this calculation. TeXForm::unspt: TeXForm of TemplateSlotSequence[1,] is not supported. and broken output$endgroup$
– VirtualUser
May 28 at 13:18
$begingroup$
When I copy your input to my notebook I get:
Further output of TeXForm::unspt will be suppressed during this calculation. TeXForm::unspt: TeXForm of TemplateSlotSequence[1,] is not supported. and broken output$endgroup$
– VirtualUser
May 28 at 13:18
$begingroup$
@VirtualUser, I added the line needed for making
TeXForm work with Row. (see also: Incompatibility of Row and TeXForm$endgroup$
– kglr
May 28 at 13:30
$begingroup$
@VirtualUser, I added the line needed for making
TeXForm work with Row. (see also: Incompatibility of Row and TeXForm$endgroup$
– kglr
May 28 at 13:30
1
1
$begingroup$
You have a spurious set of parentheses in the Answer box.
$endgroup$
– Carl Woll
May 28 at 16:44
$begingroup$
You have a spurious set of parentheses in the Answer box.
$endgroup$
– Carl Woll
May 28 at 16:44
1
1
$begingroup$
Your code doesn't work for the input "integrate 1/(1+x^2) dx".
$endgroup$
– Carl Woll
May 28 at 21:23
$begingroup$
Your code doesn't work for the input "integrate 1/(1+x^2) dx".
$endgroup$
– Carl Woll
May 28 at 21:23
|
show 2 more comments
$begingroup$
You can just apply TeXForm to the content returned by WolframAlpha, although you will encounter 3 issues:
Some of the StyleBoxes use options that
TeXFormdoesn't recognize. TeXForm will issue messages and ignore them, so you can either useQuietor strip out those options.The
TeXFormproduced has empty lines. This causes problems for the MathJax engine.Some spaces get removed.
So, one could do the following:
content = WolframAlpha[
"integrate (sin(x))^4 dx",
"IndefiniteIntegral",2,"Content",
PodStates->"IndefiniteIntegral__Step-by-step solution"
];
StringReplace[Quiet @ ToString[content, TeXForm], "n" ~~ Whitespace ~~ "n" -> "n"]
which will fix the first 2 issues above. However, it is also possible to fix the internal code. The 3 specific problems with the internal code:
- Some spaces need to have a text wrapper so that they don't disapper.
- The internal code has a bug when Style uses lists of options.
- The internal code tosses in some superfluous carriage returns ("n") that break MathJax.
I will provide code to fix these issues at the bottom of my answer. After running that code, simply using TeXForm produces the desired output:
TeXForm @ WolframAlpha[
"integrate (sin(x))^4 dx",
"IndefiniteIntegral",2,"Content",
PodStates->"IndefiniteIntegral__Step-by-step solution"
]
$beginarrayl
beginarrayl
textTake the integral: \
int sin ^4(x) , dx \
endarray
\
hline
beginarrayl
textUse textthe textreduction textformula, int sin ^m(x) , dxtext text= -fraccos (x) sin ^m-1(x)mtext text+
fracm-1mint sin ^-2+m(x) , dx,text textwhere m=4: \
text text= -frac14 sin ^3(x) cos (x)+frac34int sin ^2(x) , dx \
endarray
\
beginarrayl
textWrite sin ^2(x)text textas frac12-frac12 cos (2 x): \
text text= -frac14 sin ^3(x) cos (x)+frac34int left(frac12-frac12 cos (2 x)right) , dx \
endarray
\
beginarrayl
textIntegrate textthe textsum textterm textby textterm textand textfactor textout textconstants: \
text text= -frac14 sin ^3(x) cos (x)-frac38int cos (2 x) , dx+frac38int 1 , dx \
endarray
\
beginarrayl
textFor textthe textintegrand cos (2 x),text textsubstitute u=2 xtext textand du=2, dx: \
text text= -frac14 sin ^3(x) cos (x)-frac316int cos (u) , du+frac38int 1 , dx \
endarray
\
beginarrayl
textThe textintegral textof cos (u)text textis sin (u): \
text text= -frac3 sin (u)16-frac14 sin ^3(x) cos (x)+frac38int 1 , dx \
endarray
\
beginarrayl
textThe textintegral textof 1text textis x: \
text text= -frac3 sin (u)16+frac3 x8-frac14 sin ^3(x) cos (x)+textconstant \
endarray
\
beginarrayl
textSubstitute textback textfor u=2 x: \
text text= frac3 x8-frac14 sin ^3(x) cos (x)-frac38 sin (x) cos (x)+textconstant \
endarray
\
beginarrayl
textWhich textis textequal textto: \
fbox$beginarrayll
textAnswer: & \
text & text text= frac132 (12 x-8 sin (2 x)+sin (4 x))+textconstant \
endarray
$ \
endarray
\
endarray$
As a comparison with kglr's answer, there is no need to use MakeExpression, no spurious parentheses get introduced (his answer has spurious parentheses in the "Answer" box), the spacing issue gets fixed (note the missing space in the line "the integral of 1is x:"), and the output is correct even when a step-by-step solution has only 1 step.
Now, for the code. Note that the usual caveats apply to the following code, which modifies the internal code used by Mathematica:
(* force autoloading of TeXForm code *)
TeXForm
(* the following modification just flattens out options *)
System`Convert`TeXFormDump`maketex[(StyleBox|Cell)[System`Convert`CommonDump`str_,System`Convert`CommonDump`sty_String:"",System`Convert`CommonDump`opts__?OptionQ]] := Module[
System`Convert`TeXFormDump`fv,System`Convert`TeXFormDump`und,System`Convert`TeXFormDump`fw,System`Convert`TeXFormDump`fs,System`Convert`CommonDump`pre="",System`Convert`CommonDump`post="",System`Convert`TeXFormDump`mid,
System`Convert`TeXFormDump`fv=FontVariations/. Flatten@System`Convert`CommonDump`opts/. FontVariations->;
System`Convert`TeXFormDump`und="Underline"/. System`Convert`TeXFormDump`fv/. "Underline"->False;
System`Convert`TeXFormDump`fw,System`Convert`TeXFormDump`fs=FontWeight,FontSlant/. Flatten@System`Convert`CommonDump`opts/. FontWeight;
System`Convert`TeXFormDump`mid=System`Convert`TeXFormDump`MakeTeX[StyleBox[System`Convert`CommonDump`str,System`Convert`CommonDump`sty]];
If[System`Convert`TeXFormDump`fs==="Italic",System`Convert`TeXFormDump`mid=If[StringMatchQ[System`Convert`TeXFormDump`mid,"\text*"],StringTake[System`Convert`TeXFormDump`mid,7,-2],"$"<>System`Convert`TeXFormDump`mid<>"$"];System`Convert`CommonDump`pre="\text\textit"<>System`Convert`CommonDump`pre;System`Convert`CommonDump`post=System`Convert`CommonDump`post<>"";];
If[System`Convert`TeXFormDump`und,System`Convert`CommonDump`pre="\underline"<>System`Convert`CommonDump`pre;System`Convert`CommonDump`post=System`Convert`CommonDump`post<>"";];
If[System`Convert`TeXFormDump`fw==="Bold",System`Convert`CommonDump`pre="\pmb"<>System`Convert`CommonDump`pre;System`Convert`CommonDump`post=System`Convert`CommonDump`post<>"";];
System`Convert`CommonDump`pre<>System`Convert`TeXFormDump`mid<>System`Convert`CommonDump`post
]
(* the following modification just removes the initial "n" *)
System`Convert`TeXFormDump`maketex[GridBox[System`Convert`TeXFormDump`grid_,System`Convert`CommonDump`opts___?OptionQ]] := Module[
System`Convert`TeXFormDump`colaln,System`Convert`TeXFormDump`rowdivs,System`Convert`TeXFormDump`outstr,System`Convert`TeXFormDump`i,System`Convert`TeXFormDump`cols,System`Convert`TeXFormDump`rows,
System`Convert`CommonDump`DebugPrint["------------------------------------"];
System`Convert`CommonDump`DebugPrint["maketex[GridBox[grid_, opts___?OptionQ]]"];
System`Convert`CommonDump`DebugPrint["grid: ",System`Convert`TeXFormDump`grid];
System`Convert`TeXFormDump`cols=Dimensions[System`Convert`TeXFormDump`grid][[2]];
System`Convert`TeXFormDump`rows=Dimensions[System`Convert`TeXFormDump`grid][[1]];
System`Convert`TeXFormDump`colaln=System`Convert`TeXFormDump`processColumnOptions[System`Convert`CommonDump`opts,System`Convert`TeXFormDump`cols];
System`Convert`TeXFormDump`rowdivs=System`Convert`TeXFormDump`processRowOptions[System`Convert`CommonDump`opts,System`Convert`TeXFormDump`rows];
System`Convert`TeXFormDump`outstr="\beginarray"<>System`Convert`TeXFormDump`colaln<>""<>"n";
For[System`Convert`TeXFormDump`i=1,System`Convert`TeXFormDump`i<=System`Convert`TeXFormDump`rows,System`Convert`TeXFormDump`i++,If[System`Convert`TeXFormDump`rowdivs[[System`Convert`TeXFormDump`i]]==True,System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>"\hline"<>"n"];System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>System`Convert`TeXFormDump`MakeRow[System`Convert`TeXFormDump`grid[[System`Convert`TeXFormDump`i]]];];
If[Last[System`Convert`TeXFormDump`rowdivs]==True,System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>"\hline"<>"n"];
System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>"\endarray"<>"n";
System`Convert`TeXFormDump`outstr
]
(* The following modification prevents some spaces from getting lost *)
System`Convert`TeXFormDump`maketex["" ""] = "\text "
$endgroup$
add a comment |
$begingroup$
You can just apply TeXForm to the content returned by WolframAlpha, although you will encounter 3 issues:
Some of the StyleBoxes use options that
TeXFormdoesn't recognize. TeXForm will issue messages and ignore them, so you can either useQuietor strip out those options.The
TeXFormproduced has empty lines. This causes problems for the MathJax engine.Some spaces get removed.
So, one could do the following:
content = WolframAlpha[
"integrate (sin(x))^4 dx",
"IndefiniteIntegral",2,"Content",
PodStates->"IndefiniteIntegral__Step-by-step solution"
];
StringReplace[Quiet @ ToString[content, TeXForm], "n" ~~ Whitespace ~~ "n" -> "n"]
which will fix the first 2 issues above. However, it is also possible to fix the internal code. The 3 specific problems with the internal code:
- Some spaces need to have a text wrapper so that they don't disapper.
- The internal code has a bug when Style uses lists of options.
- The internal code tosses in some superfluous carriage returns ("n") that break MathJax.
I will provide code to fix these issues at the bottom of my answer. After running that code, simply using TeXForm produces the desired output:
TeXForm @ WolframAlpha[
"integrate (sin(x))^4 dx",
"IndefiniteIntegral",2,"Content",
PodStates->"IndefiniteIntegral__Step-by-step solution"
]
$beginarrayl
beginarrayl
textTake the integral: \
int sin ^4(x) , dx \
endarray
\
hline
beginarrayl
textUse textthe textreduction textformula, int sin ^m(x) , dxtext text= -fraccos (x) sin ^m-1(x)mtext text+
fracm-1mint sin ^-2+m(x) , dx,text textwhere m=4: \
text text= -frac14 sin ^3(x) cos (x)+frac34int sin ^2(x) , dx \
endarray
\
beginarrayl
textWrite sin ^2(x)text textas frac12-frac12 cos (2 x): \
text text= -frac14 sin ^3(x) cos (x)+frac34int left(frac12-frac12 cos (2 x)right) , dx \
endarray
\
beginarrayl
textIntegrate textthe textsum textterm textby textterm textand textfactor textout textconstants: \
text text= -frac14 sin ^3(x) cos (x)-frac38int cos (2 x) , dx+frac38int 1 , dx \
endarray
\
beginarrayl
textFor textthe textintegrand cos (2 x),text textsubstitute u=2 xtext textand du=2, dx: \
text text= -frac14 sin ^3(x) cos (x)-frac316int cos (u) , du+frac38int 1 , dx \
endarray
\
beginarrayl
textThe textintegral textof cos (u)text textis sin (u): \
text text= -frac3 sin (u)16-frac14 sin ^3(x) cos (x)+frac38int 1 , dx \
endarray
\
beginarrayl
textThe textintegral textof 1text textis x: \
text text= -frac3 sin (u)16+frac3 x8-frac14 sin ^3(x) cos (x)+textconstant \
endarray
\
beginarrayl
textSubstitute textback textfor u=2 x: \
text text= frac3 x8-frac14 sin ^3(x) cos (x)-frac38 sin (x) cos (x)+textconstant \
endarray
\
beginarrayl
textWhich textis textequal textto: \
fbox$beginarrayll
textAnswer: & \
text & text text= frac132 (12 x-8 sin (2 x)+sin (4 x))+textconstant \
endarray
$ \
endarray
\
endarray$
As a comparison with kglr's answer, there is no need to use MakeExpression, no spurious parentheses get introduced (his answer has spurious parentheses in the "Answer" box), the spacing issue gets fixed (note the missing space in the line "the integral of 1is x:"), and the output is correct even when a step-by-step solution has only 1 step.
Now, for the code. Note that the usual caveats apply to the following code, which modifies the internal code used by Mathematica:
(* force autoloading of TeXForm code *)
TeXForm
(* the following modification just flattens out options *)
System`Convert`TeXFormDump`maketex[(StyleBox|Cell)[System`Convert`CommonDump`str_,System`Convert`CommonDump`sty_String:"",System`Convert`CommonDump`opts__?OptionQ]] := Module[
System`Convert`TeXFormDump`fv,System`Convert`TeXFormDump`und,System`Convert`TeXFormDump`fw,System`Convert`TeXFormDump`fs,System`Convert`CommonDump`pre="",System`Convert`CommonDump`post="",System`Convert`TeXFormDump`mid,
System`Convert`TeXFormDump`fv=FontVariations/. Flatten@System`Convert`CommonDump`opts/. FontVariations->;
System`Convert`TeXFormDump`und="Underline"/. System`Convert`TeXFormDump`fv/. "Underline"->False;
System`Convert`TeXFormDump`fw,System`Convert`TeXFormDump`fs=FontWeight,FontSlant/. Flatten@System`Convert`CommonDump`opts/. FontWeight;
System`Convert`TeXFormDump`mid=System`Convert`TeXFormDump`MakeTeX[StyleBox[System`Convert`CommonDump`str,System`Convert`CommonDump`sty]];
If[System`Convert`TeXFormDump`fs==="Italic",System`Convert`TeXFormDump`mid=If[StringMatchQ[System`Convert`TeXFormDump`mid,"\text*"],StringTake[System`Convert`TeXFormDump`mid,7,-2],"$"<>System`Convert`TeXFormDump`mid<>"$"];System`Convert`CommonDump`pre="\text\textit"<>System`Convert`CommonDump`pre;System`Convert`CommonDump`post=System`Convert`CommonDump`post<>"";];
If[System`Convert`TeXFormDump`und,System`Convert`CommonDump`pre="\underline"<>System`Convert`CommonDump`pre;System`Convert`CommonDump`post=System`Convert`CommonDump`post<>"";];
If[System`Convert`TeXFormDump`fw==="Bold",System`Convert`CommonDump`pre="\pmb"<>System`Convert`CommonDump`pre;System`Convert`CommonDump`post=System`Convert`CommonDump`post<>"";];
System`Convert`CommonDump`pre<>System`Convert`TeXFormDump`mid<>System`Convert`CommonDump`post
]
(* the following modification just removes the initial "n" *)
System`Convert`TeXFormDump`maketex[GridBox[System`Convert`TeXFormDump`grid_,System`Convert`CommonDump`opts___?OptionQ]] := Module[
System`Convert`TeXFormDump`colaln,System`Convert`TeXFormDump`rowdivs,System`Convert`TeXFormDump`outstr,System`Convert`TeXFormDump`i,System`Convert`TeXFormDump`cols,System`Convert`TeXFormDump`rows,
System`Convert`CommonDump`DebugPrint["------------------------------------"];
System`Convert`CommonDump`DebugPrint["maketex[GridBox[grid_, opts___?OptionQ]]"];
System`Convert`CommonDump`DebugPrint["grid: ",System`Convert`TeXFormDump`grid];
System`Convert`TeXFormDump`cols=Dimensions[System`Convert`TeXFormDump`grid][[2]];
System`Convert`TeXFormDump`rows=Dimensions[System`Convert`TeXFormDump`grid][[1]];
System`Convert`TeXFormDump`colaln=System`Convert`TeXFormDump`processColumnOptions[System`Convert`CommonDump`opts,System`Convert`TeXFormDump`cols];
System`Convert`TeXFormDump`rowdivs=System`Convert`TeXFormDump`processRowOptions[System`Convert`CommonDump`opts,System`Convert`TeXFormDump`rows];
System`Convert`TeXFormDump`outstr="\beginarray"<>System`Convert`TeXFormDump`colaln<>""<>"n";
For[System`Convert`TeXFormDump`i=1,System`Convert`TeXFormDump`i<=System`Convert`TeXFormDump`rows,System`Convert`TeXFormDump`i++,If[System`Convert`TeXFormDump`rowdivs[[System`Convert`TeXFormDump`i]]==True,System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>"\hline"<>"n"];System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>System`Convert`TeXFormDump`MakeRow[System`Convert`TeXFormDump`grid[[System`Convert`TeXFormDump`i]]];];
If[Last[System`Convert`TeXFormDump`rowdivs]==True,System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>"\hline"<>"n"];
System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>"\endarray"<>"n";
System`Convert`TeXFormDump`outstr
]
(* The following modification prevents some spaces from getting lost *)
System`Convert`TeXFormDump`maketex["" ""] = "\text "
$endgroup$
add a comment |
$begingroup$
You can just apply TeXForm to the content returned by WolframAlpha, although you will encounter 3 issues:
Some of the StyleBoxes use options that
TeXFormdoesn't recognize. TeXForm will issue messages and ignore them, so you can either useQuietor strip out those options.The
TeXFormproduced has empty lines. This causes problems for the MathJax engine.Some spaces get removed.
So, one could do the following:
content = WolframAlpha[
"integrate (sin(x))^4 dx",
"IndefiniteIntegral",2,"Content",
PodStates->"IndefiniteIntegral__Step-by-step solution"
];
StringReplace[Quiet @ ToString[content, TeXForm], "n" ~~ Whitespace ~~ "n" -> "n"]
which will fix the first 2 issues above. However, it is also possible to fix the internal code. The 3 specific problems with the internal code:
- Some spaces need to have a text wrapper so that they don't disapper.
- The internal code has a bug when Style uses lists of options.
- The internal code tosses in some superfluous carriage returns ("n") that break MathJax.
I will provide code to fix these issues at the bottom of my answer. After running that code, simply using TeXForm produces the desired output:
TeXForm @ WolframAlpha[
"integrate (sin(x))^4 dx",
"IndefiniteIntegral",2,"Content",
PodStates->"IndefiniteIntegral__Step-by-step solution"
]
$beginarrayl
beginarrayl
textTake the integral: \
int sin ^4(x) , dx \
endarray
\
hline
beginarrayl
textUse textthe textreduction textformula, int sin ^m(x) , dxtext text= -fraccos (x) sin ^m-1(x)mtext text+
fracm-1mint sin ^-2+m(x) , dx,text textwhere m=4: \
text text= -frac14 sin ^3(x) cos (x)+frac34int sin ^2(x) , dx \
endarray
\
beginarrayl
textWrite sin ^2(x)text textas frac12-frac12 cos (2 x): \
text text= -frac14 sin ^3(x) cos (x)+frac34int left(frac12-frac12 cos (2 x)right) , dx \
endarray
\
beginarrayl
textIntegrate textthe textsum textterm textby textterm textand textfactor textout textconstants: \
text text= -frac14 sin ^3(x) cos (x)-frac38int cos (2 x) , dx+frac38int 1 , dx \
endarray
\
beginarrayl
textFor textthe textintegrand cos (2 x),text textsubstitute u=2 xtext textand du=2, dx: \
text text= -frac14 sin ^3(x) cos (x)-frac316int cos (u) , du+frac38int 1 , dx \
endarray
\
beginarrayl
textThe textintegral textof cos (u)text textis sin (u): \
text text= -frac3 sin (u)16-frac14 sin ^3(x) cos (x)+frac38int 1 , dx \
endarray
\
beginarrayl
textThe textintegral textof 1text textis x: \
text text= -frac3 sin (u)16+frac3 x8-frac14 sin ^3(x) cos (x)+textconstant \
endarray
\
beginarrayl
textSubstitute textback textfor u=2 x: \
text text= frac3 x8-frac14 sin ^3(x) cos (x)-frac38 sin (x) cos (x)+textconstant \
endarray
\
beginarrayl
textWhich textis textequal textto: \
fbox$beginarrayll
textAnswer: & \
text & text text= frac132 (12 x-8 sin (2 x)+sin (4 x))+textconstant \
endarray
$ \
endarray
\
endarray$
As a comparison with kglr's answer, there is no need to use MakeExpression, no spurious parentheses get introduced (his answer has spurious parentheses in the "Answer" box), the spacing issue gets fixed (note the missing space in the line "the integral of 1is x:"), and the output is correct even when a step-by-step solution has only 1 step.
Now, for the code. Note that the usual caveats apply to the following code, which modifies the internal code used by Mathematica:
(* force autoloading of TeXForm code *)
TeXForm
(* the following modification just flattens out options *)
System`Convert`TeXFormDump`maketex[(StyleBox|Cell)[System`Convert`CommonDump`str_,System`Convert`CommonDump`sty_String:"",System`Convert`CommonDump`opts__?OptionQ]] := Module[
System`Convert`TeXFormDump`fv,System`Convert`TeXFormDump`und,System`Convert`TeXFormDump`fw,System`Convert`TeXFormDump`fs,System`Convert`CommonDump`pre="",System`Convert`CommonDump`post="",System`Convert`TeXFormDump`mid,
System`Convert`TeXFormDump`fv=FontVariations/. Flatten@System`Convert`CommonDump`opts/. FontVariations->;
System`Convert`TeXFormDump`und="Underline"/. System`Convert`TeXFormDump`fv/. "Underline"->False;
System`Convert`TeXFormDump`fw,System`Convert`TeXFormDump`fs=FontWeight,FontSlant/. Flatten@System`Convert`CommonDump`opts/. FontWeight;
System`Convert`TeXFormDump`mid=System`Convert`TeXFormDump`MakeTeX[StyleBox[System`Convert`CommonDump`str,System`Convert`CommonDump`sty]];
If[System`Convert`TeXFormDump`fs==="Italic",System`Convert`TeXFormDump`mid=If[StringMatchQ[System`Convert`TeXFormDump`mid,"\text*"],StringTake[System`Convert`TeXFormDump`mid,7,-2],"$"<>System`Convert`TeXFormDump`mid<>"$"];System`Convert`CommonDump`pre="\text\textit"<>System`Convert`CommonDump`pre;System`Convert`CommonDump`post=System`Convert`CommonDump`post<>"";];
If[System`Convert`TeXFormDump`und,System`Convert`CommonDump`pre="\underline"<>System`Convert`CommonDump`pre;System`Convert`CommonDump`post=System`Convert`CommonDump`post<>"";];
If[System`Convert`TeXFormDump`fw==="Bold",System`Convert`CommonDump`pre="\pmb"<>System`Convert`CommonDump`pre;System`Convert`CommonDump`post=System`Convert`CommonDump`post<>"";];
System`Convert`CommonDump`pre<>System`Convert`TeXFormDump`mid<>System`Convert`CommonDump`post
]
(* the following modification just removes the initial "n" *)
System`Convert`TeXFormDump`maketex[GridBox[System`Convert`TeXFormDump`grid_,System`Convert`CommonDump`opts___?OptionQ]] := Module[
System`Convert`TeXFormDump`colaln,System`Convert`TeXFormDump`rowdivs,System`Convert`TeXFormDump`outstr,System`Convert`TeXFormDump`i,System`Convert`TeXFormDump`cols,System`Convert`TeXFormDump`rows,
System`Convert`CommonDump`DebugPrint["------------------------------------"];
System`Convert`CommonDump`DebugPrint["maketex[GridBox[grid_, opts___?OptionQ]]"];
System`Convert`CommonDump`DebugPrint["grid: ",System`Convert`TeXFormDump`grid];
System`Convert`TeXFormDump`cols=Dimensions[System`Convert`TeXFormDump`grid][[2]];
System`Convert`TeXFormDump`rows=Dimensions[System`Convert`TeXFormDump`grid][[1]];
System`Convert`TeXFormDump`colaln=System`Convert`TeXFormDump`processColumnOptions[System`Convert`CommonDump`opts,System`Convert`TeXFormDump`cols];
System`Convert`TeXFormDump`rowdivs=System`Convert`TeXFormDump`processRowOptions[System`Convert`CommonDump`opts,System`Convert`TeXFormDump`rows];
System`Convert`TeXFormDump`outstr="\beginarray"<>System`Convert`TeXFormDump`colaln<>""<>"n";
For[System`Convert`TeXFormDump`i=1,System`Convert`TeXFormDump`i<=System`Convert`TeXFormDump`rows,System`Convert`TeXFormDump`i++,If[System`Convert`TeXFormDump`rowdivs[[System`Convert`TeXFormDump`i]]==True,System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>"\hline"<>"n"];System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>System`Convert`TeXFormDump`MakeRow[System`Convert`TeXFormDump`grid[[System`Convert`TeXFormDump`i]]];];
If[Last[System`Convert`TeXFormDump`rowdivs]==True,System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>"\hline"<>"n"];
System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>"\endarray"<>"n";
System`Convert`TeXFormDump`outstr
]
(* The following modification prevents some spaces from getting lost *)
System`Convert`TeXFormDump`maketex["" ""] = "\text "
$endgroup$
You can just apply TeXForm to the content returned by WolframAlpha, although you will encounter 3 issues:
Some of the StyleBoxes use options that
TeXFormdoesn't recognize. TeXForm will issue messages and ignore them, so you can either useQuietor strip out those options.The
TeXFormproduced has empty lines. This causes problems for the MathJax engine.Some spaces get removed.
So, one could do the following:
content = WolframAlpha[
"integrate (sin(x))^4 dx",
"IndefiniteIntegral",2,"Content",
PodStates->"IndefiniteIntegral__Step-by-step solution"
];
StringReplace[Quiet @ ToString[content, TeXForm], "n" ~~ Whitespace ~~ "n" -> "n"]
which will fix the first 2 issues above. However, it is also possible to fix the internal code. The 3 specific problems with the internal code:
- Some spaces need to have a text wrapper so that they don't disapper.
- The internal code has a bug when Style uses lists of options.
- The internal code tosses in some superfluous carriage returns ("n") that break MathJax.
I will provide code to fix these issues at the bottom of my answer. After running that code, simply using TeXForm produces the desired output:
TeXForm @ WolframAlpha[
"integrate (sin(x))^4 dx",
"IndefiniteIntegral",2,"Content",
PodStates->"IndefiniteIntegral__Step-by-step solution"
]
$beginarrayl
beginarrayl
textTake the integral: \
int sin ^4(x) , dx \
endarray
\
hline
beginarrayl
textUse textthe textreduction textformula, int sin ^m(x) , dxtext text= -fraccos (x) sin ^m-1(x)mtext text+
fracm-1mint sin ^-2+m(x) , dx,text textwhere m=4: \
text text= -frac14 sin ^3(x) cos (x)+frac34int sin ^2(x) , dx \
endarray
\
beginarrayl
textWrite sin ^2(x)text textas frac12-frac12 cos (2 x): \
text text= -frac14 sin ^3(x) cos (x)+frac34int left(frac12-frac12 cos (2 x)right) , dx \
endarray
\
beginarrayl
textIntegrate textthe textsum textterm textby textterm textand textfactor textout textconstants: \
text text= -frac14 sin ^3(x) cos (x)-frac38int cos (2 x) , dx+frac38int 1 , dx \
endarray
\
beginarrayl
textFor textthe textintegrand cos (2 x),text textsubstitute u=2 xtext textand du=2, dx: \
text text= -frac14 sin ^3(x) cos (x)-frac316int cos (u) , du+frac38int 1 , dx \
endarray
\
beginarrayl
textThe textintegral textof cos (u)text textis sin (u): \
text text= -frac3 sin (u)16-frac14 sin ^3(x) cos (x)+frac38int 1 , dx \
endarray
\
beginarrayl
textThe textintegral textof 1text textis x: \
text text= -frac3 sin (u)16+frac3 x8-frac14 sin ^3(x) cos (x)+textconstant \
endarray
\
beginarrayl
textSubstitute textback textfor u=2 x: \
text text= frac3 x8-frac14 sin ^3(x) cos (x)-frac38 sin (x) cos (x)+textconstant \
endarray
\
beginarrayl
textWhich textis textequal textto: \
fbox$beginarrayll
textAnswer: & \
text & text text= frac132 (12 x-8 sin (2 x)+sin (4 x))+textconstant \
endarray
$ \
endarray
\
endarray$
As a comparison with kglr's answer, there is no need to use MakeExpression, no spurious parentheses get introduced (his answer has spurious parentheses in the "Answer" box), the spacing issue gets fixed (note the missing space in the line "the integral of 1is x:"), and the output is correct even when a step-by-step solution has only 1 step.
Now, for the code. Note that the usual caveats apply to the following code, which modifies the internal code used by Mathematica:
(* force autoloading of TeXForm code *)
TeXForm
(* the following modification just flattens out options *)
System`Convert`TeXFormDump`maketex[(StyleBox|Cell)[System`Convert`CommonDump`str_,System`Convert`CommonDump`sty_String:"",System`Convert`CommonDump`opts__?OptionQ]] := Module[
System`Convert`TeXFormDump`fv,System`Convert`TeXFormDump`und,System`Convert`TeXFormDump`fw,System`Convert`TeXFormDump`fs,System`Convert`CommonDump`pre="",System`Convert`CommonDump`post="",System`Convert`TeXFormDump`mid,
System`Convert`TeXFormDump`fv=FontVariations/. Flatten@System`Convert`CommonDump`opts/. FontVariations->;
System`Convert`TeXFormDump`und="Underline"/. System`Convert`TeXFormDump`fv/. "Underline"->False;
System`Convert`TeXFormDump`fw,System`Convert`TeXFormDump`fs=FontWeight,FontSlant/. Flatten@System`Convert`CommonDump`opts/. FontWeight;
System`Convert`TeXFormDump`mid=System`Convert`TeXFormDump`MakeTeX[StyleBox[System`Convert`CommonDump`str,System`Convert`CommonDump`sty]];
If[System`Convert`TeXFormDump`fs==="Italic",System`Convert`TeXFormDump`mid=If[StringMatchQ[System`Convert`TeXFormDump`mid,"\text*"],StringTake[System`Convert`TeXFormDump`mid,7,-2],"$"<>System`Convert`TeXFormDump`mid<>"$"];System`Convert`CommonDump`pre="\text\textit"<>System`Convert`CommonDump`pre;System`Convert`CommonDump`post=System`Convert`CommonDump`post<>"";];
If[System`Convert`TeXFormDump`und,System`Convert`CommonDump`pre="\underline"<>System`Convert`CommonDump`pre;System`Convert`CommonDump`post=System`Convert`CommonDump`post<>"";];
If[System`Convert`TeXFormDump`fw==="Bold",System`Convert`CommonDump`pre="\pmb"<>System`Convert`CommonDump`pre;System`Convert`CommonDump`post=System`Convert`CommonDump`post<>"";];
System`Convert`CommonDump`pre<>System`Convert`TeXFormDump`mid<>System`Convert`CommonDump`post
]
(* the following modification just removes the initial "n" *)
System`Convert`TeXFormDump`maketex[GridBox[System`Convert`TeXFormDump`grid_,System`Convert`CommonDump`opts___?OptionQ]] := Module[
System`Convert`TeXFormDump`colaln,System`Convert`TeXFormDump`rowdivs,System`Convert`TeXFormDump`outstr,System`Convert`TeXFormDump`i,System`Convert`TeXFormDump`cols,System`Convert`TeXFormDump`rows,
System`Convert`CommonDump`DebugPrint["------------------------------------"];
System`Convert`CommonDump`DebugPrint["maketex[GridBox[grid_, opts___?OptionQ]]"];
System`Convert`CommonDump`DebugPrint["grid: ",System`Convert`TeXFormDump`grid];
System`Convert`TeXFormDump`cols=Dimensions[System`Convert`TeXFormDump`grid][[2]];
System`Convert`TeXFormDump`rows=Dimensions[System`Convert`TeXFormDump`grid][[1]];
System`Convert`TeXFormDump`colaln=System`Convert`TeXFormDump`processColumnOptions[System`Convert`CommonDump`opts,System`Convert`TeXFormDump`cols];
System`Convert`TeXFormDump`rowdivs=System`Convert`TeXFormDump`processRowOptions[System`Convert`CommonDump`opts,System`Convert`TeXFormDump`rows];
System`Convert`TeXFormDump`outstr="\beginarray"<>System`Convert`TeXFormDump`colaln<>""<>"n";
For[System`Convert`TeXFormDump`i=1,System`Convert`TeXFormDump`i<=System`Convert`TeXFormDump`rows,System`Convert`TeXFormDump`i++,If[System`Convert`TeXFormDump`rowdivs[[System`Convert`TeXFormDump`i]]==True,System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>"\hline"<>"n"];System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>System`Convert`TeXFormDump`MakeRow[System`Convert`TeXFormDump`grid[[System`Convert`TeXFormDump`i]]];];
If[Last[System`Convert`TeXFormDump`rowdivs]==True,System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>"\hline"<>"n"];
System`Convert`TeXFormDump`outstr=System`Convert`TeXFormDump`outstr<>"\endarray"<>"n";
System`Convert`TeXFormDump`outstr
]
(* The following modification prevents some spaces from getting lost *)
System`Convert`TeXFormDump`maketex["" ""] = "\text "
edited May 28 at 23:42
answered May 28 at 15:05
Carl WollCarl Woll
83.5k3105217
83.5k3105217
add a comment |
add a comment |
$begingroup$
I tried to do this before, I could not find an option.
Alternative is to use "Plaintext" option, then copy the plain text to your latex editor and do some (lots) of manually clean up and editing
r = WolframAlpha[
"Integrate[x Sin[x],x,0,Pi]", "Input", 2, "Plaintext",
PodStates -> "Input__Step-by-step solution"]
gives
Compute the definite integral:
integral_0^[Pi] x sin(x) dx
For the integrand x sin(x), integrate by parts, integral f dg = f g - integral g df, where
f = x, dg = sin(x) dx, df = dx, g = -cos(x):
= (-x cos(x)) right bracketing bar _0^[Pi] + integral_0^[Pi] cos(x) dx
Evaluate the antiderivative at the limits and subtract.
(-x cos(x)) right bracketing bar _0^[Pi] = (-[Pi] cos([Pi])) - (-0 cos(0)) = [Pi]:
= [Pi] + integral_0^[Pi] cos(x) dx
Apply the fundamental theorem of calculus.
The antiderivative of cos(x) is sin(x):
= [Pi] + sin(x) right bracketing bar _0^[Pi]
Evaluate the antiderivative at the limits and subtract.
sin(x) right bracketing bar _0^[Pi] = sin([Pi]) - sin(0) = 0:
Answer: |
| = [Pi]
Then clean it to become
documentclassarticle
usepackageamsmath
begin document
Compute the definite integral:
$int_0^pi x sin(x) ,dx$
For the integrand $x sin(x)$, integrate by parts, $int f dg = f g - int g df$, where
$f = x, dg = sin(x) dx, df = dx, g = -cos(x) = (-x cos(x))$
Evaluate the antiderivative at the limits and subtract. etc...
end document
When done cleaning it by hand, compile it

I could not find a "TeXForm" option to Wolfram Alpha output.
$endgroup$
add a comment |
$begingroup$
I tried to do this before, I could not find an option.
Alternative is to use "Plaintext" option, then copy the plain text to your latex editor and do some (lots) of manually clean up and editing
r = WolframAlpha[
"Integrate[x Sin[x],x,0,Pi]", "Input", 2, "Plaintext",
PodStates -> "Input__Step-by-step solution"]
gives
Compute the definite integral:
integral_0^[Pi] x sin(x) dx
For the integrand x sin(x), integrate by parts, integral f dg = f g - integral g df, where
f = x, dg = sin(x) dx, df = dx, g = -cos(x):
= (-x cos(x)) right bracketing bar _0^[Pi] + integral_0^[Pi] cos(x) dx
Evaluate the antiderivative at the limits and subtract.
(-x cos(x)) right bracketing bar _0^[Pi] = (-[Pi] cos([Pi])) - (-0 cos(0)) = [Pi]:
= [Pi] + integral_0^[Pi] cos(x) dx
Apply the fundamental theorem of calculus.
The antiderivative of cos(x) is sin(x):
= [Pi] + sin(x) right bracketing bar _0^[Pi]
Evaluate the antiderivative at the limits and subtract.
sin(x) right bracketing bar _0^[Pi] = sin([Pi]) - sin(0) = 0:
Answer: |
| = [Pi]
Then clean it to become
documentclassarticle
usepackageamsmath
begin document
Compute the definite integral:
$int_0^pi x sin(x) ,dx$
For the integrand $x sin(x)$, integrate by parts, $int f dg = f g - int g df$, where
$f = x, dg = sin(x) dx, df = dx, g = -cos(x) = (-x cos(x))$
Evaluate the antiderivative at the limits and subtract. etc...
end document
When done cleaning it by hand, compile it

I could not find a "TeXForm" option to Wolfram Alpha output.
$endgroup$
add a comment |
$begingroup$
I tried to do this before, I could not find an option.
Alternative is to use "Plaintext" option, then copy the plain text to your latex editor and do some (lots) of manually clean up and editing
r = WolframAlpha[
"Integrate[x Sin[x],x,0,Pi]", "Input", 2, "Plaintext",
PodStates -> "Input__Step-by-step solution"]
gives
Compute the definite integral:
integral_0^[Pi] x sin(x) dx
For the integrand x sin(x), integrate by parts, integral f dg = f g - integral g df, where
f = x, dg = sin(x) dx, df = dx, g = -cos(x):
= (-x cos(x)) right bracketing bar _0^[Pi] + integral_0^[Pi] cos(x) dx
Evaluate the antiderivative at the limits and subtract.
(-x cos(x)) right bracketing bar _0^[Pi] = (-[Pi] cos([Pi])) - (-0 cos(0)) = [Pi]:
= [Pi] + integral_0^[Pi] cos(x) dx
Apply the fundamental theorem of calculus.
The antiderivative of cos(x) is sin(x):
= [Pi] + sin(x) right bracketing bar _0^[Pi]
Evaluate the antiderivative at the limits and subtract.
sin(x) right bracketing bar _0^[Pi] = sin([Pi]) - sin(0) = 0:
Answer: |
| = [Pi]
Then clean it to become
documentclassarticle
usepackageamsmath
begin document
Compute the definite integral:
$int_0^pi x sin(x) ,dx$
For the integrand $x sin(x)$, integrate by parts, $int f dg = f g - int g df$, where
$f = x, dg = sin(x) dx, df = dx, g = -cos(x) = (-x cos(x))$
Evaluate the antiderivative at the limits and subtract. etc...
end document
When done cleaning it by hand, compile it

I could not find a "TeXForm" option to Wolfram Alpha output.
$endgroup$
I tried to do this before, I could not find an option.
Alternative is to use "Plaintext" option, then copy the plain text to your latex editor and do some (lots) of manually clean up and editing
r = WolframAlpha[
"Integrate[x Sin[x],x,0,Pi]", "Input", 2, "Plaintext",
PodStates -> "Input__Step-by-step solution"]
gives
Compute the definite integral:
integral_0^[Pi] x sin(x) dx
For the integrand x sin(x), integrate by parts, integral f dg = f g - integral g df, where
f = x, dg = sin(x) dx, df = dx, g = -cos(x):
= (-x cos(x)) right bracketing bar _0^[Pi] + integral_0^[Pi] cos(x) dx
Evaluate the antiderivative at the limits and subtract.
(-x cos(x)) right bracketing bar _0^[Pi] = (-[Pi] cos([Pi])) - (-0 cos(0)) = [Pi]:
= [Pi] + integral_0^[Pi] cos(x) dx
Apply the fundamental theorem of calculus.
The antiderivative of cos(x) is sin(x):
= [Pi] + sin(x) right bracketing bar _0^[Pi]
Evaluate the antiderivative at the limits and subtract.
sin(x) right bracketing bar _0^[Pi] = sin([Pi]) - sin(0) = 0:
Answer: |
| = [Pi]
Then clean it to become
documentclassarticle
usepackageamsmath
begin document
Compute the definite integral:
$int_0^pi x sin(x) ,dx$
For the integrand $x sin(x)$, integrate by parts, $int f dg = f g - int g df$, where
$f = x, dg = sin(x) dx, df = dx, g = -cos(x) = (-x cos(x))$
Evaluate the antiderivative at the limits and subtract. etc...
end document
When done cleaning it by hand, compile it

I could not find a "TeXForm" option to Wolfram Alpha output.
answered May 28 at 12:10
NasserNasser
59.7k492209
59.7k492209
add a comment |
add a comment |
$begingroup$
[See here][1]: not $LaTeX$ but a good start:
WolframAlpha["integrate (sin(x))^4 dx", "PodPlaintext",
PodStates -> "IndefiniteIntegral__Step-by-step solution"]
= 1/32 (12 x - 8 sin(2 x) + sin(4 x)) + constant", "(3 x)/8 + 1/8
sin(x) cos^3(x) - 1/8 sin^3(x) cos(x) - 1/2 sin(x) cos(x) +
constant", "(3 x)/8 - 1/8 i e^(-2 i x) + 1/8 i e^(2 i x) + 1/64 i
e^(-4 i x) - 1/64 i e^(4 i x) + constant", "(3 x)/8 - 1/4 sin(2 x) +
1/32 sin(4 x) + constant", "x^5/5 - (2 x^7)/21 + x^9/45 - (34
x^11)/10395 + O(x^13)
(Taylor series)", "integral_0^π sin^4(x) dx = (3 π)/8
≈1.1781", "integral_0^(2 π) sin^4(x) dx = (3 π)/4
≈2.35619", "integral_0^(2 π) (sin^8(x))/(2 π) dx
= 35/128≈0.273438"```
$endgroup$
$begingroup$
AfterWolframAlpha["integrate (sin(x))^4 dx"]we can just click "show step by step" but I still have doubts how to copy that solution to latex.
$endgroup$
– VirtualUser
May 28 at 11:54
add a comment |
$begingroup$
[See here][1]: not $LaTeX$ but a good start:
WolframAlpha["integrate (sin(x))^4 dx", "PodPlaintext",
PodStates -> "IndefiniteIntegral__Step-by-step solution"]
= 1/32 (12 x - 8 sin(2 x) + sin(4 x)) + constant", "(3 x)/8 + 1/8
sin(x) cos^3(x) - 1/8 sin^3(x) cos(x) - 1/2 sin(x) cos(x) +
constant", "(3 x)/8 - 1/8 i e^(-2 i x) + 1/8 i e^(2 i x) + 1/64 i
e^(-4 i x) - 1/64 i e^(4 i x) + constant", "(3 x)/8 - 1/4 sin(2 x) +
1/32 sin(4 x) + constant", "x^5/5 - (2 x^7)/21 + x^9/45 - (34
x^11)/10395 + O(x^13)
(Taylor series)", "integral_0^π sin^4(x) dx = (3 π)/8
≈1.1781", "integral_0^(2 π) sin^4(x) dx = (3 π)/4
≈2.35619", "integral_0^(2 π) (sin^8(x))/(2 π) dx
= 35/128≈0.273438"```
$endgroup$
$begingroup$
AfterWolframAlpha["integrate (sin(x))^4 dx"]we can just click "show step by step" but I still have doubts how to copy that solution to latex.
$endgroup$
– VirtualUser
May 28 at 11:54
add a comment |
$begingroup$
[See here][1]: not $LaTeX$ but a good start:
WolframAlpha["integrate (sin(x))^4 dx", "PodPlaintext",
PodStates -> "IndefiniteIntegral__Step-by-step solution"]
= 1/32 (12 x - 8 sin(2 x) + sin(4 x)) + constant", "(3 x)/8 + 1/8
sin(x) cos^3(x) - 1/8 sin^3(x) cos(x) - 1/2 sin(x) cos(x) +
constant", "(3 x)/8 - 1/8 i e^(-2 i x) + 1/8 i e^(2 i x) + 1/64 i
e^(-4 i x) - 1/64 i e^(4 i x) + constant", "(3 x)/8 - 1/4 sin(2 x) +
1/32 sin(4 x) + constant", "x^5/5 - (2 x^7)/21 + x^9/45 - (34
x^11)/10395 + O(x^13)
(Taylor series)", "integral_0^π sin^4(x) dx = (3 π)/8
≈1.1781", "integral_0^(2 π) sin^4(x) dx = (3 π)/4
≈2.35619", "integral_0^(2 π) (sin^8(x))/(2 π) dx
= 35/128≈0.273438"```
$endgroup$
[See here][1]: not $LaTeX$ but a good start:
WolframAlpha["integrate (sin(x))^4 dx", "PodPlaintext",
PodStates -> "IndefiniteIntegral__Step-by-step solution"]
= 1/32 (12 x - 8 sin(2 x) + sin(4 x)) + constant", "(3 x)/8 + 1/8
sin(x) cos^3(x) - 1/8 sin^3(x) cos(x) - 1/2 sin(x) cos(x) +
constant", "(3 x)/8 - 1/8 i e^(-2 i x) + 1/8 i e^(2 i x) + 1/64 i
e^(-4 i x) - 1/64 i e^(4 i x) + constant", "(3 x)/8 - 1/4 sin(2 x) +
1/32 sin(4 x) + constant", "x^5/5 - (2 x^7)/21 + x^9/45 - (34
x^11)/10395 + O(x^13)
(Taylor series)", "integral_0^π sin^4(x) dx = (3 π)/8
≈1.1781", "integral_0^(2 π) sin^4(x) dx = (3 π)/4
≈2.35619", "integral_0^(2 π) (sin^8(x))/(2 π) dx
= 35/128≈0.273438"```
edited May 28 at 12:14
answered May 28 at 11:51
RomanRoman
10.9k11943
10.9k11943
$begingroup$
AfterWolframAlpha["integrate (sin(x))^4 dx"]we can just click "show step by step" but I still have doubts how to copy that solution to latex.
$endgroup$
– VirtualUser
May 28 at 11:54
add a comment |
$begingroup$
AfterWolframAlpha["integrate (sin(x))^4 dx"]we can just click "show step by step" but I still have doubts how to copy that solution to latex.
$endgroup$
– VirtualUser
May 28 at 11:54
$begingroup$
After
WolframAlpha["integrate (sin(x))^4 dx"] we can just click "show step by step" but I still have doubts how to copy that solution to latex.$endgroup$
– VirtualUser
May 28 at 11:54
$begingroup$
After
WolframAlpha["integrate (sin(x))^4 dx"] we can just click "show step by step" but I still have doubts how to copy that solution to latex.$endgroup$
– VirtualUser
May 28 at 11:54
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f199245%2fget-latex-form-from-step-by-step-solution%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown