2

When I execute the following code, I get a nice .pdf as a Result:

\documentclass{minimal}
\usepackage{fancyvrb}
\begin{document}
\begin{Verbatim}
sdfsdfs
\end{Verbatim} 
\end{document}

PDF_OUTPUT

Below is the Same Code with Some Comments Added Using %

\documentclass{minimal}
\usepackage{fancyvrb}
\begin{document}
\begin{Verbatim} % Upper case `V` references package{fancyvrb}
sdfsdfs
\end{Verbatim} % Upper case `V` references package{fancyvrb}
\end{document}

After Comments are Added, I Get the Following Error Message:

[Loading MPS to PDF converter (version 2006.09.02).]
)
! FancyVerb Error:
  Extraneous input `sdfsdfs' between \begin{Verbatim}[<key=value>] and line end

.
\FV@Error ... {FancyVerb Error:
\space \space #1
}

l.5 sdfsdfs

I tried doing a make clean (delete all temp .aux files, .gz, .synctex, etc...

Below are Descriptions of the Software I am Using:

tex_works_version_image miktex_version_image

      --------------------------------------------------
      |                   `fancyvrb'                   |
      |                  Version 3.1                   |
      |                  Nov 17, 2018                  |
      |                                                |
      | Timothy Van Zandt (Princeton University - USA) |
      |                                                |
      |     Packaging, documentation and support       |
      |       Denis Girou (CNRS/IDRIS - France)        |
      |            <Denis.Girou@idris.fr>              |
      |        Sebastian Rahtz (Elsevier - GB)         |
      |       Herbert Voss, Berlin (hvoss@tug.org)     |
       --------------------------------------------------


--- fancyvrb.sty
3.1a 2018/11/20   - small changes to the documentation (hv)  
3.1  2018/11/17   - load package xcolor only if it is not done already (hv)  
3.0  2018/11/01   - remove the example part from francyvrb (hv)  
[etc...]

--- fancyvrb-ex.sty
0.01 2018/11/01  - first CTAN version
  • 5
    Welcome to TeX.SX! The error log already gives the answer: Extraneous input `sdfsdfs' between \begin{Verbatim}[<key=value>] and line end. You have extra code added after the \begin{Verbatim} command which is not allowed. Moving the comment one line up should fix the problem (and perhaps a similar solution for the \end{Verbatim} is needed). – siracusa Jan 10 at 20:33
  • 2
    @Guido are you sure? (I tried that and it didn't work for me, and I don't see that documented?) – David Carlisle Jan 10 at 20:49
  • 1
    Just for future reference: The version of your editor (TeXworks) is usually not relevant for issues like this. More often that not the MikTeX version is also not relevant. Package versions are more interesting. A very clean solution to show all involved package versions is by adding \listfiles to the top of your MWE and copying the file list at the end of the .log file. That saves you hunting down all .stys and including their headers. – moewe Jan 10 at 21:05
  • LaTeX is the first language I have ever encountered where comments are not always ignored. It was a very disconcerting experience. I see now that a verbatim environment turns ALL language keywords, etc... including the begin-comment command %, into mere string characters. – IdleCustard Jan 11 at 1:27
  • 3
    @IdleCustard that is why you almost always need a full document example in a question and a fragment is not so helpful, latex is completely context sensitive, no characters have fixed syntax it does not have to be \ to delimit commands or { } to delimit arguments, all such character settings can be changed at any point. However many languages have an equivalent to verbatim eg xml/html has <![CDATA[...]]> inside which comment syntax <!-- ... --> is not a comment but just text. – David Carlisle Jan 11 at 1:39
5

You get an error for text on that line irrespective of whether it is a comment.

\documentclass{minimal}
\usepackage{fancyvrb}
\begin{document}
\begin{Verbatim} xxx
sdfsdfs
\end{Verbatim} 
\end{document}

Turning comments in to non-comments is more or less the main feature of a verbatim environment, the whole point of such an environment is that special characters like % just become normal characters that typeset as themselves and not acting with their usual special behaviours.

  • I see! The % [blah blah blah] is actually inside of the \verb block. The comment began AFTER the \begin statement! – IdleCustard Jan 11 at 1:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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