# How can you combine lines in LATEX, and lines Mathematica?

supose that You want to make a report about the golden section algorithm, and you want to explain the proccess with text in LATEX, and in every iteration you want to show in that report the values ande the correct option, and then, you want to continue explaining in LATEX.

How can you do this?

## For exemplae in this code, How can you do it?

itmax = 10;
tolerancia = 0.2;
alfa = (-1 + Sqrt[5])/2;
ttheta[Lambda_] = Lambda^2 + 2*Lambda;
a = -3;
b = 5;
La = a + (1 - alfa)*(b - a) // N;
Mu = a + alfa*(b - a) // N;
tthetaLa = ttheta[La];
tLacalc = "*";
tthetaMu = ttheta[Mu];
tMucalc = "*";
Printf["With * we show you that this is an evaluate of theta(t)"]
Printf["With NO* we show you that this is an evaluate of theta(t)"]
Print["iteración_k   |   a_k    b_k   |   Lambda_k     Mu_k   |   \
theta(Lambda_k)  theta(Mu_k)"];
Do[
L = b - a;
Print[" In the iteration "i, " you have the values:",
"\n a= ",a,
"\n b= ",b,
"\n Lamda= ",La,
"\n Mu= ",Mu,
"\n ",
"\n Where the values of theeta are:",
"\n theta (Lambda)= ",tthetaLa,
"\n theta (Mu)=     ",tthetaMu,
"os a =  |   ", a, "     ", b, "   |  ", La, "     ", Mu,
"   |  ", tthetaLa, tLacalc "      ", tthetaMu, tMucalc ];
If[tthetaLa > tthetaMu,
If[b - a < tolerancia, Break[]];

a = La;
La = Mu;
Mu = a + alfa (b - a);
tthetaLa = tthetaMu;
tLacalc = " ";
tthetaMu = ttheta[Mu];
tMucalc = " ";,

b = Mu;
Mu = La;
La = a + (1 - alfa) (b - a);
tthetaMu = tthetaLa;
tMucalc = " ";
tthetaLa = ttheta[La];
tLacalc = "*";
]
, {i, 1, itmax}
];
" donde la función toma valor ", valorestimado];

-

Well, as far as I know there is no single package that can be used to include Mathematica inputs/outputs in LaTeX.

So, the best you can do is to follow 4 easy steps to include your Mathematica codes into LaTeX.

STEP 1

Save your code in PDF format using Mathematica itself. In this case you have to select the blue part of your code at the right side of your Mathematica notebook and then choose the option "Save Selection As..."

STEP 2 Choose a name for your (now) PDF-formatted part of code. In this example I will use the name input.pdf.

STEP 3 Insert the PDF-file into your LaTeX document with the command \includegraphics[]{input.pdf}:

STEP 4 Compile the LaTeX document and see the result:

-