2

I'm creating a document in LaTeX with the bibliography in a separated BibTeX file.

When I compile the document without any reference to the bibliography it runs correctly, but when I add references to the bibliography it sends the following error.

! You can't use `the character 1' after \the.

I was making some tests and when I remove the tikzpicture, the whole file compiles correctly, including the bibliography. But when I add the picture again, I get the same error.

The following code is a sample with the image that triggers the error.

\documentclass[openany]{book}
\usepackage[utf8]{inputenc} 
%Si se activa no funcionan algunos gráficos
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{circuitikz}
\usepackage{amsmath}

\usetikzlibrary{positioning,shadows,backgrounds}
\usetikzlibrary{positioning,shadows,backgrounds,arrows,intersections}
\usepackage{cite}
\usepackage{float}
\usepackage{venndiagram}
\usepackage{amssymb}
\usepackage{amsfonts}

\usepackage{pgf}
\usetikzlibrary{arrows,automata}
\usepackage{verbatim}



\usepackage[left=2cm,right=2cm, top=2.5cm, bottom=2.5cm]{geometry}
\usetikzlibrary{decorations.pathmorphing,patterns}
\usetikzlibrary{trees}
%\setlength\parindent{0pt}
\usepackage{cancel}

\setcounter{secnumdepth}{3} %para que ponga 1.1.1.1 en subsubsecciones
\setcounter{tocdepth}{3} % para que ponga subsubsecciones en el indice

\usepackage{titlesec}

\graphicspath{ {imagenes/} }

\titleformat
{\chapter} % command
[display] % shape
{\bfseries\Large\itshape} % format
{}
%{Story No. \ \thechapter} % label
{0.5ex} % sep
{
    \rule{\textwidth}{1pt}
    \vspace{1ex}
    \centering
} % before-code
[
\vspace{-0.5ex}%
\rule{\textwidth}{0.3pt}
] % after-code

\setlength{\parskip}{1ex}


\begin{document}

\title{Apuntes y Tareas de Probabilidad.}
\author{Luis Alejandro Barranco Ju\'arez}


\maketitle

%\begin{titlepage}
%\begin{center}
%\begin{Huge}
%\textsc{Apuntes y Tareas.}
%\end{Huge}
%\end{center}
%\end{titlepage}

\pagenumbering{roman}

\tableofcontents % indice de contenidos

\newpage

\pagenumbering{arabic}

\chapter{Tarea 1} 
\markboth{TAREA 1}{TAREA 1}

\section{Tri\'angulos de Pascal.}   

\begin{tikzpicture}[x=13mm,y=9mm]
    % some colors
    \colorlet{even}{cyan!60!black}
    \colorlet{odd}{orange!100!black}
    \colorlet{links}{red!70!black}
    \colorlet{back}{yellow!20!white}
    % some styles
    \tikzset{
            box/.style={
            minimum height=5mm,
            inner sep=.7mm,
            outer sep=0mm,
            text width=10mm,
            text centered,
            font=\small\bfseries\sffamily,
            text=#1!50!black,
            draw=#1,
            line width=.25mm,
            top color=#1!5,
            bottom color=#1!40,
            shading angle=0,
            rounded corners=2.3mm,
            drop shadow={fill=#1!40!gray,fill opacity=.8},
            rotate=0,
            },
            link/.style={-latex,links,line width=.3mm},
            plus/.style={text=links,font=\footnotesize\bfseries\sffamily},
    }
    % Pascal's triangle
    % row #0 => value is 1
    \node[box=odd] (p-0-0) at (0,0) {1};
    \foreach \row in {1,...,16} {
     % col #0 => value is 1
            \node[box=odd] (p-\row-0) at (-\row/2,-\row) {1};
            \pgfmathsetmacro{\value}{1};
            \foreach \col in {1,...,\row} {
        % iterative formula : val = precval * (row-col+1)/col
        % (+ 0.5 to bypass rounding errors)
            \pgfmathtruncatemacro{\value}{\value*((\row-\col+1)/\col)+0.5};
            \global\let\value=\value
            % position of each value
            \coordinate (pos) at (-\row/2+\col,-\row);
            % odd color for odd value and even color for even value
            \pgfmathtruncatemacro{\rest}{mod(\value,5)}
            \ifnum \rest=0
                    \node[box=even] (p-\row-\col) at (pos) {\value};
            \else
                    \node[box=odd] (p-\row-\col) at (pos) {\value};
            \fi
      % for arrows and plus sign
%      \ifnum \col<\row
%        \node[plus,above=0mm of p-\row-\col]{+};
%        \pgfmathtruncatemacro{\prow}{\row-1}
%        \pgfmathtruncatemacro{\pcol}{\col-1}
%        \draw[link] (p-\prow-\pcol) -- (p-\row-\col);
%        \draw[link] ( p-\prow-\col) -- (p-\row-\col);
%      \fi
            }
    }
    \begin{pgfonlayer}{background}
            % filling and drawing with the same color to enlarge background
            \path[draw=back,fill=back,line width=5mm,rounded corners=2.5mm]
            (  p-0-0.north west) -- (  p-0-0.north east) --
            (p-16-16.north east) -- (p-16-16.south east) --
            ( p-16-0.south west) -- ( p-16-0.north west) --
            cycle;
    \end{pgfonlayer}
    \end{tikzpicture}

    Para n=5.

    \cite{Polya}

\addcontentsline{toc}{chapter}{Bibliografía}
\bibliographystyle{acm} % estilo de la bibliografía.
\bibliography{prueba} % biblio.bib es el fichero donde está salvada la bibliografía.

\end{document}

My .bib file looks like this:

@book{Polya,
author    = "G.Polya",
title     = "How to Solve It",
publisher = "Princeton University Press",
year      = "1957",
}

What is causing this problem?

  • 2
    Please make your code snippet compilable! Then we can copy your code and test on our own computers ... Welcome to TeX.SE! – Mensch Jun 15 '16 at 21:32
  • Thank you, I have modified the post with a sample of my code with the elements that are not compiling correctly. – labj86 Jun 15 '16 at 21:58
  • Thank you, I have run the code for the tikz picture and it works fine, but when I add the link to the bibliography, the file doesn't compile. – labj86 Jun 15 '16 at 23:10
  • 1
    Have you checked the log files for warnings? If there are warnings check all of them! They can cause/explain the problem. Add the tikz code only if it is error and warning free ... – Mensch Jun 15 '16 at 23:14
  • Please consider minimising your code. If you have a really simple picture, does the problem still occur? Does it go away if you don't load cancel? If not, you don't need cancel in the example. You should also consider cleaning up your preamble for your own sake. You have a lot of redundant stuff there which will only make troubleshooting harder. – cfr Jun 15 '16 at 23:58
2

Thoughtless use of \def, \let, \global etc. costs lives.

Well, they waste time, anyway, and if you waste enough of that, that's a life gone.


You have overridden TeX's definition of \value and made this redefinition global by saying

\global\let\value=\value

TeX is, therefore, unable to do anything which depends on \value after this point in the document. The citation is just collateral damage.

Here's a not minimal, but at least more minimal, example which reproduces the error:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\ifnum\value{page}=1 hi\else bye\fi

\begin{tikzpicture}
  \foreach \row in {1,...,16} {
    \pgfmathsetmacro{\value}{1}
    \foreach \col in {1,...,\row} {
      \pgfmathtruncatemacro{\value}{\value*((\row-\col+1)/\col)+0.5};
      \global\let\value=\value
    }
  }
\end{tikzpicture}

\ifnum\value{page}=1 hi\else bye\fi
\end{document}

The problem can be addressed by ensuring that new macro names do not overwrite existing ones. In this case, substituting \myvalue for \value will work.

Using \newcommand*\value{1} rather than \pgfmathsetmacro{\value}{1} would have provided an informative error message explaining the problem.

|improve this answer|||||
  • Thank you very much, this helped me to solve the problem. – labj86 Jun 17 '16 at 19:26
  • @labj86 Croeso! (You're welcome!) – cfr Jun 17 '16 at 20:54

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.