I want my Java code to be typeset in a monospaced font, so I am using the verbatim environment. LaTeX commands are highlighted in Eclipse, but as soon as I use the verbatim environment everything inside and the color of the environment itself becomes gray.


 public class main {
 public static void main (string[] args){
     for(int i = 0; i < arg.length; i ++){


I'm using the verbatim and alltt packages.

Update 1. MWE.



% Поддержка русского языка











\begin{frame}{Классификация по поколениям}


\item Третьего поколения (высокоуровневые языки) - последовательность
высокоуровневых конструкций (циклы, условные выражения, классы, интерфейсы,
методы, процедуры, \ldots) \pause



Fortran, C, C++, C\#, Java, Lisp.


public class main {
public statiс void main (string[] args){
for(int i = 0; i < arg.length; i ++){




\item Четвертого поколения (для конкретного применения) -
последовательность инструкций конкретной предметной области \pause

SQL, Postscript, XML, Mathlab.
\end{exampleblock} \pause



  • 2
    Welcome to TeX.SX! Personally, I would expect this behavior. There is nothing telling eclipse that what's inside is java code—frankly I would be surprised if it handled that case even with a package such as listings. I'm not sure there is a way to get the behavior you want. Feb 19, 2014 at 6:12
  • As a hint, in a beamer presentation you can use semiverbatim, so you can use overlays and the like.
    – Johannes_B
    Feb 19, 2014 at 7:34
  • 3
    If you want to use verbatim in a frame, you have to use \begin{frame}[fragile]
    – egreg
    Feb 19, 2014 at 9:28
  • 1
    That's not a minimal example - you forgot the everything-but-the-kitchen-sink package. Feb 19, 2014 at 16:06
  • 1
    Please read the fine beamer manual; it has a section on verbatim. Feb 19, 2014 at 16:08

1 Answer 1


You cannot use any of the verbatim environments, including verbatim itself, just as any of the listing environment without writing,


or any other form of passing the fragile flag to the \frame command. If the frame does not include any overlays, i.e., it has only a single slide, it is recommended to write:

  • Note that adding the [fragile] option breaks pdfsync (synctex) on the frames to which it is added. See tex.stackexchange.com/a/458467/153737.
    – Glenn
    Feb 2, 2021 at 18:01
  • it worked in my case as well
    – BZKN
    Jan 20 at 11:32

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