# LaTeX complaining commands in Verbatim

Known Fact:

With a Verbatim environment, every LaTeX commands will be handled as plain text. However, I need a working command in the Verbatim.

Objective:

I have a sample.cls file that will be \VerbatimInput to a main .tex file so that I can refer to later in the main file for explanations once it is read in. What follows is the code I used to input sample.cls

\fvset{frame=none,numbers=left,numbersep=3pt,firstline=1,lastline=20}
\VerbatimInput[commandchars=+]{sample.cls}


and an image after read in is shown below (The sample.cls is a makeshift here containing the following lines.)

For example, the block between line (9) and line (13) is what I am refering to. Notice that the label format I used in sample.cls are +label[vrb:test1] and +label[vrb:test2], which are not seen here due to being two control sequences in the Verbertim environment.

The referring scheme by inserting a command in the Verbatim structure works fine, but LaTeX complains those commands because they are embedded in the sample.cls that the main file needs (in use.)

In short the labels, +label[vrb:test1] and +label[vrb:test2], are equivalent to acting commands \label{vrb:test1} and \label{vrb:test1} in the Verbatim environment, but LaTeX renders errors.

Question:

Although hitting ENTER key can still finish the compilation, I am writing to seek help solving this dilemma (i.e., no need to hit ENTER key) and how to avoid these contradictions.

Error signal obtained, Window, TeXworks environment

60
LaTeX Error: Missing \begin{document}.

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

l.60 \setlength{\topmargin}{-0.5cm} +
label[vrb:psize1]
89
LaTeX Error: Missing \begin{document}.

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

l.89 +
label[vrb:cc]
175
LaTeX Error: Missing \begin{document}.

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

l.175 +
label[vrb:title1]


sample.cls

 \NeedsTeXFormat{LaTeX2e}
\ProvidesClass{sample}[Sample class]
%-------------------------- initial code -----------------------
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}
+label[vrb:test1]
%-------------------------- initial code -----------------------
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}
%-------------------------- executation ---------------------
\ProcessOptions\relax
+label[vrb:test2]
\endinput


Main file

 \documentclass[12pt]{sample}
\usepackage{fancyvrb}

\begin{document}

\fvset{frame=none,numbers=left,numbersep=3pt,firstline=1,lastline=20}
\VerbatimInput[commandchars=+]{sample.cls}
For example, the block between line (\ref{vrb:test1}) and line (\ref{vrb:test2}) is
what I am refering to.  Notice that the label format I used in sample.cls are +
label[vrb:test1] and + label[vrb:test2], which are not seen here due to being two
control sequences in Verbertim. environment.

\end{document}

• Can you include a bit of code that produces the error? Aug 23 '13 at 10:56
• @egreg The MWE does not run on sample.cls. But my problem is what I encountered today while trying to do the notions explained in the MWE. The error information is obtained from my actual case. Yes, it compiles with hittng enter key, but I hope to improve. Aug 23 '13 at 11:22
• @egreg I managed to produce the minimal sample.cls that generates the concerns I don't understand. Aug 23 '13 at 12:17
• @Jesse please add also a M(N)WE of the file you are compiling... Aug 23 '13 at 14:15
• @karlkoeller -- The source file is added. Aug 23 '13 at 14:48

I get no error from \VerbatimInput; but of course your class file is illegal and the error message

LaTeX Error: Missing \begin{document}.

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

l.60 \setlength{\topmargin}{-0.5cm} +
label[vrb:psize1]


is quite clear: when loading the class, + starts typesetting, which is disallowed for obvious reasons when classes or packages are being loaded.

You could obviate by hiding the label behind a comment character:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{sample}[Sample class]
%-------------------------- initial code -----------------------
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}} % +label[vrb:test1]
%-------------------------- initial code -----------------------
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}
%-------------------------- execution ---------------------
\ProcessOptions\relax

However, square brackets will not be printed because they will be considered like braces when the text is processed by \VerbatimInput.