2

I have used texput to set the tex1 output of log(x) to be \ln(x) with

texput('log, lambda([e],[a]:args(e), printf(false, "\\ln(~a)", tex1(a))));

and am wondering if it is possible to also set the output for something like (log(x))^n? In particular I'd like to use the \ln^n(x) convention.

Rax Adaam
  • 790
  • 3
  • 11
  • Try this: `:lisp (push '%log *tex-mexpt-trig-like-fns*)` – Robert Dodier Feb 05 '21 at 03:02
  • Thank you, Robert. That did half the job -- the right power style, but for the original tex output: `log(x)^2` returned `\log^2 \left(x \right)` instead of `\ln^2 \left( x \right)`. I tried redefining `\log` to `\ln` (i.e. using `prefix` and not applying any parentheses), but that didn't work either. In the worst case, I'll just add a local KaTeX macro to redefine `\log` to `\ln` locally. – Rax Adaam Feb 05 '21 at 15:58
  • 1
    OK, thanks for the info. That it doesn't work as described is a bug and I'll try to work on that. As a work around, try, in addition to what you have already: `:lisp (setf (get '%log 'texsym) '("\\ln ")) ` (A happy side effect of that is that you can say just `texput(log, "\\ln ")` instead of the longer incantation with `lambda([e], ...)`.) – Robert Dodier Feb 05 '21 at 16:23
  • Would it be helpful to file a bug report for this? Happy to do so, if it saves you any time. – Rax Adaam Feb 06 '21 at 04:08
  • 1
    About bug reports, yes, generally that helps a lot. However in this case I'm already on it, so I'll just cover it without a bug report. – Robert Dodier Feb 06 '21 at 20:50
  • For the record, I fixed the texput bug with commit 4e65bc. Bug fix will appear in next release (Maxima 5.46). – Robert Dodier Dec 15 '21 at 01:11

1 Answers1

2

The strangeness around TeX output for log is a bug, which I'm working on. But here is a work around which gets the behavior you want, I think.

Here I'm calling both texput(log, "\\ln ") and texput(log, "\\ln ", prefix), to set the TeX output for log in different contexts, and also :lisp (push log *tex-mexpt-trig-like-fns*) to have log treated similarly to trig functions.

(%i1) stringdisp: true $
(%i2) map (tex1, [log(x), log(x+1), log(x)^n]);                              
(%o2)   ["\log x", "\log \left(x+1\right)", "\left(\log x\right)^{n}"]
(%i3) texput (log, "\\ln ");
(%o3)                               "\ln "
(%i4) texput (log, "\\ln ", prefix);
(%o4)                               "\ln "
(%i5) map (tex1, [log(x), log(x+1), log(x)^n]); 
(%o5)           ["\ln x", "\ln \left(x+1\right)", "\ln x^{n}"]

Hmm, that's not quite enough. Oh, that's right, I forgot the bit about trig functions.

(%i6) :lisp (push '%log *tex-mexpt-trig-like-fns*)
(%LOG %SIN %COS %TAN %SINH %COSH %TANH %ASIN %ACOS %ATAN %ASINH %ACOSH %ATANH)
(%i6) map (tex1, [log(x), log(x+1), log(x)^n]); 
(%o6)           ["\ln x", "\ln \left(x+1\right)", "\ln ^{n}x"]

Does that seem right?

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
  • I just noticed that none of `sec`, `csc` or `cot` are on this list for trig-like exponents, either. I just ran the same commands for those, but wondered if this would constitute a "bug" or if they were intentionally omitted? – Rax Adaam Mar 08 '21 at 21:45
  • Yeah, it's a bug; just an oversight I guess. – Robert Dodier Mar 09 '21 at 06:06
  • For the record, putting sec, csc, and cot on the list of trig-like operators was in commit 7bcc17, which is present in the current release (Maxima 5.45). – Robert Dodier Dec 15 '21 at 01:13