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?

2
  • 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 ;-)
    – user31729
    Commented Feb 22, 2015 at 2:37
  • @ChristianHupfer, I'll try.
    – Özgür
    Commented Feb 22, 2015 at 2:42

1 Answer 1

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

3
  • if \chapter{Özgür} like not working. Do you check it? @Gonzalo Medina.
    – Özgür
    Commented Feb 22, 2015 at 4:33
  • @Özgür for an explanation and possible solutions, please see tex.stackexchange.com/q/24528/3954 Commented Feb 22, 2015 at 4:41
  • It is OK, working @Gonzalo Medina.
    – Özgür
    Commented Feb 22, 2015 at 5:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .