Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Missing \begin{document}?

2,768 views
Skip to first unread message

Russ P.

unread,
Oct 25, 2011, 2:25:18 PM10/25/11
to
I've been using LaTeX for some 25 years, and I've had my share of
frustration, but this takes the cake. I couldn't get my LaTeX file to
"compile," so I tried stripping out stuff until I got down to this
minimal LaTeX file:

\documentclass[]{article}
\title{This is the Title}
\author{Arthur A. Author}
\begin{document}
\maketitle
\begin{abstract}
This is the abstract.
\end{abstract}
\section{Introduction}
This is the Introduction.
\end{document}

When I try to compile it, I get this:

prompt> latex test
This is pdfeTeX, Version 3.141592-1.21a-2.2 (Web2C 7.5.4)
entering extended mode
(./test.tex
LaTeX2e <2003/12/01>
Babel <v3.8d> and hyphenation patterns for american, french, german,
ngerman, b
ahasa, basque, bulgarian, catalan, croatian, czech, danish, dutch,
esperanto, e
stonian, finnish, greek, icelandic, irish, italian, latin, magyar,
norsk, polis
h, portuges, romanian, russian, serbian, slovak, slovene, spanish,
swedish, tur
kish, ukrainian, nohyphenation, loaded.

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...

l.1 �
��
?

The \begin{document} is there plain as day, so why is it not finding
it. Then if I type "H <return>" as instructed, I get this:

You're in trouble here. Try typing <return> to proceed.
If that doesn't work, type X <return> to quit.
?

Then if I hit return, it compiles. But it puts a blank page at the
beginning of the document.

Any idea what i going on here? Thanks.

--Russ P.

Herbert Schulz

unread,
Oct 25, 2011, 2:36:07 PM10/25/11
to
In article
<dbdb6e4a-2876-452f...@hv4g2000vbb.googlegroups.com>,
> ??
> ?
>
> The \begin{document} is there plain as day, so why is it not finding
> it. Then if I type "H <return>" as instructed, I get this:
>
> You're in trouble here. Try typing <return> to proceed.
> If that doesn't work, type X <return> to quit.
> ?
>
> Then if I hit return, it compiles. But it puts a blank page at the
> beginning of the document.
>
> Any idea what i going on here? Thanks.
>
> --Russ P.

Howdy,

Clean up the files from previous runs with errors. Especially the aux
file.

Good Luck,
Herb Schulz

Russ P.

unread,
Oct 25, 2011, 2:43:17 PM10/25/11
to
On Oct 25, 11:36 am, Herbert Schulz <he...@wideopenwest.com> wrote:
> In article
> <dbdb6e4a-2876-452f-af37-49ee9aca5...@hv4g2000vbb.googlegroups.com>,
Thanks for the suggestion. I just tried it, but I still get the same
result.

--Russ P.

Herbert Schulz

unread,
Oct 25, 2011, 3:22:07 PM10/25/11
to
In article
<041491f4-bcc0-4680...@k35g2000yqh.googlegroups.com>,
Howdy,

Just compiled your very simple sample with no problems. Are you sure you
deleted all the old files?

Good Luck,
Herb Schulz

Lee Rudolph

unread,
Oct 25, 2011, 3:35:33 PM10/25/11
to
"Russ P." <russ.paie...@gmail.com> wrote:

> I've been using LaTeX for some 25 years, and I've had my share of
> frustration, but this takes the cake. I couldn't get my LaTeX file to
> "compile," so I tried stripping out stuff until I got down to this
> minimal LaTeX file:
>
> \documentclass[]{article}
> \title{This is the Title}
> \author{Arthur A. Author}
> \begin{document}
> \maketitle
> \begin{abstract}
> This is the abstract.
> \end{abstract}
> \section{Introduction}
> This is the Introduction.
> \end{document}
...

I'm sure you've already checked what I'm about to
suggest, but since it's caught me a few times,
I'll suggest it anyway.

Have you actually *retyped* your minimal file
(and gotten the bad result)? When you say that
you "tried stripping out stuff", that leaves open
the possibility that you simply deleted lines from
the bad file. Now, *sometimes* (depending on what
editor I've been using) I have managed to get a
non-(screen-)printing character inserted in a
tex file, causing whatever command it happens
to be invisibly embedded in to malfunction,
and to keep malfunctioning until I figure out
that the same thing has happened again.
Could there be an invisible character somewhere
before "\begin{document}"?

Lee Rudolph

Peter Flynn

unread,
Oct 25, 2011, 3:48:10 PM10/25/11
to
A good point, and one I occasionally miss. One example is an editor in
XML mode may (validly) insert a BOM at the start of the document, which
could get copied and pasted if the data is transferred to another
environment. Another candidate would be a bogus ^Z (DOS EOF mark) left
by antique editors.

I'm still curious as to why anyone would want those empty square
brackets in the documentclass line, but that's a different question.

///Peter

Ahmed Musa

unread,
Oct 25, 2011, 3:32:31 PM10/25/11
to

Russ P.

unread,
Oct 25, 2011, 3:53:11 PM10/25/11
to
I have now removed every blank line and verified that there are no
extra invisible characters at the end of any line. I still get the
same result. I am completely baffled.

--Russ P.

jon

unread,
Oct 25, 2011, 4:00:30 PM10/25/11
to
now it might be time to try compiling other documents. from a
terminal, can you do (e.g.):

$ latex small2e

cheers,
jon.

Robin Fairbairns

unread,
Oct 25, 2011, 4:04:14 PM10/25/11
to
Peter Flynn <pe...@silmaril.ie> writes:

> [other attributions missing]
> A good point, and one I occasionally miss. One example is an editor in
> XML mode may (validly) insert a BOM at the start of the document,
> which could get copied and pasted if the data is transferred to
> another environment. Another candidate would be a bogus ^Z (DOS EOF
> mark) left by antique editors.

that would be my bet: an editor that doesn't know it's talking to an
"old" application. i've seen another instance that turned out to be a
bom causing this error. (if the op will report whether it all comes
right if the editor is set to produce iso 8859-1 (latin 1) or ascii, or
suchlike, i would be most grateful -- this issue is on my "watch list"
for the faq...).

> I'm still curious as to why anyone would want those empty square
> brackets in the documentclass line, but that's a different question.

started from editing a template document; that has the brackets in there
to remind its user of the possibility of class options, and no harm is
done if no options are needed.
--
Robin Fairbairns, Cambridge
my address is @cl.cam.ac.uk, regardless of the header. sorry about that.

Russ P.

unread,
Oct 25, 2011, 4:25:10 PM10/25/11
to
OK, just to be sure I'm not missing something obvious, I manually
typed this file into my emacs editor:

\documentclass{article}
\begin{document}
This is some text.
\end{document}

I still get the same basic result:

@etna ~/papers/mine/selfsep > latex test2
This is pdfeTeX, Version 3.141592-1.21a-2.2 (Web2C 7.5.4)
entering extended mode
(./test2.tex
LaTeX2e <2003/12/01>
Babel <v3.8d> and hyphenation patterns for american, french, german,
ngerman, b
ahasa, basque, bulgarian, catalan, croatian, czech, danish, dutch,
esperanto, e
stonian, finnish, greek, icelandic, irish, italian, latin, magyar,
norsk, polis
h, portuges, romanian, russian, serbian, slovak, slovene, spanish,
swedish, tur
kish, ukrainian, nohyphenation, loaded.

! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...

l.1 �
��\documentclass{article}
?

And when I type "H <return>" I get this:

You're in trouble here. Try typing <return> to proceed.
If that doesn't work, type X <return> to quit.
?

And when I type return again, it compiles, but I get a blank first
page.

I just tried recompiling one of my old LaTeX files, and it works fine.

I assume that my emacs editor is using ASCII, but I really know
nothing about that.

--Russ P.

Dan Luecking

unread,
Oct 25, 2011, 5:00:11 PM10/25/11
to
On Tue, 25 Oct 2011 11:25:18 -0700 (PDT), "Russ P."
<russ.p...@gmail.com> wrote:

>I've been using LaTeX for some 25 years, and I've had my share of
>frustration, but this takes the cake. I couldn't get my LaTeX file to
>"compile," so I tried stripping out stuff until I got down to this
>minimal LaTeX file:
>
>\documentclass[]{article}
>\title{This is the Title}
>\author{Arthur A. Author}
>\begin{document}
>\maketitle
>\begin{abstract}
>This is the abstract.
>\end{abstract}
>\section{Introduction}
>This is the Introduction.
>\end{document}
>
>When I try to compile it, I get this:
>
>prompt> latex test
...
>! LaTeX Error: Missing \begin{document}.
>
>See the LaTeX manual or LaTeX Companion for explanation.
>Type H <return> for immediate help.
> ...
>
>l.1 ?
> ??

This error message indicates a non-ASCII triplet
of bytes occuring on line 1 (and nothing else on
that line). I don't know why they are there nor why you
can't detect them, but others might be able to help
if you explain how you edit and save your files.

>?
>
> The \begin{document} is there plain as day, so why is it not finding
>it.

It never got that far before encountering this error. In fact,
this error message is somewhat misleading. What has actually
happened is LaTeX has encountered the start of a paragraph
without having encountered \begin{document}.

> Then if I type "H <return>" as instructed, I get this:
>
>You're in trouble here. Try typing <return> to proceed.
>If that doesn't work, type X <return> to quit.
>?

LaTeX could use a better help message here, but there are
too many reasons for this error to give more than a
general statement.

>
>Then if I hit return, it compiles. But it puts a blank page at the
>beginning of the document.

Those non-ASCII bytes started a paragraph, but print nothing,
probably because the default fonts have no characters in those
positions. After that, \begin{document} issues a \clearpage, whence
the blank page.


Dan
To reply by email, change LookInSig to luecking

Dan Luecking

unread,
Oct 25, 2011, 5:05:58 PM10/25/11
to
On Tue, 25 Oct 2011 12:53:11 -0700 (PDT), "Russ P."
<russ.p...@gmail.com> wrote:

>On Oct 25, 12:35 pm, Lee Rudolph <lrudo...@panix.com> wrote:
>> "Russ P." <russ.paie...@gmail.com> wrote:
[...]
>>
>> Have you actually *retyped* your minimal file
>> (and gotten the bad result)?  When you say that
>> you "tried stripping out stuff", that leaves open
>> the possibility that you simply deleted lines from
>> the bad file.  Now, *sometimes* (depending on what
>> editor I've been using) I have managed to get a
>> non-(screen-)printing character inserted in a
>> tex file, causing whatever command it happens
>> to be invisibly embedded in to malfunction,
>> and to keep malfunctioning until I figure out
>> that the same thing has happened again.
>> Could there be an invisible character somewhere
>> before "\begin{document}"?
>>
>> Lee Rudolph
>
>I have now removed every blank line and verified that there are no
>extra invisible characters at the end of any line. I still get the
>same result. I am completely baffled.

They were at the beginning of line 1. It's just a guess
but could emacs be inserting some sort of byte sequence as
a file type identifier upon saving? If that is the case,
you might not actually be there until saved to disk. Perhaps
emacs needs to be reconfigured. You probably have another
editor you could open the file in. That might show these bytes.

Heiko Oberdiek

unread,
Oct 25, 2011, 5:14:11 PM10/25/11
to
"Russ P." <russ.p...@gmail.com> wrote:

> On Oct 25, 1:04 pm, Robin Fairbairns <r...@cl.cam.ac.uk> wrote:
> > Peter Flynn <pe...@silmaril.ie> writes:
> > > [other attributions missing]
> > > A good point, and one I occasionally miss. One example is an editor in
> > > XML mode may (validly) insert a BOM at the start of the document,
> > > which could get copied and pasted if the data is transferred to
> > > another environment. Another candidate would be a bogus ^Z (DOS EOF
> > > mark) left by antique editors.
> >
> > that would be my bet: an editor that doesn't know it's talking to an
> > "old" application.  i've seen another instance that turned out to be a
> > bom causing this error.

> OK, just to be sure I'm not missing something obvious, I manually
> typed this file into my emacs editor:
>
> \documentclass{article}
> \begin{document}
> This is some text.
> \end{document}
>
> I still get the same basic result:

> ! LaTeX Error: Missing \begin{document}.

> l.1 ?
> ??\documentclass{article}
> ?

> I just tried recompiling one of my old LaTeX files, and it works fine.
>
> I assume that my emacs editor is using ASCII, but I really know
> nothing about that.

The error message is *before* \documentclass, but in the same line.
That's the classical case that the editor has used encoding UTF-8 and
added a superfluous Byte Order Mark (=BOM) at the beginning of the
file. The Byte Order Mark makes sense for UTF16 or UTF32, but it
doesn't for UTF-8. You can verify that with a hex editor/viewer:
In UTF-8 the BOM has three bytes as hex numbers: EF BB BF.
Example using "hexdump -C":

00000000 ef bb bf 5c 64 6f 63 75 6d 65 6e 74 63 6c 61 73
|\documentclas|
00000010 73 7b 61 72 74 69 63 6c 65 7d 0a 5c 62 65 67 69
|s{article}.\begi|
...

In
http://stackoverflow.com/questions/3859274/removing-byte-order-marks-boms-using-emacs
is shown, how to remove the BOM by changing the encoding from
"utf-8-with-signature" to plain "utf-8".

--
Heiko Oberdiek

Russ P.

unread,
Oct 25, 2011, 5:41:15 PM10/25/11
to
On Oct 25, 2:14 pm, Heiko Oberdiek <heiko.oberd...@googlemail.com>
wrote:
> |\documentclas|
> 00000010  73 7b 61 72 74 69 63 6c  65 7d 0a 5c 62 65 67 69
> |s{article}.\begi|
> ...
>
> Inhttp://stackoverflow.com/questions/3859274/removing-byte-order-marks-...
> is shown, how to remove the BOM by changing the encoding from
> "utf-8-with-signature" to plain "utf-8".
>
> --
> Heiko Oberdiek

Wow! Thanks so much! What a godawful waste of time that was.

I am wondering (1) why I've never had to do that before, and (2) if I
will have to do it every time I open a LaTeX file in emacs from now
on.

--Russ P.

Russ P.

unread,
Oct 25, 2011, 5:52:31 PM10/25/11
to
On Oct 25, 2:14 pm, Heiko Oberdiek <heiko.oberd...@googlemail.com>
wrote:
> |\documentclas|
> 00000010  73 7b 61 72 74 69 63 6c  65 7d 0a 5c 62 65 67 69
> |s{article}.\begi|
> ...
>
> Inhttp://stackoverflow.com/questions/3859274/removing-byte-order-marks-...
> is shown, how to remove the BOM by changing the encoding from
> "utf-8-with-signature" to plain "utf-8".
>
> --
> Heiko Oberdiek

That worked. Thanks. What a waste of time that was.

I am wondering (1) why I have never encountered this problem before,
and (2) if I will now have to do this every time I open a LaTeX file
in emacs.

--Russ P.

(My first attempt to send this message apparently failed, so my
apology if this is a repeat.)

Herbert Schulz

unread,
Oct 25, 2011, 6:22:29 PM10/25/11
to
In article
<76ad5ae7-df7c-471d...@p20g2000prm.googlegroups.com>,
Howdy,

Did you save the file as UTF-8 with BOM? The Byte Order Marker is a set
of ``invisible'' characters that TeX doesn't understand.

Good Luck,
Herb Schulz

Russ P.

unread,
Oct 25, 2011, 6:32:23 PM10/25/11
to
On Oct 25, 3:22 pm, Herbert Schulz <he...@wideopenwest.com> wrote:
> In article
> <76ad5ae7-df7c-471d-a19d-e988a481f...@p20g2000prm.googlegroups.com>,
No. How do I do that?

Philipp Stephani

unread,
Oct 25, 2011, 6:49:23 PM10/25/11
to
"Russ P." <russ.p...@gmail.com> writes:

> Wow! Thanks so much! What a godawful waste of time that was.
>
> I am wondering (1) why I've never had to do that before, and (2) if I
> will have to do it every time I open a LaTeX file in emacs from now
> on.

Emacs never uses utf-8-with-signature by default. Either you selected
it manually, or there is a configuration option that selects it.

--
Change “LookInSig” to “tcalveu” to answer by mail.

Robin Fairbairns

unread,
Oct 26, 2011, 6:26:30 AM10/26/11
to
Heiko Oberdiek <heiko.o...@googlemail.com> writes:

> "Russ P." <russ.p...@gmail.com> wrote:
>> I still get the same basic result:
>>
>> ! LaTeX Error: Missing \begin{document}.
>>
>> l.1 ?
>> ??\documentclass{article}
>> ?
>
> The error message is *before* \documentclass, but in the same line.
> That's the classical case that the editor has used encoding UTF-8 and
> added a superfluous Byte Order Mark (=BOM) at the beginning of the
> file. The Byte Order Mark makes sense for UTF16 or UTF32, but it
> doesn't for UTF-8. You can verify that with a hex editor/viewer:
> In UTF-8 the BOM has three bytes as hex numbers: EF BB BF.
> Example using "hexdump -C":
>
> 00000000 ef bb bf 5c 64 6f 63 75 6d 65 6e 74 63 6c 61 73
> |\documentclas|
> 00000010 73 7b 61 72 74 69 63 6c 65 7d 0a 5c 62 65 67 69
> |s{article}.\begi|
> ...
>
> In
> http://stackoverflow.com/questions/3859274/removing-byte-order-marks-boms-using-emacs
> is shown, how to remove the BOM by changing the encoding from
> "utf-8-with-signature" to plain "utf-8".

thanks for that, heiko; i've turned it into an answer for the next
release of the uk faq, which is due soon (the changes log is too
big for me to delay much...)

Peter Flynn

unread,
Oct 26, 2011, 5:06:37 PM10/26/11
to
On 25/10/11 23:32, Russ P. wrote:
> On Oct 25, 3:22�pm, Herbert Schulz<he...@wideopenwest.com> wrote:
>> In article
[...]
>> Did you save the file as UTF-8 with BOM? The Byte Order Marker is a set
>> of ``invisible'' characters that TeX doesn't understand.
>>
>> Good Luck,
>> Herb Schulz
>
> No. How do I do that?

In Emacs, type M-x hexl-mode RET to switch to HEX mode. You should then
be able to see the BOM characters (and get rid of them). Type M-x
latex-mode RET to go back to normal editing.

///Peter

my name

unread,
Aug 4, 2014, 12:19:24 PM8/4/14
to
Try to open the .tex file with the MS Word and remove any character that you may find before \documentclass...

That worked for me.

Still one or two black pages before the actual content in the compiled document.

C.
0 new messages