# Tikz takes forever to compile when imported into main file

I used TikzEdt in order to generate some figures to use in my thesis. However, when I included the source code by copy-pasting/\input in the main document under a figure environment my document took forever to compile without any errors and yielded a corrupted PDFoutput file after I cancel the compilation.

As far as I am concerned, I have all the necessary packages in the preamble and I have generated a minimal working example after inspecting the exported code from TikzEdt.

The non-compiling file is huge so the driving file is here, the class file is a modified book class and the included macros are basic.

Furthermore TikzEdt complains that the following line with the message: "Couldn't parse code. NoViableAltException in line 16 at position 44. Is some \end{} command missing?". A compiling MWE is here.

\draw[<->, thick] (-1,0)++({\ang+90}:1) --++ (\ang:{2*cos(\ang)});

EDIT The issue is resolved and the problem was my usage of \ang which is an internal macro defined in the package siunitx. TikzEdt parser still complains, yet I do not know if it is a real problem.

A screenshot from the issue in TikzEdt is below. The error message is displayed in red lines.

• You want your example to produce the error but, if I've understood you correctly, the code you've posted will compile fine. Is that correct? Also, I'm confused about what you are doing with TkzEdt when it gives you the parsing error. I thought you exported the code from there? Are you saying it can't compile it either? If we need the other example, post it here instead of or as well as the existing one. – cfr Apr 28 '17 at 0:18
• @cfr Both MWEs and TikzEdt compile and output a valid PDF. But TikzEdt complains, and I exported the code from there. I have a huge main thesis file with a big preamble and this is the file which does not compile. – Vesnog Apr 28 '17 at 0:21
• @cfr After going through the preamble commenting out each comment to see if they are the culprit, I managed to make a minimal example with the same preamble as in the large document. This file compiled after commenting out \siunitx package which is pretty surprising and it also switched to compatibility mode as evident from: Package caption Error: The subcaption' package does not work correctly(caption) in compatibility mode. \begin{document}. – Vesnog Apr 28 '17 at 0:27
• But you say in the question that the MWE does NOT compile. Now you say it does, which means that the problem is in code we don't have. We need an example which produces the error. All that is wrong with this one is a missing \begin{document}. It compiles fine in either preview or non-preview mode. – cfr Apr 28 '17 at 0:29
• Which error do you get from TeX when you compile? I don't have TkzEdt to compare. I can produce AN error by adding xparse but I don't know whether it is the right error. – cfr Apr 28 '17 at 0:33

Well, you need a \begin{document}, obviously, but it otherwise works fine converted to a regular document with the picture in a figure.

\documentclass{article}
\usepackage{tikz,amsmath, amssymb,bm,color}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{decorations.markings,math}
\usetikzlibrary{calc}

\begin{document}
\begin{figure}
\center
\begin{tikzpicture}
\tikzmath{\ang = 45;};
\begin{scope}[thick,decoration={
markings,
mark=at position 0.5 with {\arrow{latex}}}
]
\filldraw[red] (-1,0) circle (2pt)
node[anchor=east, font = \footnotesize] at (-1,-0.2) {$\mathrm{E_0}$};
\draw[dashed, red] (-1,0) --++({\ang+90}:1);
\filldraw[green] (1,0) circle (2pt)
node[anchor=west, font = \footnotesize] at (1,-0.2) {$\mathrm{E_0}$};
\draw[postaction={decorate}, red] (-1,0) --++ (\ang:2);
\draw[postaction={decorate}, green] (1,0) --++ (\ang:2);
\draw[<->, thick] (-1, -0.2) -- (1, -0.2);
\draw[dashed, green] (1,0) --++ ({\ang+90}:2.5);
\draw[<->, thick] (-1,0)++({\ang+90}:1) --++ (\ang:{2*cos(\ang)});
%       \draw[<->, thick] (-1,0)++({\ang+90}:1) --++ (\ang:{2*cos(\ang) });
\node[anchor=north, font = \footnotesize]  at  (0, -0.2) {d=$\lambda/2$};
\end{scope}
\draw[blue, thick, dash pattern= on 25 off 7 on 50 off 7 on 10] (-2,0) -- (2, 0);
\node[anchor=west, font = \footnotesize, blue] at (1.5,-0.05) {z}; node[near start, auto] {true}
\draw[thick,blue,->] ([shift=(0:1)]1,0) arc (0:\ang:1);
%   \draw[thick,blue,->] (2,0)  arc (0:\ang:1);
\draw (1,0)++({\ang/2}:1.2) node[rotate=\ang, anchor=base, blue, font=\normalsize]{$\theta$};
\draw ({\ang+90}:1.3) node[rotate=\ang, anchor=base, black, font=\normalsize]{$d\cos\theta$};
\end{tikzpicture}
\caption{Picture}
\end{figure}
\end{document}


Possibly I don't understand the question.

# EDIT

Adding siunitx produces AN error, though whether it is YOUR error, I don't know. Specifically xparse complains that \ang is not expandable. This is because the current code invokes \ang, which is no longer an unassigned macro name. So it is trying to expand \ang to its definition, but can't. (And, if it could, the results would not be good either.)

The solution is to use a new name such as \myangle.

\documentclass{article}
\usepackage{tikz,amsmath,amssymb,bm}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{decorations.markings,math}
\usetikzlibrary{calc}
\usepackage{siunitx}

\begin{document}
\begin{figure}
\center
\begin{tikzpicture}
\tikzmath{\myangle = 45;};
\begin{scope}[thick,decoration={
markings,
mark=at position 0.5 with {\arrow{latex}}}
]
\filldraw[red] (-1,0) circle (2pt)
node[anchor=east, font = \footnotesize] at (-1,-0.2) {$\mathrm{E_0}$};
\draw[dashed, red] (-1,0) --++({\myangle+90}:1);
\filldraw[green] (1,0) circle (2pt)
node[anchor=west, font = \footnotesize] at (1,-0.2) {$\mathrm{E_0}$};
\draw[postaction={decorate}, red] (-1,0) --++ (\myangle:2);
\draw[postaction={decorate}, green] (1,0) --++ (\myangle:2);
\draw[<->, thick] (-1, -0.2) -- (1, -0.2);
\draw[dashed, green] (1,0) --++ ({\myangle+90}:2.5);
\draw[<->, thick] (-1,0)++({\myangle+90}:1) --++ (\myangle:{2*cos(\myangle)});
%       \draw[<->, thick] (-1,0)++({\myangle+90}:1) --++ (\myangle:{2*cos(\myangle) });
\node[anchor=north, font = \footnotesize]  at  (0, -0.2) {d=$\lambda/2$};
\end{scope}
\draw[blue, thick, dash pattern= on 25 off 7 on 50 off 7 on 10] (-2,0) -- (2, 0);
\node[anchor=west, font = \footnotesize, blue] at (1.5,-0.05) {z}; node[near start, auto] {true}
\draw[thick,blue,->] ([shift=(0:1)]1,0) arc (0:\myangle:1);
%   \draw[thick,blue,->] (2,0)  arc (0:\myangle:1);
\draw (1,0)++({\myangle/2}:1.2) node[rotate=\myangle, anchor=base, blue, font=\normalsize]{$\theta$};
\draw ({\myangle+90}:1.3) node[rotate=\myangle, anchor=base, black, font=\normalsize]{$d\cos\theta$};
\end{tikzpicture}
\caption{Picture}
\end{figure}
\end{document}


compiles to the output shown above.

• Thanks for the answer, I think this is some sort of package clash issue as I explained in the comment under my answer. It seems to conflict with siunitx package. – Vesnog Apr 28 '17 at 0:28
• Then you need to edit your question to provide code which really does not compile, else we can't possibly know what the problem might be. – cfr Apr 28 '17 at 0:31
• You are right, it did not occur to me it was a package clash issue in the first place. I think I need to upload my class file and the main file together with the defined macros. – Vesnog Apr 28 '17 at 0:32
• @Vesnog Please see my edit above first. You haven't said what error you get, so I don't know whether the error I got is your error, but presumably you will know whether it is or not. At any rate, this is A problem with the code, even if not the only one. – cfr Apr 28 '17 at 0:38
• I am now trying to change that \ang` variable and see if it resolves the problem. – Vesnog Apr 28 '17 at 0:42