It might be helpful to look at the PDF produced by three different constructions that look the same to see the difference between simple paths, compound paths and grouped paths:
I've done this in l3draw
since it's syntax matches closely what you get in the final PDF.
\documentclass{article}
\pdfcompresslevel=0
\pdfobjcompresslevel=0
\usepackage{l3draw}
\pagestyle{empty}
\begin{document}
\ExplSyntaxOn
% four simple paths
% there are 4 stroke commands
\draw_begin:
\color_select:n { red }
\draw_path_moveto:n { 0bp , 0bp }
\draw_path_lineto:n { 10bp , 20bp }
\draw_path_use_clear:n { stroke }
\color_select:n { black }
\draw_path_moveto:n { 20bp , 0bp }
\draw_path_lineto:n { 20bp , 20bp }
\draw_path_use_clear:n { stroke }
\draw_path_moveto:n { 30bp , 0bp }
\draw_path_lineto:n { 30bp , 20bp }
\draw_path_use_clear:n { stroke }
\color_select:n { red }
\draw_path_moveto:n { 40bp , 0bp }
\draw_path_lineto:n { 50bp , 20bp }
\draw_path_use_clear:n { stroke }
\draw_end:
\par
% red paths are simple paths, black path is a compound path
% there are 3 stroke commands
\draw_begin:
\color_select:n { red }
\draw_path_moveto:n { 0bp , 0bp }
\draw_path_lineto:n { 10bp , 20bp }
\draw_path_use_clear:n { stroke }
\color_select:n { black }
\draw_path_moveto:n { 20bp , 0bp }
\draw_path_lineto:n { 20bp , 20bp }
\draw_path_moveto:n { 30bp , 0bp } % ← notice the moveto
\draw_path_lineto:n { 30bp , 20bp }
\draw_path_use_clear:n { stroke }
\color_select:n { red }
\draw_path_moveto:n { 40bp , 0bp }
\draw_path_lineto:n { 50bp , 20bp }
\draw_path_use_clear:n { stroke }
\draw_end:
\par
% four simple paths, but the black paths are grouped
% there is no need to set the stroke colour back to red after the group
% there are 4 stroke commands
\draw_begin:
\color_select:n { red }
\draw_path_moveto:n { 0bp , 0bp }
\draw_path_lineto:n { 10bp , 20bp }
\draw_path_use_clear:n { stroke }
\draw_scope_begin:
\color_select:n { black }
\draw_path_moveto:n { 20bp , 0bp }
\draw_path_lineto:n { 20bp , 20bp }
\draw_path_use_clear:n { stroke }
\draw_path_moveto:n { 30bp , 0bp }
\draw_path_lineto:n { 30bp , 20bp }
\draw_path_use_clear:n { stroke }
\draw_scope_end:
\draw_path_moveto:n { 40bp , 0bp }
\draw_path_lineto:n { 50bp , 20bp }
\draw_path_use_clear:n { stroke }
\draw_end:
\ExplSyntaxOff
\end{document}
The output of the 3 drawings is the same to look at:

But the PDF is slightly different for each case:
First drawing PDF
1.0 0.0 0.0 rg 1.0 0.0 0.0 RG ← select RGB red stroke and fill colour
0 0 m ← move to (0,0)
10 20 l ← line to (10,20)
S ← stroke path with current stroke colour (red)
0.0 g 0.0 G ← select Grayscale black stroke and fill colour
20 0 m ← move to (20,0)
20 20 l ← line to (20,20)
S ← stroke path with current stroke colour (black)
30 0 m ← move to (30,0)
30 20 l ← line to (30,20)
S ← stroke path with current stroke colour (black)
1.0 0.0 0.0 rg 1.0 0.0 0.0 RG ← select RGB red stroke and fill colour
40 0 m ← move to (40,0)
50 20 l ← line to (50,20)
S ← stroke path with current stroke colour (red)
This is (approximately) equivalent to the following tikz
picture:
\begin{tikzpicture}[color=red]
\draw (0bp,0bp) -- (10bp,20bp);
\draw[black] (20bp,0bp) -- (20bp,20bp);
\draw[black] (30bp,0bp) -- (30bp,20bp);
\draw (40bp,0bp) -- (50bp,20bp);
\end{tikzpicture}
Second drawing PDF
1.0 0.0 0.0 rg 1.0 0.0 0.0 RG ← select RGB red stroke and fill colour
0 0 m ← move to (0,0)
10 20 l ← line to (10,20)
S ← stroke path with current stroke colour (red)
0.0 g 0.0 G ← select Grayscale black stroke and fill colour
20 0 m ← move to (20,0)
20 20 l ← line to (20,20)
30 0 m ← move to (30,0)
30 20 l ← line to (30,20)
S ← stroke path with current stroke colour (black)
1.0 0.0 0.0 rg 1.0 0.0 0.0 RG ← select RGB red stroke and fill colour
40 0 m ← move to (40,0)
50 20 l ← line to (50,20)
S ← stroke path with current stroke colour (red)
This is (approximately) equivalent to the following tikz
picture:
\begin{tikzpicture}[color=red]
\draw (0bp,0bp) -- (10bp,20bp);
\draw[black] (20bp,0bp) -- (20bp,20bp) (30bp,0bp) -- (30bp,20bp);
\draw (40bp,0bp) -- (50bp,20bp);
\end{tikzpicture}
Third drawing PDF
1.0 0.0 0.0 rg 1.0 0.0 0.0 RG ← select RGB red stroke and fill colour
0 0 m ← move to (0,0)
10 20 l ← line to (10,20)
S ← stroke path with current stroke colour (red)
q ← save graphics state
0.0 g 0.0 G ← select Grayscale black stroke and fill colour
20 0 m ← move to (20,0)
20 20 l ← line to (20,20)
S ← stroke path with current stroke colour (black)
30 0 m ← move to (30,0)
30 20 l ← line to (30,20)
S ← stroke path with current stroke colour (black)
1.0 0.0 0.0 rg 1.0 0.0 0.0 RG ← select RGB red stroke and fill colour (this isn't technically needed, but LaTeX uses a stack for colour)
Q ← restore graphics state
40 0 m ← move to (40,0)
50 20 l ← line to (50,20)
S ← stroke path with current stroke colour (red)
This is (approximately) equivalent to the following tikz
picture:
\begin{tikzpicture}[color=red]
\draw (0bp,0bp) -- (10bp,20bp);
\begin{scope}[color=black]
\draw (20bp,0bp) -- (20bp,20bp);
\draw (30bp,0bp) -- (30bp,20bp);
\end{scope}
\draw (40bp,0bp) -- (50bp,20bp);
\end{tikzpicture}
\draw (0,0) -- (1,0) (2,0) -- (3,0);
is creating only one path. Try it with\draw[->] (0,0) -- (1,0) (2,0) -- (3,0);
and you'll see it.tikz
\path
command can create an arbitrary large number (up to TeX constraints) ofpgf
paths, i.e. things that can be impacted by pgf commands like\pgfusepath{stroke}
. To see this, consider e.g. anedge
or decorations. In this sense, a path is not well defined. Apgf
path is better defined.\draw (0,0) -- (1,0) (2,0) -- (3,0);
is one path that consists of 2 connected path components, see more in my previous answer here tex.stackexchange.com/a/615851/140722