18

I want to use Maxima to evaluate documents. It's easy to convert Maxima output into TeX:

(%i1) tex(5*x^2+sin(x)+c)$
$$\sin x+5\,x^2+c$$

However, it doesn't work for previously input lines:

(%i2) 5*x^2+sin(x)+c;
                                           2
(%o2)                          sin(x) + 5 x  + c
(%i3) tex(%i2);

\begin{verbatim}
(%i2)sin(x)+5*x^2+c;
\end{verbatim}

(%o3)                                (%i2)

After much research (including here which is close but no cigar) I've come up empty. Any insights?

Ryan Kennedy
  • 3,275
  • 4
  • 30
  • 47
  • 1
    Incidentally, using `$$…$$` to delimit math in LaTeX isn’t advisable. There are some spacing inconsistencies with other math environments and it’s generally recommended to either use `\[…\]` or one of the extended AMSmath environments such as `align` etc (similar for `$…$` vs. `\(…\)` but for different reasons). – Konrad Rudolph Mar 11 '13 at 16:58
  • Thanks. I plan to strip the dollar signs and do a bit of post-processing. – Ryan Kennedy Mar 11 '13 at 18:17

1 Answers1

23

Try this.

tex (''%i2);

or

apply (tex, [%i2]);
Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
  • 4
    It would be nice if some explanation were added. For us who couldn't think of those solutions ourselves (I'm one of them) , it would be very instructive. – Albert van der Horst Dec 26 '13 at 12:41
  • 2
    @AlbertvanderHorst Well, the problem is that `tex` inspects its argument to see if it is an input or output label and if so, it treats those specially. In order to defeat the inspection, you have to ensure that `tex` sees the value of `%i2` or whatever is the argument. Two ways to accomplish that are to use quote-quote (i.e., two single quotes) to cause the value to be interpolated into the input before evaluation, or `apply` to apply the function to the value of the label. `apply` is more general, as quote-quote only works on console input, but quote-quote is more convenient. – Robert Dodier Dec 26 '13 at 21:00
  • 1
    Neither trick works in wxMaxima as of today. I think the answer needs updating. – Szczepan Hołyszewski Feb 02 '22 at 02:46
  • @SzczepanHołyszewski Hmm, I just tried it again, and it works the same as before; I tried wxMaxima 19.07 + Maxima 5.43.2. If you are getting some erroneous output, that suggests a bug in either wxMaxima and/or Maxima; can I ask you to create a bug report? See https://github.com/wxMaxima-developers/wxmaxima/issues and https://sourceforge.net/p/maxima/bugs/ . – Robert Dodier Feb 02 '22 at 03:43
  • I'm not getting erroneous output, I'm just failing to completely prevent interpreting the expression in some cases involving quadratic surds. The result is NOT a symbol-by-symbol translation of the input into LaTeX. I need to typeset the expression exactly as I want it, because I must illustrate a particular step in the derivation and I don't want maxima to do any "helpful redaction" that obscures the idea I want to convey. – Szczepan Hołyszewski Feb 02 '22 at 03:49
  • OK, got it. It sounds like you want the same behavior as in this question: https://stackoverflow.com/questions/70835041/suspending-simplification-of-integral If that doesn't cover it, I think you should open a new question. I can try to help if you describe a little bit about what you're trying to do. – Robert Dodier Feb 02 '22 at 17:26