It's quite unfortunate that fp
doesn't offer an option to warn the user when the first argument to an \FP...
macro is already defined.
It's also (unfortunate) common practice to use short names for variables to use in TikZ. This may have no side effect if used inside a tikzpicture
, because (non global) redefinitions are nullified when the tikzpicture
ends.
Not always safe: in a very recent question, a user got into troubles because of using \color
as the name for a variable in a \foreach
loop, but the loop code used \textcolor
.
In your case, you're redefining three existing control sequences:
\u
is for the “breve accent”, whence \u{a}
yields ă;
\v
is for the “háček” accent, whence \v{c}
yields č;
\wd
is a primitive TeX command that's used in several places, as it returns the width of some built box.
While the first two redefinitions are harmless in your example, because it doesn't sport accented letters, the last one is fatal. At some point, TeX is instructed to do some calculations involving the box containing the text to be typeset at the node and it needs the width of that box, which it inquires using \wd
; but \wd
now means something completely different.
Here is a different method. The names are longer, but the input is much clearer. With \fpeval
you can do computations on the spot (see the second node).
\documentclass{article}
\usepackage{xfp} % not fp
\usepackage{tikz}
\ExplSyntaxOn
\NewDocumentCommand{\setfpvar}{mm}
{
\fp_zero_new:c { l_aria_fpvar_#1_fp }
\fp_set:cn { l_aria_fpvar_#1_fp } { #2 }
}
\NewExpandableDocumentCommand{\fpvar}{m}
{
\fp_use:c { l_aria_fpvar_#1_fp }
}
\ExplSyntaxOff
\begin{document}
\setfpvar{u}{-60}
\setfpvar{v}{3}
\setfpvar{wd}{\fpvar{u}/\fpvar{v}}
\begin{tikzpicture}
\node at (0,0) {$u/v=\fpvar{wd}$};
\node at (0,-1) {$u/v=\fpeval{\fpvar{u}/\fpvar{v}}$};
\end{tikzpicture}
\end{document}

\wd
primitive. This calls for trouble. Name your macro\mywd
or so instead.\u
and\v
single letter macros. There are use for diacritics. In general, thou shalt not redefine single letter macros.\w
instead of\wd
for the variable name it works with tikz.\ariau
and\ariav
. These are highly unlikely to be defined by any other package and should therefore always be safe to use.