2

Known Fact:

Have read this LaTeX complaining about illegal parameter number

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.)

enter image description here

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
 \LoadClass[a4paper,openright]{report}  
 +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}
Jesse
  • 29,686
  • 1
    Can you include a bit of code that produces the error? – egreg 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. – Jesse Aug 23 '13 at 11:22
  • @egreg I managed to produce the minimal sample.cls that generates the concerns I don't understand. – Jesse Aug 23 '13 at 12:17
  • @Jesse please add also a M(N)WE of the file you are compiling... – karlkoeller Aug 23 '13 at 14:15
  • @karlkoeller -- The source file is added. – Jesse Aug 23 '13 at 14:48

1 Answers1

1

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
\LoadClass[a4paper,openright]{report}  % +label[vrb:test2]
\endinput

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

egreg
  • 1,121,712
  • I was blinded by the impression that everything behind % is ignored. This case shows that the command +\label[xxx] is still valid even behind % in the Verbatim environment. Nice trick. – Jesse Aug 23 '13 at 15:07