我不是第一个尝试绘制康托阶梯的人,但我想了解为什么我的代码不起作用。这是一个最小的例子:
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{math}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}[
evaluate={
function cantor(\n,\t) {
if \n == 0 then {
return \t;
}
else {
if \t < 1/3 then {
return cantor(\n-1,3*\t)/2;
}
else {
if \t < 2/3 then {
return 1/2;
}
else {
return (1/2+cantor(\n-1,3*\t-2)/2);
};
};
};
},
}
]
\begin{axis}
\addplot+ [domain=0:1,samples=100] {cantor(0,x)};
\end{axis}
\end{tikzpicture}
\end{document}
错误信息是
Runaway argument?
\ifx \tikz@math@meaning \tikz@math@meaning@null \let \tikz@math@next \ETC.
./cantor2.tex:33: Paragraph ended before \tikz@math@@getmeaning was complete.
<to be read again>
我想知道我做错了什么。任何帮助都将不胜感激 :-)