[Tex/LaTex] Tikzexternalize not compatible with Miktex 2.9 abntex2 package

abntmiktextexlipsetikz-pgf

The folowing code works correctly inside Texlipse together with Miktex 2.9 x64.
The tikzexternalize option is used to speed up the compilation process, just make sure the shell-escape mode is enables exclicitly passing the -shell-escape argument to the compiler.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize[prefix=figures/]

\begin{document}

\begin{tikzpicture}
\node[draw, circle, minimum width=1cm] {};
\end{tikzpicture}   

\end{document}

Now, when the article class is replaced by the abntex2 class as the following code, the pdf file is not generated inside figures folder any longer.

\documentclass[
    % -- opções da classe memoir --
    12pt,               % tamanho da fonte
    openright,          % capítulos começam em pág ímpar (insere página vazia caso
    % preciso)
    twoside,            % para impressão em verso e anverso. Oposto a oneside
    a4paper,            % tamanho do papel.
    % -- opções da classe abntex2 --
    %chapter=TITLE,     % títulos de capítulos convertidos em letras maiúsculas
    %section=TITLE,     % títulos de seções convertidos em letras maiúsculas
    %subsection=TITLE,  % títulos de subseções convertidos em letras maiúsculas
    %subsubsection=TITLE,% títulos de subsubseções convertidos em letras maiúsculas
    % -- opções do pacote babel --
    english,            % idioma adicional para hifenização
    french,             % idioma adicional para hifenização
    spanish,            % idioma adicional para hifenização
    brazil              % o último idioma é o principal do documento
    ]{abntex2}

\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize[prefix=figures/]

\begin{document}

\begin{tikzpicture}
\node[draw, circle, minimum width=1cm] {};
\end{tikzpicture}

\end{document}

Then the console shows the following information where the main tex file name is DissDaniel.tex:

pdflatex.exe> ===== 'mode=convert with system call': Invoking 'pdflatex -shell-escape -halt-o
pdflatex.exe> n-error -interaction=batchmode -jobname "figures/DissDaniel-figure0" "\def\tikz
pdflatex.exe> externalrealjob{DissDaniel}\input{DissDaniel}"' ========
pdflatex.exe> 
pdflatex.exe> ! Package tikz Error: Sorry, the system call 'pdflatex -shell-escape -halt-on-e
pdflatex.exe> rror -interaction=batchmode -jobname "figures/DissDaniel-figure0" "\def\tikzext
pdflatex.exe> ernalrealjob{DissDaniel}\input{DissDaniel}"' did NOT result in a usable output 
pdflatex.exe> file 'figures/DissDaniel-figure0' (expected one of .pdf:.jpg:.jpeg:.png:). Plea
pdflatex.exe> se verify that you have enabled system calls. For pdflatex, this is 'pdflatex -
pdflatex.exe> shell-escape'. Sometimes it is also named 'write 18' or something like that. Or
pdflatex.exe>  maybe the command simply failed? Error messages can be found in 'figures/DissD
pdflatex.exe> aniel-figure0.log'. If you continue now, I'll try to typeset the picture.
pdflatex.exe> 
pdflatex.exe> See the tikz package documentation for explanation.
pdflatex.exe> Type  H <return>  for immediate help.
pdflatex.exe>  ...                                              
pdflatex.exe>                                                   
pdflatex.exe> l.32 \end{tikzpicture}

Best Answer

I created na issue in abntex2 today.

Lauro Cesar digged into the problem until he came with a solution for me to test. And it Works!

According to this link:

The package calc changed the commands \setcounter and friends to be fragile. So you have to make them robust. The example below uses etoolbox with \robustify:

\usepackage{etoolbox}
\robustify\setcounter
\robustify\addtocounter
\robustify\setlength
\robustify\addtolength

Thank you Lauro for your lightning fast response and goal achievement.