tikz latex3 add tag
joulev
So let's assume that I have a command `\foo` that changes the value of a `fp` variable, and then "display" (return?) it.

This `\foo` works.

```tex
% arara: pdflatex
\documentclass{article}
\usepackage[enable-debug]{expl3}
\usepackage{xparse}
\usepackage{tikz}
\ExplSyntaxOn
\debug_on:n {all}
\fp_new:N \l_foo_fp
\NewDocumentCommand \foo {m}
  {
    \fp_set:Nn \l_foo_fp { #1 }
    \fp_to_dim:N \l_foo_fp
  }
\ExplSyntaxOff
\begin{document}
\foo{1cm}
\end{document}
```

![blob](/image?hash=1f8faae7acab77d397ff85a2546946a7357abbbf4783fe2321fbc045fb3b1a01)

All good! Let's use the command to construct some Ti*k*Z paths.

```tex
% arara: pdflatex
\documentclass{article}
\usepackage[enable-debug]{expl3}
\usepackage{xparse}
\usepackage{tikz}
\ExplSyntaxOn
\debug_on:n {all}
\fp_new:N \l_foo_fp
\NewDocumentCommand \foo {m}
  {
    \fp_set:Nn \l_foo_fp { #1 }
    \fp_to_dim:N \l_foo_fp
  }
\ExplSyntaxOff
\begin{document}
\begin{tikzpicture}
  \draw (0,0) circle (\foo{1cm});
\end{tikzpicture}
\end{document}

% ! LaTeX3 Error: A floating point with value '0' was misused.
%
% To obtain the value of a floating point variable, use '\fp_to_decimal:N',
% '\fp_to_tl:N', or other conversion functions.
```

It doesn't work. I have tried all sensible `\fp_to_*:N` I can think of without success. Using `\l_foo_fp` only, with or without `\fp_use:N`, also fail.

Not sure if this is even related to Ti*k*Z, because the error message is a `LaTeX3 Error`. Anyway, how to deal with this?
Top Answer
user 3.14159
You want an expandable variant thereof. This expandable variant already exists. It is given in `xfp.sty`.

````
\NewExpandableDocumentCommand \fpeval { m } { \fp_eval:n {#1} }
\NewExpandableDocumentCommand \inteval { m } { \int_eval:n {#1} }
````

So you can just load this package instead of defining your own macro.

````
\documentclass{article}
\usepackage[enable-debug]{expl3}
\usepackage{xfp}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \draw (0,0) circle[radius=\fpeval{1cm}*1pt];
\end{tikzpicture}
\end{document}
````

![Screen Shot 2020-04-23 at 12.28.57 PM.png](/image?hash=2efc91e6777b84fab289bb05a9f8b4ffb690599eaba2a7f1dee96bae54d6b00b)

A few comments are in order.
1. `\fpeval` strips units (and so does `\pgfmathsetmacro`), so we had to add `*1pt`. Ti*k*Z has a very delicate mechanism that checks whether or not an expression which it encounters in a coordinate, say, has units. By using `xfp` we disable this mechanism and need to be more careful than in plain Ti*k*Z.
2. You could try to combine Ti*k*Z's mechanism of checkign whether the thing has units with `xfp`. While this will be definitely a hack, it should be possible.
3. There is the `fpu` library. It does not always yield very precise results but allows one to get rid of the `dimension too large` errors. For plain Ti*k*Z purposes the precision is usually more than sufficient.
4. You may have the at first sight great idea to replace `\pgfmathparse` (and `\pgfmathsetmacro`) by an `xfp` variant. This idea is unfortunately not that great. Why? pgf has tons of functions, and so does `expl3`, but the function names do not always coincide. (It would be great, though, if an `expl3` witch or wizard could add a switch that makes the pgf functions known to `expl3`. Whether or not this is possible even in principle, I do not know.) What is more, even if that worked, this won't fix the `dimension too large` errors, at least not completely, since many of them come from plain TeX computations without any `\pgfmathparse`. However, empirically one finds that replacing `\pgfmathreciprocal@` by an `fpu` variant a substantial fraction of these errors disappears. This will also be true if we replace `\pgfmathreciprocal@` by an `xfp` variant (but it will be hard to find one example in which the gain in precision  is relevant).

Let me expand a bit on the Ti*k*Zy mechanism to check for units/dimensions. The main instrument here is `\ifpgfmathunitsdeclared`, see this excerpt from pgfmanual v3.1.5 on p. 1028

![Screen Shot 2020-04-23 at 1.48.03 PM.png](/image?hash=5a5ca11fcaf6a64bda1d38ea09076cb2678c5220fda12ab4cbb27fafba77d3b8)


This allows you to define a style that uses `xfp` and checks units in the usual Ti*k*Zy fashion.

````
\documentclass{article}
\usepackage[enable-debug]{expl3}
\usepackage{xfp}
\usepackage{tikz}
\tikzset{%
  fpradius/.code={%
    \pgfmathparse{#1}%
    \ifpgfmathunitsdeclared
      \pgfkeyssetevalue{/tikz/x radius}{\fpeval{#1}*1pt}%
      \pgfkeyssetevalue{/tikz/y radius}{\fpeval{#1}*1pt}%
    \else
      \pgfkeyssetevalue{/tikz/x radius}{\fpeval{#1}}%
      \pgfkeyssetevalue{/tikz/y radius}{\fpeval{#1}}%
    \fi
  }%
}%

\begin{document}
\begin{tikzpicture}
  \draw (0,0) circle[fpradius=1cm] (pi,0) circle[fpradius=1];
\end{tikzpicture}
\end{document}
````

![Screen Shot 2020-04-23 at 1.49.04 PM.png](/image?hash=013ef7038d2cc5c04976187e30a68aacacc1904459116c03c2029b74f6012eec)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.