Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
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
add comment

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.