2

Consider the following LaTeX manuscript featuring a PGF path consisting of two successive diagonal line segments intercepted by a rectangular text node.

\documentclass{article}
  \usepackage{pgf}
\begin{document}
    \begin{pgfpicture}
      \pgfpathmoveto{\pgfpoint{-1cm}{-1cm}}
      \pgfpathlineto{\pgfpointorigin}
      \pgfnode{rectangle}{center}{Hello world}{}{\pgfusepath{stroke}}
      \pgfpathlineto{\pgfpoint{1cm}{1cm}}
      \pgfusepath{stroke}
    \end{pgfpicture}
\end{document}

The resulting image is

stroke

Why is the second line segment not drawn?

If I now change the node's stroke instruction to fill, the following image results:

fill

Where has the first line segment gone?

7
  • 1
    97.3 The Line-To Path Operation (\pgfpathlineto{<coordinatei>) "This command extends the current path in a straight line to the given <coordinate>. If this command is given at the beginning of path without any other path construction command given before (in particular without a move-to operation), the TEX file may compile without an error message, but a viewer application may display an error message when trying to render the picture." or do not display the line.
    – Bobyandbob
    Commented Jul 23, 2017 at 19:16
  • I would really suggest that you read about the timer concept before going about these. Without those details, you won't be satisfied with any answer.
    – percusse
    Commented Jul 23, 2017 at 19:18
  • @Bobyandbob: But the line-to operation is not given at the beginning of a path, but in the middle of it.
    – Evan Aad
    Commented Jul 23, 2017 at 19:22
  • @percusse: Where can I read about it?
    – Evan Aad
    Commented Jul 23, 2017 at 19:22
  • 1
    section .96.5.2
    – percusse
    Commented Jul 23, 2017 at 20:01

1 Answer 1

1

The internals are a bit convoluted but since node is using \pgfusepath all the soft path collected until that point is used and deleted.

And since there is no moveto operation at the beginning of the next path it is not drawn. Check for example

\begin{pgfpicture}
%\pgfpathmoveto{\pgfpointorigin}
  \pgfpathlineto{\pgfpoint{1cm}{1cm}}
  \pgfusepath{stroke}
\end{pgfpicture}

which draws nothing if it is left commented.

5
  • So the node become part of the first part of the path?
    – Evan Aad
    Commented Jul 24, 2017 at 7:08
  • @EvanAad No, node path was added to the already waiting list of paths to be drawn and triggered already accumulated path to be used which includes also the line drawn before it.
    – percusse
    Commented Jul 24, 2017 at 7:20
  • Would you say that it is better to keep path building and node creation separated? Is there any circumstance where it would make sense to intertwine them?
    – Evan Aad
    Commented Jul 24, 2017 at 7:23
  • @EvanAad I don't think that is the right way of thinking about this. There is no separation. you just add things to the current path and whenever you are ready you give a draw, fill etc. directive and the low level postscript creates objects. There is no conceptual difference in the eyes of lowlevel whether it's node or not.
    – percusse
    Commented Jul 24, 2017 at 7:39
  • I've done some experimenting, and I feel like the node does become part of the ambient path. Unfortunately there's not enough space in this comment to list my experiment, so I'll add it to my original post and then delete it. You can see it by looking at the delta between the revisions.
    – Evan Aad
    Commented Jul 24, 2017 at 8:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .