我想要构建返回实数值的宏。例如,我想要类似以下伪代码的内容:
\documentclass{article}
\usepackage{etoolbox}
\usepackage{calculator}
\newcommand{\scale}[3]{%
\ifnumgreater{#1}{10}
{\return{#1}}
{\ifnumgreater{#2}{10}
{\return{#2}}
{\return{#3}}
}
}
\begin{document}
\begin{tikzpicture}[scale=1]
%* Polar Ray - Centerline - Origin at (0,0), 45degs from horizontal to a length of \scale
\draw [red,dashed] (0,0) -- ++(45:\scale{9}{12}{10});
\end{tikzpicture}
\end{document}
最终,我将使用几种此类宏来评估tikz
图表中的几何图形。谢谢
答案1
function
一种可能的实现是使用TikZ 库声明math
:
\documentclass[tikz]{standalone}
\usetikzlibrary{math}
\tikzmath{function myscalefun(\a,\b,\c) {
if \a>10 then { return \a; } else {
if \b>10 then { return \b; } else {
return \c; }; };
};}
\begin{document}
\begin{tikzpicture}[scale=1]
\clip (0,0) rectangle (15.5,9);
\foreach \r in {8,...,15} {
\draw[gray!20] (0,0) circle (\r);
\node[above] at (\r,0) {\r};
}
\draw (0,0) -- ++(45:{myscalefun(9,12,10)});
\draw (0,0) -- ++(30:{myscalefun(11,12,10)});
\draw (0,0) -- ++(15:{myscalefun(9,8,9)});
\end{tikzpicture}
\end{document}