diff --git a/parse.lisp b/parse.lisp index 5226c3b..9ab80f7 100644 --- a/parse.lisp +++ b/parse.lisp @@ -163,13 +163,19 @@ non-nil, allow names to be more than one character long." finally (let ((str (coerce token 'string))) (return - ;; the multi-char token is an operator. its a variable, so defer - ;; to multi-char-names - (if (or multi-char-names + (string + (cond + ;; single character unary operand + ((let ((val (operator-symbol (string (first token))))) + (and (symbolp val) (unary-p val))) + (first token)) + ;; multi-char variable, constant (true or false), or operator + ((or multi-char-names (operator-symbol str) (symbolp (interpret-operand str))) - str - (string (first token))))))) + str) + ;; single letter variable (multi-char-names is off) + (t (first token)))))))) (defun next-token (str &key multi-char-names) "Return a list of the next token in STR and how much whitespace it had." diff --git a/typeset.lisp b/typeset.lisp index 7360053..a8e4b5f 100644 --- a/typeset.lisp +++ b/typeset.lisp @@ -109,7 +109,7 @@ else collect char))) -(defun typeset-proposition (expr &optional +(defun typeset-proposition (expr &key (lookup-table *operator-ascii-lookup-alist*) var-name-transform (parent-prec most-positive-fixnum)) @@ -143,19 +143,25 @@ use (it controls when parentheses are applied.)" (if (null args) ;; we have one argument (format nil "~A~A~A~A" (car prefix-suffix) oper-ascii - (typeset-proposition first-arg lookup-table - var-name-transform our-prec) + (typeset-proposition first-arg + :lookup-table lookup-table + :var-name-transform var-name-transform + :parent-prec our-prec) (cdr prefix-suffix)) ;; we have many arguments (loop for arg in args collect oper-ascii into output collect - (typeset-proposition arg lookup-table - var-name-transform our-prec) + (typeset-proposition arg + :lookup-table lookup-table + :var-name-transform var-name-transform + :parent-prec our-prec) into output finally - (push (typeset-proposition first-arg lookup-table - var-name-transform our-prec) + (push (typeset-proposition first-arg + :lookup-table lookup-table + :var-name-transform var-name-transform + :parent-prec our-prec) output) (return (format nil "~A~{~A~^ ~}~A" (car prefix-suffix) output (cdr prefix-suffix)))))))))) @@ -168,8 +174,8 @@ NOTE: though the overall order does not matter, the order must be the same between each row." (let ((typeset-exprs (mapcar (lambda (expr) (typeset-proposition - expr *operator-latex-lookup-alist* - 'latex-var-name-transform)) + expr :lookup-table *operator-latex-lookup-alist* + :var-name-transform 'latex-var-name-transform)) (extract-truth-table-expressions table)))) (format nil "~ \\begin{tabular}{~{~*|c~}|}~ @@ -200,8 +206,8 @@ NOTE: though the overall order does not matter, the order must be the same between each row." (let ((typeset-exprs (mapcar (lambda (expr) (typeset-proposition - expr *operator-html-lookup-alist* - 'html-var-name-transform)) + expr :lookup-table *operator-html-lookup-alist* + :var-name-transform 'html-var-name-transform)) (extract-truth-table-expressions table)))) (format nil "~