3

I would like to include to one path both lines and points. My problem is that \draw command does not draw stroke a point while a single set of coordinates follows it. I.e. \draw (0,0); gives no visible effect.

Code:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{xstring}
\usetikzlibrary{shadows}

\pgfkeys{ /glow settings/.is family, /glow settings, layers/.store in=\opacitysteps, width/.store in=\glowwidth, color/.store in=\linecolor, default/.style={ layers=20, width=6pt, color=black } } \newcommand\drawglow[2][]{% \pgfkeys{/glow settings,default,#1} \foreach \w in {1,...,\opacitysteps}{ \pgfmathparse{10/\opacitysteps(1-pow(\w/\opacitysteps,0.25))} \edef\layeropacity{\pgfmathresult} \pgfmathparse{\glowwidth\w/\opacitysteps} \edef\layerwidth{\pgfmathresult} \draw [opacity=\layeropacity,line width=\layerwidth,color=\linecolor] #2; } }

\begin{document} \begin{tikzpicture}[line cap=round,line join=round] \drawglow[width=15mm]{(0,0) -- (1,1) (2,2) (0,1) -- (1,0) (0,1.3) (2,2.1)} \end{tikzpicture} \end{document}

Initially I tried to adapt this solution to obtain the string (0,0) -- (1,1) (2,2) -- ++(0,0) (0,1) -- (1,0) (0,1.3) -- ++(0,0) (2,2.3) -- ++(0,0), but without success.

I would like to obtain the following result:

enter image description here

EDIT: I am thinking about the LaTeX solution - not individual adjustment of each object. So the same options should modify the stoking style of paths and points. In my question the argument passed to the macro has the uniform style - both for dots and lines. So let we fix it to be (0,0) -- (1,1) (2,2) (0,1) -- (1,0) (0,1.3) (2,2.1). I found a similar question, but in fact left unanswered.

forrest
  • 958

1 Answers1

3

Original answer: append circle[radius=.1pt] manually

In example below, single coordinates, which correspond to the first n-1 move-to path operations in a chain of consecutive n move-tos (n >= 2), are one-by-one converted to small circles (<coordinate> circle[radius=.1pt]).

Other power tikz players may provide more advanced hence more automatic solutions using for example decorations and/or soft path manipulations supported by spath3.

\documentclass{standalone}
%\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shadows}

\pgfkeys{ /glow settings/.is family, /glow settings, layers/.store in=\opacitysteps, width/.store in=\glowwidth, color/.store in=\linecolor, default/.style={ layers=20, width=6pt, color=black } } \newcommand\drawglow[2][]{% \pgfkeys{/glow settings,default,#1} \foreach \w in {1,...,\opacitysteps}{ \pgfmathparse{10/\opacitysteps(1-pow(\w/\opacitysteps,0.25))} \edef\layeropacity{\pgfmathresult} \pgfmathparse{\glowwidth\w/\opacitysteps} \edef\layerwidth{\pgfmathresult} \draw[opacity=\layeropacity,line width=\layerwidth,color=\linecolor] #2; } }

\begin{document} \begin{tikzpicture}[line cap=round,line join=round] \drawglow[width=15mm]{ (0,0) -- (1,1) (2,2) circle[radius=.1pt] (0,1) -- (1,0) (0,1.3) circle[radius=.1pt] (2,2.1) circle[radius=.1pt] } \end{tikzpicture} \end{document}

enter image description here

Update, insert circle[radius=.1pt] automatically

Some tikz internals are patched to allow inserting arbitrary path operations between consecutive move-tos, including the position between final move-to and ;.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, shadows}

\usepackage{xpatch}

\pgfkeys{ /glow settings/.is family, /glow settings, layers/.store in=\opacitysteps, width/.store in=\glowwidth, color/.store in=\linecolor, default/.style={ layers=20, width=6pt, color=black } } \newcommand\drawglow[2][]{% \pgfkeys{/glow settings,default,#1} \foreach \w in {1,...,\opacitysteps}{ \pgfmathsetmacro\layeropacity{10/\opacitysteps(1-pow(\w/\opacitysteps,0.25))} \pgfmathsetmacro\layerwidth{\glowwidth\w/\opacitysteps} % \pgfwarning{line width=\layerwidth} \draw[opacity=\layeropacity,line width=\layerwidth,color=\linecolor] #2; } }

\makeatletter \def\mytikz@text@moveto{moveto}

\xpatchcmd\tikz@handle % relax the match pattern from \tikz@resetexpandcount\pgfutil@next % to \tikz@resetexpandcount, to gain backward compatibility {\tikz@resetexpandcount} {% \let\mytikz@pathop@last=\mytikz@pathop@current \let\mytikz@pathop@current=\pgfutil@empty % specially handle the case when the last path operation before ";" is moveto \ifx\pgfutil@next\tikz@finish \mytikz@drawcoord@prepare {\let\pgfutil@next=\mytikz@drawcoord@drawfinish}% \fi \tikz@resetexpandcount } {}{\PatchFailed}

\xpatchcmd\tikz@moveto {\tikz@scan@one@point{\tikz@@moveto}} {% \let\mytikz@pathop@current=\mytikz@text@moveto \def\pgfutil@next{\tikz@scan@one@point{\tikz@@moveto}}% \mytikz@drawcoord@prepare {\let\pgfutil@next=\mytikz@drawcoord@drawbetween}% \pgfutil@next } {}{\PatchFailed}

\def\mytikz@drawcoord@prepare#1{% \ifx\mytikz@pathop@last\mytikz@text@moveto \unless\ifx\mytikz@drawcoord@code\pgfutil@empty #1% \fi \fi }

\def\mytikz@drawcoord@drawbetween{% \expandafter\tikz@scan@next@command\mytikz@drawcoord@code} \def\mytikz@drawcoord@drawfinish{% \expandafter\tikz@scan@next@command\mytikz@drawcoord@code;}

% user interface \tikzset{ draw coordinate/.store in=\mytikz@drawcoord@code, draw coordinate=% init to an empty value } \makeatother

\begin{document} \begin{tikzpicture}[line cap=round,line join=round] \drawglow[width=15mm]{ (0,0) -- (1,1) (2,2) (0,1) -- (1,0) (0,1.3) (2,2.1) } \node[below=of current bounding box] {before}; \end{tikzpicture}

\begin{tikzpicture}[line cap=round,line join=round] \drawglow[width=15mm]{ (0,0) -- (1,1) (2,2) circle[radius=.1pt] (0,1) -- (1,0) (0,1.3) circle[radius=.1pt] (2,2.1) circle[radius=.1pt] } \node[below=of current bounding box] {manual solution}; \end{tikzpicture}

\begin{tikzpicture}[ line cap=round, line join=round, draw coordinate={circle[radius=.1pt]} ] \drawglow[width=15mm]{ (0,0) -- (1,1) (2,2) (0,1) -- (1,0) (0,1.3) (2,2.1) } \node[below=of current bounding box] {auto solution}; \end{tikzpicture} \end{document}

enter image description here

muzimuzhi Z
  • 26,474
  • I am looking for the solution which enables passing parameters in the uniform style. By several rearrangements of points joined by lines adding and removing circle commands seems to be not a good solution. I would like to convert each (x,y) into (x,y) -- ++(0,0) or - following your suggestion - into (x,y) circle[radius=half of my line width]. I tried to incorporate such a conversion into my macro, but without success. – forrest Jan 11 '23 at 13:14
  • 1
    @forrest Hi, I just appended a new, automatic solution. – muzimuzhi Z Jan 25 '23 at 17:31
  • I got the error: ! Undefined control sequence. <argument> \PatchFailed. Of course I looked for the command \patchcmd in the etoolbox package. But still I don't know, how to fix this problem. – forrest Feb 01 '23 at 13:32
  • @forrest Which pgf-tikz version do you use? – muzimuzhi Z Feb 01 '23 at 14:02
  • I have pdfTeX 3.141592653-2.6-1.40.22 (TeX Live 2021) – forrest Feb 02 '23 at 10:35
  • What's the exact version of tikz? tikz released between texlive 2021 and 2022, thus texlive 2021 installations may have different pgf versions installed, depending on whether user manually updated packages or not. You can add \listoffiles in preamble, compile, and then find package versions near the end of log. – muzimuzhi Z Feb 02 '23 at 16:17
  • @forrest Also please try the revised example, in which the match patten is relaxed a little bit. – muzimuzhi Z Feb 02 '23 at 16:21