# How to keep my Tex interpreter running?

I'm coding with Vscode and XeLatex. When running the code below, it worked and cost approximately 20s

\documentclass[border={0pt}]{standalone}

\usepackage{tikz,}

\begin{document}

\begin{tikzpicture}
[%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
box/.style={rectangle,draw=black,thick, minimum size=28pt},
]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\foreach \y in {0,2,4,...,100}{
\foreach \x in {0,1,...,100}
\node[box,fill=black] at (\x,\y){};
}
\end{tikzpicture}

\end{document}


But when it comes to the code like this (which I suppose takes the double computational complexity), it would run for no more than 30s and automatically turned off.


\usepackage{tikz,}

\begin{document}

\begin{tikzpicture}
[%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
box/.style={rectangle,draw=black,thick, minimum size=28pt},
]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\foreach \y in {0,2,4,...,100}{
\foreach \x in {0,1,...,100}
\node[box,fill=black] at (\x,\y){};
}
\foreach \y in {1,3,5,...,99}{
\foreach \x in {0,2,...,100}
\node[box,fill=red] at (\x,\y){};
}

\end{tikzpicture}

\end{document}


How can I make it run for 20 seconds more to make it, or it just me misunderstood the information fed back by Tex? If there is anything ambiguous please tell me. Thanks for your help!!

• TeX will just run until it's done. In online systems such as Overleaf, there is a 'wrapper' that will kill long jobs, but on a local system, usually you just do that yourself :) Mar 12, 2021 at 9:58
• you seem to be running from python, your call to tex from there must be setting a timeout as tex itself will loop forever if that is specified. So you will need to change your python settings somewhere Mar 12, 2021 at 10:13

Remarks:

• Nodes are highly inefficient just for drawing rectangles. There is a rectangle operator just for this job.

• Using \foreach inside one \path (or \fill, \draw, ...) is more efficient (file size) than creating a path for each loop iteration.

• Simple stripes do not need a nested loop.

Code example with much better runtime and file size:

\documentclass[border=0pt, tikz]{standalone}

\begin{document}
\begin{tikzpicture}
\fill[black]
\foreach \y in {0,2,4,...,100}{
(0, \y) rectangle +(101, 1)
}
;
\fill[red]
\foreach \y in {1,3,5,...,99}{
\foreach \x in {0,2,...,100}{
(\x, \y) rectangle +(1, 1)
}
}
;
\end{tikzpicture}
\end{document}
`

The example can be improved further (left as exercise for the reader):

• First draw the red vertical stripes, then the black horizontal stripes on top of it. This removes the nested loop for the red boxes.

• thanks for your help! :) Mar 20, 2021 at 9:55