
我想建立一個返回實際值的巨集。例如,我想要類似以下偽代碼的內容:
\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}