2

MWE,

\documentclass[a4paper,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\title{}
\author{}
\begin{document}
\maketitle
\tableofcontents
\chapter{}
\end{document}

that I want

enter image description here

in verbatim. Always gets Can be used only in preamble. Is there a basic solve?

Özgür
  • 3,270
  • 1
    You wan't listings or something like that. You can't use a 2nd \documentclass in your document (at least not without much struggling ;-) –  Feb 22 '15 at 02:37
  • @ChristianHupfer, I'll try. – Özgür Feb 22 '15 at 02:42

1 Answers1

3

You can use the listings package; here's a little example:

\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}

\definecolor{maincs}{RGB}{177,0,39}
\definecolor{secondarycs}{RGB}{255,179,246}
\definecolor{tertiarycs}{RGB}{0,149,86}

\lstset{
  language=[LaTeX]TeX,
  basicstyle=\ttfamily\small,
  columns=fullflexible,
  breaklines=true,
  texcsstyle=*\color{maincs},
  texcs={documentclass,begin,end,chapter},
  moretexcs=[2]{usepackage},
  texcsstyle=*[2]{\color{secondarycs!80!black}},
  moretexcs=[3]{maketitle,title,author,tableofcontents},
  texcsstyle=*[3]{\color{tertiarycs}}
}

\begin{document}

\begin{lstlisting}
\documentclass[a4paper,11pt]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\title{}
\author{}
\begin{document}
\maketitle
\tableofcontents
\chapter{}
\end{document}
\end{lstlisting}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128