Incompatibility between the emaxima LaTeX mode and the knitr R package.



Dear Yihui, dear list,

Many thanks for this very prompt answer : this second suggestion worked
perfectly.

I'll try to see whether a \LaTeX macro can be used to deterine if the
current compilation is made for DVI or PDF. If so, the relevant package
options could be determined at weaving time.

Alternatively, an option could be added into emaxima.sty, which would
allow its use with possible other color-needing latex packages.

Again, thank you very much !

					Emmanuel Charpentier

Le dimanche 25 novembre 2012 ? 14:34 -0600, Yihui Xie a ?crit :
> I just looked at the source code of emaxima.sty; it uses the pdftex
> option when you produce PDF output. Then I think you can modify my
> hook accordingly, e.g.
> 
> <<no-color, include=FALSE>>=
> knit_hooks$set(document = function(x) {
>   sub('\\usepackage{graphicx, color}',
>       '\\usepackage{graphicx}\\usepackage[pdftex]{color}',
>       x, fixed = TRUE)
> })
> @
> 
> Hopefully this can avoid clash with emaxima.
> 
> Regards,
> Yihui
> --
> Yihui Xie <xieyihui at gmail.com>
> Phone: 515-294-2465 Web: http://yihui.name
> Department of Statistics, Iowa State University
> 2215 Snedecor Hall, Ames, IA
> 
> 
> On Sun, Nov 25, 2012 at 2:22 PM, Emmanuel Charpentier
> <emm.charpentier at free.fr> wrote:
> > Dear Yihui,
> >
> > Unfortunately, your solution does not apply. The knitr-added preamble
> > still defines a bunch of latex commands using color commands from
> > color...
> >
> > One could redefine them without using color, but I'm afraid this entails
> > a large work. I fear that readapting emaxima might be easier...
> >
> > Sincerely yours,
> >
> >                                         Emmanuel Charpentier
> >
> > Le dimanche 25 novembre 2012 ? 13:13 -0600, Yihui Xie a ?crit :
> >> Hi,
> >>
> >> On knitr's side, you can remove the color package using the `document`
> >> hook (if you have the latest version of knitr), e.g.
> >>
> >> <<no-color, include=FALSE>>=
> >> knit_hooks$set(document = function(x) {
> >>   sub('\\usepackage{graphicx, color}', '\\usepackage{graphicx}', x,
> >> fixed = TRUE)
> >> })
> >> @
> >>
> >>
> >> Regards,
> >> Yihui
> >> --
> >> Yihui Xie <xieyihui at gmail.com>
> >> Phone: 515-294-2465 Web: http://yihui.name
> >> Department of Statistics, Iowa State University
> >> 2215 Snedecor Hall, Ames, IA
> >>
> >>
> >> On Sun, Nov 25, 2012 at 11:19 AM, Emmanuel Charpentier
> >> <emm.charpentier at free.fr> wrote:
> >> > Dear Xie, dear list,
> >> >
> >> > In order to add some trace of symbolic computations related to a
> >> > statistical problem in the relevant document, created via R and knitr, I
> >> > tried to use the emaxima LaTeX style (which I already had used
> >> > successfully in another Sweave-processed .Rnw file).
> >> >
> >> > It turns out that this is not currently possible :
> >> >
> >> > - the knitting process adds \usepackage{graphicx, color} right after the
> >> > \documentclass declaration opening the .Rnw file.
> >> >
> >> > - The emaxima package also uses color, in an incompatible way. From the
> >> > pdflatex log :
> >> >
> >> > ==============================================================
> >> > (/usr/share/texmf/tex/latex/emaxima.sty
> >> > (/usr/share/texlive/texmf-dist/tex/latex/base/ifthen.sty)
> >> >
> >> > ! LaTeX Error: Option clash for package color.
> >> >
> >> > See the LaTeX manual or LaTeX Companion for explanation.
> >> > Type  H <return>  for immediate help.
> >> >  ...
> >> >
> >> > l.85 \usepackage
> >> >                 {pdfcolmk}
> >> > ?
> >> > ! Emergency stop.
> >> >  ...
> >> >
> >> > l.85 \usepackage
> >> >                 {pdfcolmk}
> >> > !  ==> Fatal error occurred, no output PDF file produced!
> >> > ==============================================================
> >> >
> >> > Can someone suggest a workaround ?
> >> >
> >> > Sincerely,
> >> >
> >> >                                         Emmanuel Charpentier
> >> >
> >> >
> >
> >