Search code examples
rknitrrstudiosweavexelatex

Error when \% is included in a sectioning command


When I try to input a \% in a \subsection's title and Compile pdf, I get the following error:

File ended while scanning use of \@@BOOKMARK.

How should I do it?

EDIT

Here is a reproducible example. The file is encoded in UTF-8 format.

\documentclass[a4paper]{article}


\usepackage{fontspec}
\usepackage{hyperref}
\usepackage{longtable}
\usepackage{rotating}
\usepackage{tabularx}
\usepackage{lscape}
\usepackage[normalem]{ulem}


\setmainfont[Scale=1.0]{Times New Roman} 
\setsansfont{Times New Roman}


\begin{document}

\section{Μέσες τιμές και 95\% Διαστήματα Εμπιστοσύνης}

\subsection{a \% b cd}

<<>>=
1+1
@

\end{document}

Solution

  • It is perhaps a configuration problem of hyperref. I do not have Times New Roman, but I succeeded with xelatex (TeXLive 2012, Ubuntu 13.04) in RStudio (v0.98.312) and knitr using the configuration below:

    \documentclass{article}
    \usepackage{fontspec}
    \setmainfont{DejaVu Serif}
    \usepackage[unicode=true,bookmarks=true,bookmarksopen=true]{hyperref}
    \usepackage{xunicode}
    \begin{document}
    
    
    \section{Μέσες τιμές και 95\% Διαστήματα Εμπιστοσύνης}
    
    \subsection{a \% b cd}
    
    <<>>=
    1+1
    @
    
    \end{document}
    

    Output:

    percent in subsection title

    The document is UTF8 encoded. You probably need to tell hyperref the unicode option.