Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've encountered a problem when I'm using Sweave to convert an .Rnw file into a .tex file. Sweave is replacing three options from hyperref's \hypersetup block with the value NA.

This is the section in the .Rnw file

\hypersetup{
baseurl={.},
%bookmarks=true,         % show bookmarks bar?
unicode=false,          % non-Latin characters in Acrobat’s bookmarks
pdftoolbar=true,        % show Acrobat’s toolbar?
pdfmenubar=true,        % show Acrobat’s menu?
pdffitwindow=false,     % window fit to page when opened
pdfstartview={FitH},    % fits the width of the page to the window

The resulting LaTeX for the same section comes out as:

\hypersetup{
baseurl={.},
%bookmarks=true,         % show bookmarks bar?
NA
NA
NA
pdffitwindow=false,     % window fit to page when opened
pdfstartview={FitH},    % fits the width of the page to the window

As far as I can tell the rest of the document is fine. Removing the offending sections allows the compilation of the LaTeX. I'm running R 2.13.1. Has anyone else encountered this problem? Alternatively, could anyone suggest what Sweave finds objectionable about those three options in particular?

share|improve this question
    
Related question here: tex.stackexchange.com/q/23273 –  Aaron Nov 14 '11 at 13:23
add comment

1 Answer

up vote 7 down vote accepted

The problem is that you have cut and pasted the \hypersetup commands from a PDF, and there are invalid characters in the code, specifically the right single quotation mark If you replace those characters with regular single quote marks ', the file should compile. This is caused by the way Sweave handles its input, not by the TeX file itself.

So the reason that it is those three lines is that they all contain the string "Acrobat’s".

Update

After some troubleshooting it seems that the underlying problem is a mismatch between the actual file encoding and the locale that R assumes when it runs Sweave on the file. In my particular case (running Sweave from within TeXShop) the locale wasn't being set properly. The solution was to add

export LANG=en_US.UTF-8

to the script within TeXShop that was running Sweave. Depending on how you are running Sweave the problem may be the same: you need to make sure that the encoding of the file matches the encoding that R is using when Sweave processes the file. If you are running from within an editor, check the script that it uses to compile Sweave documents; if you are running from the command line, check that your .bashrc or .profile has the locale set correctly.

For a minimal test document to show this, see this stackoverflow question: Sweave doesn't seem to get .Rnw file encoding right.

Thanks a lot to Aaron for helping to troubleshoot this problem with me.

share|improve this answer
    
See the iconv function for details. Sweave calls this function on each line, converting from the original file encoding to the current locale encoding. iconv can substitute a character string when it gets to something it can't reencode, but Sweave doesn't use this feature so it instead returns NA. So another solution might be to change your current locale to one that understands the right quote. However, you'd want to make sure LaTeX could handle the result properly, which could be difficult. –  Aaron Sep 20 '11 at 16:48
    
@Aaron I thought about that, but it doesn't seem to help. On my Mac, sessionInfo() returns en_US.UTF-8, yet with the .Rnw file saved as UTF8 the document still produces NAs. –  Alan Munn Sep 20 '11 at 20:39
    
@AlanMunn thanks, the 's were causing the problem. The weird thing is that I'd not touched that preamble in months and the previous versions of Sweave (or more accurately pgfSweave) had not exhibited this problem. –  Alastair Sep 21 '11 at 0:32
    
@AlanMunn abd @Alastair, Perhaps it's an OS or version issue then; on my Mac I have the same encoding according to sessionInfo(), but I don't get NAs. –  Aaron Sep 21 '11 at 14:36
    
@Aaron I wonder if the problem is the locale from within the R.app (which is correct) vs. the locale when R is called from the command line. –  Alan Munn Sep 21 '11 at 16:32
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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