1

When I tried to include an R plot with the following code into article(Noweb) in LyX 2.0.0

<<fig=TRUE>>=
library(graphics)
pairs(iris)
@

I got the following error message:

{C:/Users/MYaseen208/AppData/Local/MiKTeX/2.9/pdftex/config/pdftex.map}]
! Missing $ inserted.
<inserted text> 
                $
l.146 ...ir.Hp5960/lyx_tmpbuf2/sweave_example-007}

I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.
! LaTeX Error: File `C:/Users/MYaseen208/AppData/Local/Temp/lyx_tmpdir.Hp5
960/lyx_tmpbuf2/sweave_example-007' not found.

Any idea to fix this problem. Thanks

1 Answer 1

1

The contents of the chunk label (<<fig=TRUE>>=) get typeset, and the equals sign in it wants math mode. Tex is detecting that and assuming you made an error. The easiest thing to do would be to rename the chunk so that it does not contain the equals sign; something like <<figure is true>>.

(The second equal sign tells noweb that it is looking at a chunk definition. It's ok, and stays. It's the sign in the chunk name that's a problem. Nor is there a problem with equals in a chunk definition, because that gets treated as verbatim text. But the chunk label is different, because it is not treated as verbatim text.)

I daresay that you could put math mode symbols in the chunk name (<<fig$=$TRUE>>), but I worry (probably unnecessarily) this might confuse things at the tangling stage, and prefer to keep chunk labels to pure alphabetics. That's probably good practice anyway, because a chunk name should be a brief and understandable summary of what code in the chunk does, not code itself. So it's better to name your chunk in a way that clearly indicates what it does.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .