Dear Renalud,, > Would a 'results=tex' (html, text) be possible? or 'results=source' that > could be combined with \if{format}{text}?
This may well be a clean approach. After my previous email, I looked again at the definition of thr \AsIs macro. Its purpose seems to be to typeset text containing special characters in normal text mode and thus its purpose is different from \verb and ``verbatm' macros/environments in LaTeX. Georgi -- Dr Georgi Boshnakov tel: (+44) (0)161 306 3684 School of Mathematics fax: (+44) (0)161 306 3669 Alan Turing Building 1.125 The University of Manchester email: georgi.boshna...@manchester.ac.uk Oxford Road Manchester M13 9PL UK ________________________________________ From: Renaud Gaujoux [ren...@cbio.uct.ac.za] Sent: 03 November 2011 14:21 To: Georgi Boshnakov Cc: Duncan Murdoch; Renaud Gaujoux; r-devel@r-project.org Subject: Re: [Rd] R CMD check and error in an \Sexpr in an Rd file Thank you Georgi. With the fix \long the output is indeed consistent with the documentation. I think my use of cat() worked by luck as its output should not have been rendered. Would a 'results=tex' (html, text) be possible? or 'results=source' that could be combined with \if{format}{text}? This would allow to generate custom Latex, or HTML code, but it might also be is hazardous... Renaud -- Renaud Gaujoux Computational Biology - University of Cape Town South Africa On 03/11/2011 15:50, Georgi Boshnakov wrote: > Dear Duncan and Renauld, > > > The error caused by the empty line(s) can be removed by prefixin the macro > with \long > in Rd.sty: > > \long\def\Rd@AsIsX#1{\normalfont #1\egroup} > > but the slash-n's come up in the output. > > In "text mode" this seems not to be a problem. Following normal TeX rules one > needs to enter an empty line, e.g. by \n\n. > > Having written that, I tried putting two \n's in the verbatim text and it > seems to work (see below). > > I need to consult the TeX book to be sure but the > problem with AsIs seems to be that by the time it starts processing its > argument it has been tokenized by TeX > (hence single newlines have become spaces). > > Further thought may be needed about the new lines in verbatim. > I may have missed again something but it seems that the observed output is > consistent with the > documentation, which states: > > "results=verbatim Print the results of the code just as if it was > executed at the > console, and include the printed results verbatim. (Invisible results > will not print.)" > > And the examples print on the console as they appear in output (with print, > not cat). > > Do we need exception from the general rule? > > An alternative would be to introduce results=verbatimLines option. > > > Georgi > > \name{Sexpr} > \alias{Sexpr} > \title{Error and verbatim in Sexpr} > \description{ > Testing Sexpr in Rd files > > %\Sexpr[results=verbatim, stage=render]{stop("error in sexpr")} > > Verbatim: > > 1: \Sexpr[results=verbatim, stage=render]{cat("line\n\nnext line\n\n and > another")} > > % 1a: \Sexpr[results=text, stage=render]{capture.output(cat(c("line", > "next line\n"),sep="\n", collapse="\n"))} > > 2: \Sexpr[results=verbatim, stage=render]{"line\nnext line\n"} > > 3: \Sexpr[results=verbatim, stage=render]{list("line\nnext line", 3)} > > 4: \Sexpr[results=verbatim, stage=render]{list(c("line", "next line"), > 3)} > > Text: > > 1: \Sexpr[results=text, stage=render]{cat("line\nnext line\n")} > > 2: \Sexpr[results=text, stage=render]{"line\nnext line\n"} > > 3: \Sexpr[results=text, stage=render]{list("line\n\nnext line\\\\\\\\ > \\\\newline and another", 3)} > > } > > > > -- > Dr Georgi Boshnakov tel: (+44) (0)161 306 3684 > School of Mathematics fax: (+44) (0)161 306 3669 > Alan Turing Building 1.125 > The University of Manchester email: georgi.boshna...@manchester.ac.uk > Oxford Road > Manchester M13 9PL > UK > > > ________________________________________ > From: Duncan Murdoch [murdoch.dun...@gmail.com] > Sent: 03 November 2011 12:19 > To: Renaud Gaujoux > Cc: Georgi Boshnakov; r-devel@r-project.org > Subject: Re: [Rd] R CMD check and error in an \Sexpr in an Rd file > > On 11-11-03 7:58 AM, Renaud Gaujoux wrote: >> Georgi, I tried with paste() instead of cat(), but I then get the >> following in my PDF manual: >> >> [1] "line\nnext line" >> >> i.e. what would be printed in the R console, which is not what I want. >> I would like to get something like this in the Latex code: >> >> \begin{verbatim} >> line >> next line >> \end{verbatim} > I don't think you want that: it forces display mode. You might want > verbatim text displayed inline, like \verb does. > >> Using cat() I get the following in the Latex code: >> >> \AsIs{ >> line >> next line} >> >> which does not render as a new line in the PDF and breaks if empty lines >> are present in the output text. > So the problem is with the \AsIs macro. You can see the definition in > the Rd.sty file in R_HOME/share/texmf/tex/latex. Can you suggest an > improvement? > > Duncan Murdoch > >> Besides it will also break on \Sexpr[results=verbatim, >> stage=render]{list("text", 3)}. >> >> But maybe this is not what 'results=verbatim' is supposed to do nor to >> be used for? >> >> Renaud >> >> Another test Rd file. >> >> %%%%%%%%% >> \name{Sexpr} >> \alias{Sexpr} >> \title{Error and verbatim in Sexpr} >> \description{ >> Testing Sexpr in Rd files >> >> %\Sexpr[results=verbatim, stage=render]{stop("error in sexpr")} >> >> Verbatim: >> >> 1: \Sexpr[results=verbatim, stage=render]{cat("line\nnext line\n")} >> >> 2: \Sexpr[results=verbatim, stage=render]{"line\nnext line\n"} >> >> 3: \Sexpr[results=verbatim, stage=render]{list("line\nnext line", 3)} >> >> Text: >> >> 1: \Sexpr[results=text, stage=render]{cat("line\nnext line\n")} >> >> 2: \Sexpr[results=text, stage=render]{"line\nnext line\n"} >> >> 3: \Sexpr[results=text, stage=render]{list("line\nnext line", 3)} >> >> } >> %%%%% >> >> ______________________________________________ >> R-devel@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel