From p.dalgaard at biostat.ku.dk  Wed Sep 20 12:20:09 2006
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: 20 Sep 2006 12:20:09 +0200
Subject: [Rd] Sweave processes \Sexpr in commented LaTeX
	source	(2.3.1patched	and 2.4.0)
In-Reply-To: <17680.58131.594486.582029@celebrian.ci.tuwien.ac.at>
References: <1158711280.5348.24.camel@localhost.localdomain>
	<17680.58131.594486.582029@celebrian.ci.tuwien.ac.at>
Message-ID: <x2wt7y261y.fsf@viggo.kubism.ku.dk>

Friedrich Leisch <friedrich.leisch at stat.uni-muenchen.de> writes:

> >>>>> On Tue, 19 Sep 2006 19:14:39 -0500,
> >>>>> Marc Schwartz (MS) wrote:
> 
>   > Hi all,
>   > On FC5, using:
> 
>   >   Version 2.3.1 Patched (2006-08-06 r38829)
> 
>   > and today's
> 
>   >   R version 2.4.0 alpha (2006-09-19 r39397)
> 
>   > with the following .Rnw file:
> 
> 
>   > \documentclass[10pt]{article}
>   > \begin{document}
> 
>   >    This line should print '2': \Sexpr{1 + 1}
>   > %% This line should NOT print '2': \Sexpr{1 + 1}
> 
>   > \end{document}
> 
> 
>   > The \Sexpr in the second line is processed even though the line is
>   > commented. This results in the following .tex file content (in the case
>   > of R 2.4.0):
> 
> 
>   > \documentclass[10pt]{article}
>   > \usepackage{/home/marcs/R.Files/SourceCode/R-alpha/share/texmf/Sweave}
>   > \begin{document}
> 
>   >    This line should print '2': 2
>   > %% This line should NOT print '2': 2
> 
>   > \end{document}
> 
> 
> 
>   > Shouldn't Sweave just generally ignore commented LaTeX code? In
>   > reviewing Sweave.R I did not see a check for this, so perhaps there are
>   > circumstances where one wants a \Sexpr in commented LaTeX code
>   > processed. An example escapes me at the moment however.
> 
> Sweave does not parse the LaTeX part of the document at all (which
> makes it a lot easier), all it does is looking for its own "magic
> strings" and replacing those, wherever they might occur.
> 
> If we would start to respect comments, we would need a some kind of
> parser for LaTeX, which we currently don't need ... and starting to
> parse LaTeX would also open a can of worms of possible requests (what
> to do with Sexpr inside verbatim, etc, etc).

..not to mention TeX comments inside Sexpr (e.g. %*%...). Skipping
lines with % as the first character might be a viable compromise
though. 

-- 
   O__  ---- Peter Dalgaard             ?ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




[Rd] Sweave processes \Sexpr in commented LaTeX source (2.3.1patched and 2.4.0)
Peter Dalgaard