views:

473

answers:

3

Why is this not working:

\documentclass[a4paper,10pt]{article}
\usepackage{a4wide}
\usepackage[T1]{fontenc}
\usepackage[portuguese]{babel}
\usepackage[latin1]{inputenc}
\usepackage{indentfirst}
\usepackage{listings}
\usepackage{fancyhdr}
\usepackage{url}
\usepackage[compat2,a4paper,left=25mm,right=25mm,bottom=15mm,top=20mm]{geometry}
\usepackage{color}
\usepackage[colorlinks]{hyperref}
\usepackage[pdftex]{graphicx}

\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}

\pagestyle{fancy}

\fancyhead[L]{\small Laboratórios de Informática III}
\fancyhead[R]{\small Projecto 1 (Linguagem \textsf{C})}

\lstset{
    basicstyle=\ttfamily\footnotesize,
    showstringspaces=false,
    frame=single,
    tabsize=4,
    breaklines=true,

}

\definecolor{Section1}{rgb}{0.09,0.21,0.36}
\definecolor{Section2}{rgb}{0.21,0.37,0.56}
\definecolor{Section3}{rgb}{0.30,0.50,0.74}

\hypersetup{
    bookmarks=false,
    linkcolor=red,
    urlcolor=cyan,
}

\renewcommand{\section}[1]{\texorpdfstring{\color{green}#1}{#1}}

\parskip=6pt

\begin{document}

\begin{titlepage}

\begin{center}

\includegraphics[width=5cm]{./logo.jpg}\\[1cm]

\textsc{\LARGE Universidade do Minho}\\[1cm]

\textsc{\large Licenciatura em Engenharia Informática\\Laboratórios de Informática III}\\[1.5cm]

\rule{\linewidth}{0.5mm}\\[0.4cm]

\huge{\textbf{\textsc{Relatório do Projecto 1 (Linguagem C)}}}

\rule{\linewidth}{0.5mm}

\vfill

\begin{tabular}{c c}

    \includegraphics[width=3.5cm]{./nuno.jpg} & \includegraphics[width=3.5cm]{./ricardo.jpg} \\

    \textsc{\large{Nuno Mendes (51161)}} & \textsc{\large{Ricardo Amaral (48404)}} \\

\end{tabular}

\vfill

\large{\today}

\end{center}

\end{titlepage}

\tableofcontents

\newpage

\section{Introdução}

Lorem ipsum...

\newpage

\appendix

\section{\color{Section1}Diagrama das Estruturas de Dados}

\begin{center}
\includegraphics[width=16cm]{./Diagrama.pdf}
\end{center}

\end{document}

! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ...

                                               l.2 ...rline {1}\color

{green}Teste}{3}{section.1}

How can I make it work properly?

A: 

I inserted your \renewcommand into one of my LaTeX files and it worked fine, though I have questions about your aesthetic choices. This leads me to think that your error arises when you use the redefined macro. But your question does not really show us that. Or, that the error occurs before your use of the macro but that LaTeX doesn't notice until it executes the macro and fails.

EDIT: OK, I copied your text into an empty document and tried to process it. My system complained about

\lstset{
basicstyle=\ttfamily\footnotesize,
showstringspaces=false,
frame=single,
tabsize=4,
breaklines=true,

}

which does not finish properly -- the comma in breaklines=true, is misplaced. However once I had removed that comma and commented out the \includegraphics statements the file was processed without complaint. This reinforces my belief that the error is not in our renewcommand macro.

High Performance Mark
I only use it like this on my code: \section{Teste}
Nazgulled
In that case the error perhaps occurs elsewhere. I suggest you create a tiny LaTeX document to just check that the macro works.
High Performance Mark
Updated question with "full" example.
Nazgulled
Actually, the renewcommand is not as it should be, on a minimal page (so that the renewcommand works) the TOC is not correctly generated. At least the way I tested it.
Nazgulled
A: 

You should try to condense your code down to a minimal example, then either you're getting to your error yourself or we can help you a bit better. i don't think that all the code above is necessary.

Habi
I agree........
High Performance Mark
changing your lstset to \lstset{ basicstyle=\ttfamily\footnotesize, showstringspaces=false, frame=single, tabsize=4, breaklines=true}makes it compilable for me...
Habi
well, i can't seem to be able to post code-snippets in comments.remove the blank line in your \lststed-block and then your document compiles for me (after I removed all the references to non-existent images and made sure my MacTex can work with your spanish chars...)
Habi
It doesn't compile for me and the empty line was a copy/paste problem, my code didn't have that empty line. But read my "answer" below. Thanks anyway.
Nazgulled
A: 

This was for a project report already delivered and I'm not going to bother with it anymore, at least for now cause I have more important things to deal with at the moment.

I "fixed" it by using \newcommand instead and created my own commands to replace \section, \subsection and it was basically a case of find/replace. It's not the best solution as I like to use whatever is there already and configure it accordingly, but it will do for now...

I'll revisit this problem in the future if I need too. I appreciate everyone's input.

Nazgulled