Richard Fateman <fateman at eecs.berkeley.edu> writes:
> I'm not sure about the nil vs $false, but it looks like a bug in
> handling "if".
>
> in particular tex ('(if x>0 then 0)); works just fine.
Interesting. Notice the end of PARSE-CONDITION in nparse.lisp:
(t ; Note: $false instead of () makes DISPLA suppress display!
(list t '$false)))))
DIM-MCOND in displa.lisp handles both cases:
(unless (or (eq '$false else-or-then) (eq nil else-or-then))
and it also handles a third case, when the last condition is not T.
All three of these cases are rendered as "if a then b" by DISPLA:
((%mcond) $a $b)
((%mcond) $a $b t nil)
((%mcond) $a $b t $false)
I wouldn't be surprised if we could remove this old '$FALSE cruft from
both nparse.lisp and displa.lisp. However, I don't feel confident that
I understand the possible consequences. Therefore, I have changed
mactex.lisp to handle all three cases the same as DISPLA does.
Here's a new patch. Comments and suggestions welcome, or else I'll soon
commit this to both the trunk and the 5.23 branch.
Mark
*** mactex.lisp 22 Nov 2009 04:53:36 -0000 1.71
--- mactex.lisp 11 Jan 2011 01:49:10 -0000
***************
*** 1,3 ****
--- 1,5 ----
+ ;;; -*- Mode: Lisp; Package: Maxima; Syntax: Common-Lisp; Base: 10 -*- ;;;;
+
(in-package :maxima)
;; TeX-printing
***************
*** 937,950 ****
((= c 1)(cons (car n)(odds (cdr n) 0)))
((= c 0)(odds (cdr n) 1))))
(defun tex-mcond (x l r)
! (append l
! (tex (cadr x) '("\\mathbf{if}\\;")
! '("\\;\\mathbf{then}\\;") 'mparen 'mparen)
! (if (eql (fifth x) '$false)
! (tex (caddr x) nil r 'mcond rop)
! (append (tex (caddr x) nil nil 'mparen 'mparen)
! (tex (fifth x) '("\\;\\mathbf{else}\\;") r 'mcond rop)))))
(defprop mdo tex-mdo tex)
(defprop mdoin tex-mdoin tex)
--- 939,964 ----
((= c 1)(cons (car n)(odds (cdr n) 0)))
((= c 0)(odds (cdr n) 1))))
+ ;; Modified by Mark H Weaver <mhw at netris.org> in January 2011 to add
+ ;; support for MCOND expressions containing more than one non-T
+ ;; condition, i.e. elseif, which was added after this code was
+ ;; originally written by RJF. The format of MCOND expressions is
+ ;; documented above the definition of dim-mcond in displa.lisp.
(defun tex-mcond (x l r)
! (labels
! ((recurse (x l)
! (append
! (tex (car x) l '("\\;\\mathbf{then}\\;") 'mparen 'mparen)
! (cond ((member (cddr x) '(() (t nil) (t $false)) :test #'equal)
! (tex (second x) nil r 'mcond rop))
! ((eq (third x) t)
! (append
! (tex (second x) nil nil 'mparen 'mparen)
! (tex (fourth x) '("\\;\\mathbf{else}\\;") r 'mcond rop)))
! (t (append
! (tex (second x) nil nil 'mparen 'mparen)
! (recurse (cddr x) '("\\;\\mathbf{elseif}\\;"))))))))
! (append l (recurse (cdr x) '("\\mathbf{if}\\;")))))
(defprop mdo tex-mdo tex)
(defprop mdoin tex-mdoin tex)