Suppose that you want to make a report about the golden section algorithm, and you want to explain the process with text in $\LaTeX$, and in every iteration you want to show in that report the values and the correct option, and then you want to continue explaining in $\LaTeX$.

For example 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)"];
  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}
solucionestimada = (Mu + La)/2;
valorestimado = ttheta[solucionestimada];
Print["La solución estimada es ", solucionestimada, 
  " donde la función toma valor ", valorestimado];

2 Answers 2


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.


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..."

enter image description here

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

enter image description here

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

enter image description here

STEP 4 Compile the LaTeX document and see the result:

enter image description here


Perhaps Barnett's Mathscape is what you're looking for here.

Unfortunately the link to the repository where his unix-based code was being stored appears to be dead now.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.