I've working on some florishes on my ditto mark macro (see Tikz: use latex length for length of path (ditto marks)). Namely, using variable thickness for the strokes. Below it is implemented as the starred version of the macro.
However when I try to use a variable thickness stroke, I get 35 Dimension too large errors for a single \ditto* even though the generated path looks fine...
How do I fix this?
MWE:
\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{xparse}
\makeatletter
\usepackage{tikz}
\usetikzlibrary{math}
\usetikzlibrary{decorations}
\pgfkeys{/pgf/decoration/.cd,
start stroke width/.store in = \startstrokewidth,
end stroke width/.store in = \endstrokewidth,
}
\pgfkeys{/tikz/.cd,
pen stroke/.style args={#1,#2}{
decorate,
decoration={
variable stroke width,
start stroke width=#1,
end stroke width=#2,
}
}
}
\pgfdeclaredecoration{variable stroke width}{initial}{%
% modified version of:
% https://tex.stackexchange.com/questions/14283/stroke-with-variable-thickness
\state{initial}[width=0pt, next state=line, persistent precomputation={%
\pgfmathsubtract@{\startstrokewidth}{\endstrokewidth}%
\pgfmathdivide{\pgfmathresult}{\pgfdecoratedpathlength}%
\let\strokeincrement=\pgfmathresult%
\def\strokewidth{\startstrokewidth}%
}]{}
\state{line}[width=\startstrokewidth, persistent postcomputation={%
\pgfmathsubtract@{\strokewidth}{\strokeincrement}%
\let\strokewidth=\pgfmathresult%
}]{%
\pgfsetlinewidth{\strokewidth}%
\pgfsetarrows{-}%
\pgfpathmoveto{\pgfpointorigin}%
\pgfpathlineto{\pgfqpoint{.75pt}{0pt}}%
\pgfusepath{stroke}%
}
\state{final}{%
\pgfsetlinewidth{\pgflinewidth}%
\pgfpathmoveto{\pgfpointorigin}%
\pgfusepath{stroke}%
}
}
\newdimen\dto@x
\newdimen\dto@y
\newdimen\dto@spc
\NewDocumentCommand\ditto{ s O{2ex} m }{%
% #1 = starred means use pen stroke, unstarred use regular line
% #2 = minimum width
% #3 = string to use for calculating width
\settowidth{\dto@x}{#3}%
%\showthe\dto@x%
\dto@x = \ifdim#2<\dto@x\the\dto@x\else\the\dimexpr#2\relax\fi% whichever is widest of #2 and #3
\divide\dto@x by 4% sine wave has 4 points
\dto@y = .0675ex% .125ex%
\dto@spc = .5pt% ditto mark sizing
\begin{tikzpicture}[baseline=-.5ex,cap=round]
\IfBooleanTF{#1}{% starred
\draw[pen stroke={.4pt,.35pt}] (0,0) sin (1\dto@x, \dto@y) cos (2\dto@x, 0) sin (3\dto@x, -\dto@y) cos (4\dto@x, 0);
}{% unstarred
\draw (0,0) sin (1\dto@x, \dto@y) cos (2\dto@x, 0) sin (3\dto@x, -\dto@y) cos (4\dto@x, 0);
}%
\draw[xshift=-.2ex, pen stroke={.4pt,.35pt}] (2\dto@x + .25pt, 3\dto@y) -- (2\dto@x - .25pt, -3\dto@y);
\draw[xshift=.2ex, pen stroke={.4pt,.35pt}] (2\dto@x + .25pt, 3\dto@y) -- (2\dto@x - .25pt, -3\dto@y);
\end{tikzpicture}%
}
\makeatother
\begin{document}
\noindent
blah blah Test blah blah\\
blah blah \ditto{Test} blah blah\\
blah blah \ditto*{Test} blah blah\\ % throws 'Dimension too large' several times, but looks great in doc?!
blah blah Testing testing blah blah\\
blah blah \ditto{Testing testing} blah blah\\
%blah blah \ditto*{Testing testing} blah blah\\
blah blah \ditto{} blah blah\\
%blah blah \ditto*{} blah blah\\
blah blah \ditto[10em]{Test} blah blah\\
%blah blah \ditto*[10em]{Test} blah blah\\
blah blah \ditto[10em]{Testing testing} blah blah\\
%blah blah \ditto*[10em]{Testing testing} blah blah\\
blah blah \ditto[10em]{} blah blah\\
%blah blah \ditto*[10em]{} blah blah\\
\end{document}
Related:
