General"Missing \begin{document}"error but \begin{document} present

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
oceane
Posts: 1
Joined: Fri Dec 19, 2008 10:51 am

"Missing \begin{document}"error but \begin{document} present

Post by oceane »

Hello everyone!
I'm trying to use pdflatex with Sweave. This convert a rnw file in tex file. After that you just have to use "pdflatex" and you have your pdf file.
Every time I'm compiling I've got the same error message "Missing \begin{document}" but I've write this in my file !
Here's the begining of it :

Code: Select all

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{color, pdfcolmk}

\usepackage{C:/PROGRA~1/R/R-27~1.1/share/texmf/Sweave}
\begin{document}
\DefineVerbatimEnvironment{Sinput}{Verbatim}{formatcom = {\color[rgb]{0, 0, 0.56}}}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{formatcom = {\color[rgb]{0.56, 0, 0}}}

\setkeys{Gin}{width=0.8\textwidth}

\title{Dynamique de population de l'espèce Dauphin commun}
\author{CRMM}

\maketitle

\section{Fonction de mortalite }

\underline{ Présentation des données : }
Les échouages se répartissent de la façon suivante : 
Thanks a lot for your help

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

"Missing \begin{document}"error but \begin{document} present

Post by phi »

Where exactly (file, line) does the error occur? If applicable, post some excerpt of your log file. "Missing \begin{document}" means that something in your preamble tries to typeset text. The \usepackage command is a bit strange here, but seems to be correct according to the manual.
daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Re: "Missing \begin{document}"error but \begin{document} present

Post by daleif »

could the tildes be the problem? in the call for sweave?
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

"Missing \begin{document}"error but \begin{document} present

Post by phi »

this is indeed possible, the tilde is active and gets expanded by \@@input. But there are unexpandable tokens in the expansion (e.g. \relax, because \nobreakspace is robust), so TeX thinks the filename is finished and tries to typeset the rest. Try this:

Code: Select all

\usepackage{\detokenize{C:/PROGRA~1/R/R-27~1.1/share/texmf/Sweave}}
or/and use the real (quoted) path instead of the 8.3 path
User avatar
T3.
Posts: 208
Joined: Fri Mar 14, 2008 12:58 pm

"Missing \begin{document}"error but \begin{document} present

Post by T3. »

In case the problem comes from the tilde character, try the following hack (MiKTeX assumed):

Code: Select all

%& -include-directory=C:/PROGRA~1/R/R-27~1.1/share/texmf
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{color, pdfcolmk}

\usepackage{Sweave}
\begin{document}
Cheers,

Tomek
Post Reply