# Asymptote's dot analogue in TikZ

I have been trying to replicate Asymptote's dot style in TikZ, having the outer diameter equal to dotfactor * linewidth(p) where p denotes the given or current pen and dotfactor is 6 by default.

What is wrong with this example, it does not compile at all?

\documentclass{article}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{graphicx}
\usepackage{float}
\usepackage{tikz}
\usepackage{pgfkeys}

\begin{document}

\tikzset{
dot/.style={circle,fill,minimum size=6*\pgfkeysvalueof{/tikz/line width}}
}

\begin{figure}[H]
\centering
\begin{tikzpicture}[scale=2]
\coordinate [dot,label=left:$A$] (A) at (1, 0);
\coordinate [dot,label=below:$B$] (B) at (8, 3);
\draw (A) -- (B);
\end{tikzpicture}
\end{figure}

\end{document}


## 1 Answer

The line width is stored in \pgflinewidth.

\documentclass{article}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage{float}
\usepackage{tikz}

\begin{document}

\tikzset{
dot/.style={circle,fill,inner sep=6*\pgflinewidth/2}
}

\begin{figure}[H]
\centering
\begin{tikzpicture}[scale=2]
\coordinate [dot,label=left:$A$] (A) at (1, 0);
\coordinate [dot,label=below:$B$] (B) at (5, 2);
\draw (A) -- (B);
\draw[very thick] (1,-1) coordinate[dot,label=left:$A'$] (A')
-- (5,1) coordinate[dot,label=below:$B'$] (B');
\end{tikzpicture}
\end{figure}
\end{document}


It is easy to add the dotfactor to the game.

\documentclass[tikz,border=3mm]{standalone}

\tikzset{
dot/.style={circle,fill,minimum
size=\pgfkeysvalueof{/tikz/dotfactor}*\pgflinewidth-\pgflinewidth,inner sep=0pt,outer sep=0pt,
draw},
dotfactor/.initial=6
}
\begin{document}
\begin{tikzpicture}[scale=2]
\coordinate [dot,label=left:$A$] (A) at (0, 0);
\coordinate [dot,label=below:$B$] (B) at (4, 2);
\draw (A) -- (B);
\draw[very thick] (0,-1) coordinate[dot,label=left:$A'$] (A')
-- (4,1) coordinate[dot,label=below:$B'$] (B');
\draw[very thick,dotfactor=4] (0,-2) coordinate[dot,label=left:$A''$] (A'')
-- (4,0) coordinate[dot,label=below:$B''$] (B'');
\end{tikzpicture}
\end{document}


EDIT: Changed to minimum width in the lower answer. It also draws the dots (which is why there is a -\pgflinewidth) in order to avoid gaps.

• @ivankokan Because if you keep the inner sep at some value, the node won't shrink even if you decrease minimum size further. – Schrödinger's cat Jan 9 at 14:44
• Based on tex.stackexchange.com/a/48596/115879, I would say that inner sep=0pt, minimum size=(\pgfkeysvalueof{/tikz/dotfactor}-1)*\pgflinewidth is exactly what I wanted ("no additional space" + "(dotfactor-1) times the line width as two line width halves will be added"). Also, when drawing edge, one should specify .center anchors (due to outer sep gaps). – ivankokan Jan 9 at 15:33
• @ivankokan Yes, that also works. It is just two keys instead of one. But you are right, it is perhaps more intuitive. So I changed the answer accordingly. The gaps can be avoided by also drawing the circles (which, of course, means that we have to subtract half a line width from the radius or a line width from the diameter/width). – Schrödinger's cat Jan 9 at 15:40
• + Due to roundness and rendering issues, add outer sep = 0. (In my (1, 0) - (8, 3) case there is a gap around (1, 0).) – ivankokan Jan 9 at 16:20
• @ivankokan Thanks! Done. – Schrödinger's cat Jan 9 at 16:41