工作示例

工作示例

以下代码没有解析 tikzpicture 内部的定义,因此没有打印标签。

\documentclass[tikz]{article}

\usepackage{keycommand} 
\usepackage{ifthen} 
\usepackage{tikz}
\usepackage{tkz-euclide}

\ExplSyntaxOn
\NewExpandableDocumentCommand \randomint { m m }
{ \int_rand:nn { #1 } { #2 } }
\NewExpandableDocumentCommand \randomfloat { O{2} m m }
{
    \fp_eval:n { round( (#3-#2)*(rand()/#3) + #2, #1 ) }
}
\ExplSyntaxOff

\NewExpandableDocumentCommand{\bettersquareroot}{O{2}m}{%
    \fpeval{round(sqrt(#2),#1)}%
}


\newkeycommand\triangleSAS[a,b,c,alpha,beta,gamma,la,lb,lc,lalpha,lbeta,lgamma,rotate=0,scale=1][1]{
    
    \ifcommandkey{a}{a=\commandkey{a},}{}
    \ifcommandkey{b}{b=\commandkey{b},}{}
    \ifcommandkey{c}{c=\commandkey{c},}{}
    \ifcommandkey{alpha}{alpha=\commandkey{alpha},}{}
    \ifcommandkey{beta}{beta=\commandkey{beta},}{}
    \ifcommandkey{gamma}{gamma=\commandkey{gamma},}{}
    
    
    \def\a{\commandkey{a}}
    \def\b{\commandkey{b}}
    \def\c{\commandkey{c}}
    \def\aalpha{\commandkey{alpha}}
    \def\abeta{\commandkey{beta}}
    \def\agamma{\commandkey{gamma}}
    
    
    \def\labelalpha{\ifthenelse{\equal{90}{90}}{\cdot}{\aalpha\degree}} % OK
    %\def\labelalpha{\ifthenelse{\equal{\aalpha}{90}}{\cdot}{\aalpha\degree}} % undefined control sequence }

    
    \rotatebox{\commandkey{rotate}}{%
        \begin{tikzpicture}[scale=\commandkey{scale},x=1cm,y=1.0cm]
            
            \coordinate [label=left:$A$] (A) at (0,0);
            \coordinate [label=right:$B$] (B) at (\c,0);
%           \coordinate [label=above:$C$] (C) at (\Cx ,\Cy ); 
            \coordinate [label=above:$C$] (C) at (2 ,2 ); 
            \draw (A) -- node[sloped,below] {c} (B) -- node[sloped,above] {a} (C) -- node[sloped, above] {b} (A); 
            
            % angles
            \tkzMarkAngle(B,A,C)
            \tkzLabelAngle[pos=0.6](B,A,C){$\labelalpha$}
            \tkzMarkAngle(C,B,A)
            \tkzLabelAngle[pos=0.6](C,B,A){$\beta$}
            \tkzMarkAngle(A,C,B) 
            \tkzLabelAngle[pos=0.6](A,C,B){$\gamma$}
        \end{tikzpicture}
    }
}


\begin{document}
\foreach \n in {1,...,2}{
    \triangleSAS[b=5,c=6,alpha=\randomint{11}{90}]
}

\end{document}

例如

工作示例

\triangleSAS[b=4,c=5,alpha=45]

\triangleSAS[b=4,c=5,alpha=90]

有效1 有效2

答案1

你得到

! Undefined control sequence.
<argument> \aalpha \degree

最后的令牌是触发错误消息的原因。

如果我添加

\newcommand{\degree}{\ensuremath{^\circ}}

我得到了文件序言

在此处输入图片描述

并且没有错误。

相关内容