1

I would like a co-author to edit a lyx file I created. He doesn't have knitr installed and he is going to edit only text and equations parts of the document where knitr generated content is not present. I would still like him to be able to generate the pdf file from lyx though. Under Documents / settings / modules, I can delete the Rnw (knitr) module. But then there are errors appearing.

I posted a sample lyx file under knitr_iris.lyx. When the knitr module is activated, Pdf generation works fine, but when you deselect the knitr module under Documents / settings / modules, the following errors pop up:

! You can't use `macro parameter character #' in horizontal mode.

! Missing $ inserted.

These are due to the use of $ and # in R. How to tell Lyx that knitr chunks are not latex code but something else that it should ignore?

1 Answer 1

0

You can do what you want to do by using LyX branches. First, highlight an ERT or knitr chunk (there are two ways to insert knitr in LyX) and go to Insert > Branch > Insert New Branch. Call the branch as you like, for example "knitrChunks". Now highlight the rest of the ERT or knitr chunks and go to Insert > Branch > knitrChunks (this branch exists now that you created it). When you see an "X" in front of the branch, that means it's deactivated. So when your co-author edits and wants to compile, he/she can just right-click on the branch inset and go to "deactivate branch" and remove the module. To reverse that, you can right click and go to "activate branch" and add the module back.

2
  • Great, thanks! I can even insert the knitrchunk branch multiple times in the document and de-activate these all at once. This is exactly what I needed. I updated the knitr_iris.lyx example. Sep 17, 2015 at 8:19
  • @Paul4forest good point, I should have stated clearly that when you activate the branch by right-clicking on one inset, it affects all insets.
    – scottkosty
    Sep 17, 2015 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.