[Tex/LaTex] Problem when using Tikz in Lyx

lyxtikz-pgf

I am using Lyx 2.1 on a windows 7 machine with MikTex 2.9. When I embed even very simple tikz code in a Lyx document it appears to go off into a loop and eventually generates the error message

The command pdflatex -syntex=1 "file.tex" has not yet completed.

It seems to happen with most tikz code I try, but a specific example is, in the preamble I included

\usepackage{tikz}

In an ERT box within a preview box I have

\begin{tikzpicture}
\draw (0,0)--(1,2)--(2,0)
\draw[help lines] (0,0) grid (2,3)
\end{tikzpicture}

My guess is that it is something to do with SyncTex, but I have configured Lyx and the document not to use it. Any ideas what I am doing wrong (or is this a bug)?

Best Answer

In general, all TikZ commands has to be ended by a semicolon, so your code snippet should be

\begin{tikzpicture}
\draw (0,0)--(1,2)--(2,0);
\draw[help lines] (0,0) grid (2,3);
\end{tikzpicture}

If you ran a LaTeX document where such a terminating semicolon was missing, you'd get an error saying ! Package tikz Error: Giving up on this path. Did you forget a semicolon?. For some types of errors, you can tell TeX to just keep on generating the document, fixing/ignoring the error as best it can. With this error however, that doesn't seem to work, and LyX probably doesn't 'catch' this error, so instead of stopping the compilation and reporting the error, it just keeps on trying, and failing. The error messages you mention is perhaps the result of a timeout or something.

In other words, just be more careful with the semicolons. You could also create the figure in e.g. KTikZ/QTikZ or TikZEdt, and insert it in LyX afterwards.

Related Question