The initial code is as follows: the idea is to avoid the "dimension too large" error by temporarily modifying the veclen macro
\documentclass{standalone}
\usepackage{tkz-euclide}
\begin{document}
% Schrodinger's cat idea 03/01/20
\makeatletter
\tikzset{xfp/.code={%
\pgfmathdeclarefunction*{veclen}{2}{%
\begingroup%
\pgfmath@x##1pt\relax%
\pgfmath@y##2pt\relax%
\edef\tkz@xfpMathLen{\fpeval{sqrt((\pgf@x)^2+(\pgf@y)^2)}}
\pgfmath@returnone\tkz@xfpMathLen pt%
\endgroup%
}}}%
\makeatother
\begin{tikzpicture}[scale=1]
\tkzDefPoint(0,0){O}
\tkzDefPoint(2.5,0){N}
\tkzDefPoint(-4.2,0.5){M}
\tkzDefPointByrotation=center O angle 30
\tkzGetPoint{B}
\tkzDefPointByrotation=center O angle -50
\tkzGetPoint{A}
\tkzInterLCcommon=B(O,B) \tkzGetFirstPoint{C}
\tkzInterLCcommon=A(O,A) \tkzGetFirstPoint{A'}
\tkzDrawSegments(A,C M,A M,B A,B)
\tkzDrawCircle(O,N)
% \tkzMarkAnglemkpos=.2, size=1.2
% Latex Error: ./testlua2.tex:32 Dimension too large.
\begin{scope}[xfp]
\tkzMarkAnglemkpos=.2, size=1.2
\end{scope}
\tkzDrawPoints(O, A, B, M, B, C, A')
\tkzLabelPointsright
\tkzLabelPointsabove left
\tkzLabelPointbelow left{$A'$}
\end{tikzpicture}
\end{document}
Now I try to use lua like this:
\documentclass{standalone}
\usepackage{tkz-euclide}
\begin{document}
% Schrodinger's cat idea 03/01/20
\makeatletter
\tikzset{lua/.code={%
\pgfmathdeclarefunction*{veclen}{2}{%
\begingroup%
\pgfmath@x##1pt\relax%
\pgfmath@y##2pt\relax%
\pgf@xa=\pgf@x%
\pgf@ya=\pgf@y%
\edef\tkz@temp@xa{\pgfmath@tonumber{\pgf@xa}}% \strip@pt ??
\edef\tkz@temp@ya{\pgfmath@tonumber{\pgf@ya}}%
\edef\tkz@xfpMathLen{\directlua{tex.print(math.sqrt((\tkz@temp@xa)^2+(\tkz@temp@ya)^2))}}
% \edef\tkz@xfpMathLen{\fpeval{round(\tkz@xfpMathLen,6)}} % with this line I get a result
\pgfmath@returnone\tkz@xfpMathLen pt%
\endgroup%
}}}%
\makeatother
\begin{tikzpicture}[scale=1]
\tkzDefPoint(0,0){O}
\tkzDefPoint(2.5,0){N}
\tkzDefPoint(-4.2,0.5){M}
\tkzDefPointByrotation=center O angle 30
\tkzGetPoint{B}
\tkzDefPointByrotation=center O angle -50
\tkzGetPoint{A}
\tkzInterLCcommon=B(O,B) \tkzGetFirstPoint{C}
\tkzInterLCcommon=A(O,A) \tkzGetFirstPoint{A'}
\tkzDrawSegments(A,C M,A M,B A,B)
\tkzDrawCircle(O,N)
% \tkzMarkAnglemkpos=.2, size=1.2
% Latex Error: ./testlua2.tex:32 Dimension too large.
\begin{scope}[lua]
\tkzMarkAnglemkpos=.2, size=1.2
\end{scope}
\tkzDrawPoints(O, A, B, M, B, C, A')
\tkzLabelPointsright
\tkzLabelPointsabove left
\tkzLabelPointbelow left{$A'$}
\end{tikzpicture}
\end{document}
but I get the following error: ! Illegal unit of measure (pt inserted). This error disappears if I use:
\edef\tkz@xfpMathLen{\fpeval{round(\tkz@xfpMathLen,6)}}
I must admit that I don't understand what is going on. How to avoid this mistake properly?
In order to convert a dimension into a number I know two methods: \pgfmath@tonumber \strip@pt. I have tried both without success. I don't know if that's the problem.


9.4868329805051e-05. You have to tell Lua to return a number not in exponential form. – egreg Jan 09 '23 at 22:17tex.print(string.format('\@percentchar.12f',math.sqrt(...should work (increase the 12 if you need more digits.) – Ulrike Fischer Jan 09 '23 at 23:03tex.print(string.format("\csstring\%f", r))– Alain Matthes Jan 09 '23 at 23:06function print_float(x) tex.print(string.format(...) end-- side note, to understand what's going on just print out things with e.g.\typeoutwhich is sufficient in this case. – user202729 Jan 10 '23 at 02:12tracebut I get too much informations. – Alain Matthes Jan 10 '23 at 10:33\show\tkz@xfpMathLenafter the\edefand kept hitting return until the error showed. – egreg Jan 10 '23 at 10:36