Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNUEmacs/ESS/Latex/Sweave: text displays differently when cursor is in latex code or in R code

When I scroll through an Sweave document (Rnw) with latex and R code, the text jumps around when the mode changes between Latex and ESS. The two modes disagree how text should be wrapped. Moreover, I've noticed that when I do

  1. M-x toggle-truncate-lines to enable truncate long lines while the cursor is within latex code
  2. move the cursor to R code
  3. return to the latex code

the truncated long lines mode is no longer on. Has anyone noticed this? Has anyone solved this problem?

like image 458
jrm Avatar asked Dec 14 '11 22:12

jrm


1 Answers

By reading a similar question on the [email protected] mailing list, this is what I've learned. When we scroll through the noweb file, we are switching major modes from ESS to LaTeX. Most major modes kill all local variables as part of their initialization, so when we just set the variable locally it's overwritten. To solve this, I modified a hook I found:

(add-hook 'LaTeX-mode-hook '(lambda () (if (string-match "\\.Rnw\\'" buffer-file-name) (setq fill-column 80))))

You could set a similar hook for longlines-mode or toggle-truncate-lines, etc, to meet your needs. The downside to this solution is that you're stuck with a single value for the variable set in the hook.

like image 164
jrm Avatar answered Sep 22 '22 16:09

jrm