7

It was recommended that I post this as a new question. Sometime back, this marvelous solution was posted on this site.

\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}

However, in emulating the calculator on some practice problems I am writing for our students, I need to emulate the square root symbol. When I try this:

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

I get this error:

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

Any suggestions for a workaround?

1

1 Answer 1

8

Define

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

and

\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}

will give

enter image description here

1
  • Thanks. I really appreciate how helpful you have been with this code. A lot of students are benefitting because of your effort.
    – David
    Oct 28, 2012 at 23:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .