Dear all,
My approach was slightly different from trying to provide a Maxima level
interface with every feature of the tex() function. I wrote a lisp file
which redefines various things when I don't like the defaults.
It did take me some time to learn the lisp (and I'm sure this approach is
not idea!) but it may provide a starting point for others.
just load("cjstex.lisp"); to fire up these changes.
To strip off the $$'s I use
expstr:tex(expr,false),
expstr:concat(st,?subseq(expstr,2,ev(?length(expstr)-3,simp)),st)
I hope this helps.
Regards,
Chris
On Mon, 20 Aug 2007, Ryan Krauss wrote:
> Sorry, I have been away for a while.
>
> This sounds like a big step in the right direction. I think I really like it.
>
> I don't know what the current output is for matrices and fractions.
> Those were two big ones that I had to parse into something more
> Latex-ish when I wrote my python code to do semi-auto latex/maxima
>
> (%i21) tex(3/5);
> $${{3}\over{5}}$$
>
> I would prefer \frac{3}{5}, but that is fairly minor compared to what
> you have already done.
>
> Ryan
>
> On 7/22/07, Robert Dodier <robert.dodier at gmail.com> wrote:
>> On 7/12/07, Ryan Krauss <ryanlists at gmail.com> wrote:
>>
>>> I really two aspects of Robert's proposal:
>>> 1. being able to customized TEX-ENVIRONMENT so I could set mine to
>>> \begin{equation}...\end{equation}
>>> 2. I really like the idea of being able to output comments that don't
>>> get put in an environment - I like to add comments to any derivation
>>> or symbolic work so that I can make sense of it later or copy and
>>> paste it into a publication.
>>
>> OK, I've made some modifications to src/mactex.lisp (not
>> yet committed) to change the TeX environment.
>> Now the following outputs are obtained.
>>
>> load (stringproc); /* need some stuff for these examples */
>>
>> (1) Change environment for general expressions to \begin{equation} ...
>> \end{equation}
>>
>> get_tex_environment_default ();
>> => [$$, $$]
>> tex (sin(x) + cos(y));
>> => $$\cos y+\sin x$$
>> set_tex_environment_default
>> (concat (newline, "\\begin{equation}", newline),
>> concat (newline, "\\end{equation}", newline));
>> tex (sin(x) + cos(y));
>> =>
>> \begin{equation}
>> \cos y+\sin x
>> \end{equation}
>>
>>
>> (2) Change environment for functions from verbatim to equation
>>
>> get_tex_environment (":=");
>> => [$$, $$]
>> tex (foo(x) := sin(x)^3);
>> =>
>> \begin{verbatim}
>> foo(x):=sin(x)^3;
>> \end{verbatim}
>> set_tex_environment (":=", "$$", "$$");
>> tex (foo(x) := sin(x)^3);
>> => $$foo(x):=sin(x)^3$$
>>
>>
>> (3) Change environment for plain text to nothing. Also,
>> suppress the paragraph operator (the operator just
>> carries the TeX environment property on behalf of the text).
>>
>> get_tex_environment (paragraph);
>> => [$$, $$]
>> tex (paragraph ("A guy walks into a bar."));
>> => $${\it paragraph}\left(\mbox{{}A guy walks into a bar.{}}\right)$$
>> set_tex_environment (paragraph, newline, newline);
>> :lisp (defun tex-paragraph (x l r) (append l (list (l-string (cadr x))) r))
>> :lisp (setf (get '$paragraph 'tex) 'tex-paragraph)
>> tex (paragraph ("A guy walks into a bar."));
>> =>
>> A guy walks into a bar.
>>
>>
>> This stuff is implemented by introducing a new property,
>> TEX-ENVIRONMENT, which specifies the TeX environment
>> if present, and otherwise *TEX-ENVIRONMENT-DEFAULT* is
>> assumed. TEX-ENVIRONMENT is assigned to a few symbols
>> (only MDEFINE, MDEFMACRO, and MLABLE at present
>> because these were treated specially by TEX1 already).
>>
>> The user interface to maintain TEX-ENVIRONMENT comprises these functions:
>> get_tex_environment_default ()
>> set_tex_environment_default (env_open, env_close)
>> get_tex_environment (x)
>> set_tex_environment (x, env_open, env_close)
>>
>> Comments?
>>
>> best
>> Robert Dodier
>>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
-------------- next part --------------
;; Customize Maxima's TEX() function. To give better control to the output.
;; Chris Sangwin 24 Jan 2004.
;; Useful files:
;; \Maxima-5.9.0\share\maxima\5.9.0\share\utils\mactex-utilities.lisp
;; \Maxima-5.9.0\share\maxima\5.9.0\src\mactex.lisp
;; Additional mactex utilities taken from the distributed file
;; mactex-utilities.lisp
;; Based on code by Richard J. Fateman, copyright 1987.
;; Fateman's code was ported to Common Lisp by William
;; Schelter.
;; If you want LaTeX style quotients, first load mactex and second
;; define tex-mquotient as follows
(defun tex-mquotient (x l r)
(if (or (null (cddr x)) (cdddr x)) (wna-err (caar x)))
(setq l (tex (cadr x) (append l '("\\frac{")) nil 'mparen 'mparen)
r (tex (caddr x) (list "}{") (append '("}") r) 'mparen 'mparen))
(append l r))
;; Define an explicit multipliction
;;(defprop mtimes "\\times " texsym)
;;(defprop mtimes "\\cdot " texsym)
;; To use the LaTeX matrix style using the array environment, define tex-matrix as
;; Chris Sangwin 24/1/2004
;; This is a hack, sorry.
(defun tex-matrix-col-count (x csym)
;; Replaces everything with a csym
(if (null (cdr (car (cdr x)))) (list csym) ; Empty rows
; (cdr x) - a list of rows
; (car (cdr x)) - first row
; (cdr (car (cdr x))) - first row without (mlist)
(mapcon #'(lambda(y) (list csym)) (cdr (car (cdr x)))) ; replace each item with a csym
)
)
(defun tex-matrix (x l r) ;; matrix looks like ((mmatrix)((mlist) a b) ...)
(append l `("\\left(\\begin{array}{")
(tex-matrix-col-count x "c") ; Replace every column with a "c"
`("} ")
; Below is the bit we need - forms the array
(mapcan #'(lambda(y) (tex-list (cdr y) nil (list " \\\\ ") " & ")) (cdr x))
'("\\end{array}\\right)") r)
)
;; patch to tex-prefix to make sin(x) always like sin(x), and not the default sin x.
;; CJS 24 June 2004
(defun tex-prefix (x l r)
(tex (cadr x) (append l (texsym (caar x)) '("\\left( ") ) (append '(" \\right)") r) 'mparen 'mparen))
(defprop &? ("?") texsym)
;; Allow colour into TeX expressions from Maxima
;; Thanks to andrej.vodopivec at fmf.uni-lj.si Fri Jan 14 09:32:42 2005
(defun tex-texcolor (x l r)
(let
((front (append '("{\\color{")
(list (stripdollar (cadr x)))
'("}")))
(back (append '("{")
(tex (caddr x) nil nil 'mparen 'mparen)
'("}}"))))
(append l front back r)))
(defprop $texcolor tex-texcolor tex)
;; Changed log to ln, and other things
(mapc #'tex-setup
'(
(%acos "\\cos^{-1} ") ; CJS, changed!
(%asin "\\sin^{-1} ") ; CJS, changed!
(%atan "\\tan^{-1} ") ; CJS, changed!
; Latex's arg(x) is ... ?
(%cos "\\cos ")
(%cosh "\\cosh ")
(%cot "\\cot ")
(%coth "\\coth ")
(%csc "\\csc ")
; Latex's "deg" is ... ?
(%determinant "\\det ")
(%dim "\\dim ")
(%exp "\\exp ")
(%gcd "\\gcd ")
; Latex's "hom" is ... ?
(%inf "\\inf ") ; many will prefer "\\infty". Hmmm.
; Latex's "ker" is ... ?
; Latex's "lg" is ... ?
; lim is handled by tex-limit.
; Latex's "liminf" ... ?
; Latex's "limsup" ... ?
(%ln "\\ln ")
(%log "\\ln ") ; CJS, changed!
(%max "\\max ")
(%min "\\min ")
; Latex's "Pr" ... ?
(%sec "\\sec ")
(%sin "\\sin ")
(%sinh "\\sinh ")
; Latex's "sup" ... ?
(%tan "\\tan ")
(%tanh "\\tanh ")
;; (%erf "{\\rm erf}") this would tend to set erf(x) as erf x. Unusual
;(%laplace "{\\cal L}")
)) ;; etc