模拟计算器屏幕

模拟计算器屏幕

有人建议我把这个问题作为一个新问题发布。不久前,这个绝妙的解决方案被发布在这个网站上。

\documentclass{article}
\usepackage{tikz,xparse}
\ExplSyntaxOn
\NewDocumentCommand{\calcinput}{m}
 {
  \tl_map_inline:nn { #1 } { ##1 \hspace{0pt} }
 }
\ExplSyntaxOff

\begin{document}

  \def\quest{\calcinput{1/(4.2+5.4)-(3.5+4.7)/9}}
  \def\ans{\calcinput{-0.806944444}}

\begin{tikzpicture}[font=\Large\ttfamily]
 \draw (0,0) rectangle (5,-4);
\node[align=flush left,text width =5cm,
  anchor=north west,inner sep=1pt] (qu) {\quest};
\node[align=right,text width =5cm,
  anchor=north west,inner sep=1pt] (an) at (qu.south west) {\ans};
\end{tikzpicture}

\begin{tikzpicture}[font=\Large\ttfamily]
 \draw (0,0) rectangle (4,-4);
\node[align=flush left,text width =4cm,
  anchor=north west,inner sep=1pt] (qu) {\quest};
\node[align=right,text width =4cm,
  anchor=north west,inner sep=1pt] (an) at (qu.south west) {\ans};
\end{tikzpicture}

\end{document}

然而,在我为学生编写的一些练习题上模拟计算器时,我需要模拟平方根符号。当我尝试这样做时:

\def\quest{\calcinput{normalcdf(.53,1E99,.5,$\sqrt{\phantom{i}}$(.5*.5/100))}}

我收到此错误:

./Untitled.tex:20: Missing { inserted.
<to be read again> 
                   \let 
l.20 ...hor=north west,inner sep=1pt] (qu) {\quest
                                                  };

有什么解决方法的建议吗?

答案1

定义

\newcommand{\tsurd}{\ensuremath{\surd}}

\documentclass{article}
\usepackage{tikz,xparse}
\newcommand\tsurd{\ensuremath{\surd}}
\ExplSyntaxOn
\NewDocumentCommand{\calcinput}{m}
 {
  \tl_map_inline:nn { #1 } { ##1 \hspace{0pt} }
 }
\ExplSyntaxOff

\begin{document}

\def\quest{\calcinput{normalcdf(.53,1E99,.5,\tsurd(.5*.5/100))}}
  \def\ans{\calcinput{-0.806944444}}

\begin{tikzpicture}[font=\Large\ttfamily]
 \draw (0,0) rectangle (5,-4);
\node[align=flush left,text width =5cm,
  anchor=north west,inner sep=1pt] (qu) {\quest};
\node[align=right,text width =5cm,
  anchor=north west,inner sep=1pt] (an) at (qu.south west) {\ans};
\end{tikzpicture}


\begin{tikzpicture}[font=\Large\ttfamily]
 \draw (0,0) rectangle (4,-4);
\node[align=flush left,text width =4cm,
  anchor=north west,inner sep=1pt] (qu) {\quest};
\node[align=right,text width =4cm,
  anchor=north west,inner sep=1pt] (an) at (qu.south west) {\ans};
\end{tikzpicture}

\end{document}

会给

在此处输入图片描述

相关内容