The next code gives 5e-05 with \luaveclen{0.00003}{0.00004} but I need a decimal How to get a decimal notation ?
\def\luaveclen#1#2{
\directlua{
x = #1;
y = #2;
r=(x*x+y*y)^0.5
tex.print(tostring(r))}
}
with \luaveclen{0.0003}{0.0004} the result is 0.0005.
I need a decimal because here problem with veclen my answer now is wrong.
I find a solution with fpu but it's not elegant:
%!TEX TS-program = lualatex
\documentclass[11pt]{article}
\usepackage{fontspec}
\usepackage{luatextra}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,fpu}
\begin{document}
\makeatletter
\def\luaveclen#1#2{
\directlua{
x = #1;
y = #2;
r=(x*x+y*y)^0.5
tex.print(tostring(r))}
}
\pgfmathdeclarefunction*{veclen}{2}{%
\begingroup
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}
\pgfmathparse{\luaveclen{#1}{#2}}
\edef\pgfmath@tmp{\pgfmathresult}
\pgfmath@returnone\pgfmath@tmp pt
\endgroup
}
\makeatother
\pgfmathparse{veclen(0.00003,0.00004)}
Vector length is: \pgfmathresult
\begin{tikzpicture}[decoration={markings, mark = at position .5 with
{\draw (-2pt,-2pt) -- (2pt,2pt) (2pt,-2pt) -- (-2pt,2pt);}}]
\draw [postaction={decorate}] (0,0) -- ++(146:1) arc (146:157:1) -- (0,0);
\end{tikzpicture}
\luaveclen{0.0003}{0.0004}
\end{document}
%character is interpreted as a TeX comment, so this is the easiest solution. I am sure it would be possible to enable percent char also using catcodes – michal.h21 Nov 24 '19 at 19:25tex.print(string.format("\csstring\%f", r))to avoid having to define the additionalget_real_numberfunction. – Henri Menke Nov 25 '19 at 02:53