我想制作一张工作表,让学生在\fillin[]
答案行内写矩阵。从以下示例中可以看出,\fillin[]
似乎在写入单个数字系数时工作正常,但在矩阵方面存在问题。我收到错误:“缺少插入的 $。”
以下是 MWE:
\documentclass[openright, notitlepage]{book}
\usepackage{exam}
\addpoints
\printanswers
\usepackage[utf8]{inputenc}
\usepackage[margin=.75 in]{geometry}
\usepackage{amsmath,amsfonts,amssymb,amsthm,color,srcltx,bm,cancel}
\setlength\fillinlinelength{1cm}
\setlength\answerclearance{1.25ex}
\begin{document}
\section{Matrix Multiplication Practice}
\begin{questions}
\question
Please fill in the blanks:
\begin{equation*}
\begin{bmatrix}
a & b & c & d \\
e & f & g & h \\
i & j & k & l
\end{bmatrix}
\begin{bmatrix}2 \\ 3 \\ 4 \\ 5
\end{bmatrix}
=
\fillin[2]
\begin{bmatrix} a \\ e \\ i \end{bmatrix}
+
\fillin[3]
\begin{bmatrix} b \\ f \\ j \end{bmatrix}
+
\fillin[4]
\begin{bmatrix} c \\ g \\ k \end{bmatrix}
+
\fillin[5]
\begin{bmatrix} d \\ h \\ l \end{bmatrix}
\end{equation*}
\question
\setlength\answerclearance{7ex}
Please fill in the blanks:
\begin{equation*}
\begin{bmatrix}
h & y & w & s \\
e & o & a & u \\
y & u & t & p
\end{bmatrix}
\begin{bmatrix} 3 \\ 4 \\ 5 \\ 6 \end{bmatrix}
=
3
\fillin[\begin{bmatrix}h \\e \\y \end{bmatrix}]
+
4
\fillin[\begin{bmatrix}y \\o \\u \end{bmatrix}]
+
5
\fillin[\begin{bmatrix}w \\a \\t \end{bmatrix}]
+
6
\fillin[\begin{bmatrix}s \\u \\p \end{bmatrix}]
\end{equation*}
\end{questions}
\end{document}
尽管存在错误,但输出看起来还不错(我只是希望我不必手动调整\fillin[]
使用的答案间隙\setlength\answerclearance{7ex}
,这需要根据向量的高度进行一些猜测。)
知道如何修复该Missing $ inserted
错误吗?
答案1
重新定义以将基线以下的答案的深度\filling
添加到本地。\answerclearance
注意使用exam
class 而不是book
。
\documentclass[openright, notitlepage]{exam} % changed <<<<<<<<<<<<<<
%\usepackage{exam} %% does not work
\addpoints
\printanswers
\usepackage[utf8]{inputenc}
\usepackage[margin=.75 in]{geometry}
\usepackage{amsmath,amsfonts,amssymb,amsthm,color,srcltx,bm,cancel}
\setlength\fillinlinelength{1cm}
\setlength\answerclearance{1.25ex}
% *************************************** added <<<<<<<<<<<<<<<<
\usepackage{xpatch}
\newsavebox{\answerholder}
\newlength{\Danswerholder}
\newcounter{applied}
\makeatletter
\xpatchcmd{\questions}
{\addtocounter{numquestions}{1}}
{\addtocounter{numquestions}{1}\setcounter{applied}{0}}
{}{}
\renewcommand\fillin[1][{}]{%
\savebox{\answerholder}{#1}
\setlength{\Danswerholder}{\the\dp\answerholder}
\ifdim\Danswerholder>\the\fontchardp\font`g\ifnum \value{applied}=0%
\addtolength\answerclearance\Danswerholder \stepcounter{applied}
\fi\fi%
\def\fillin@ans{#1}\fillin@relay
}%
\makeatother
%***************************************
\begin{document}
\section{Matrix Multiplication Practice}
\begin{questions}
\question
Please fill in the blanks:
\begin{equation*}
\begin{bmatrix}
a & b & c & d \\
e & f & g & h \\
i & j & k & l
\end{bmatrix}
\begin{bmatrix}2 \\ 3 \\ 4 \\ 5
\end{bmatrix}
=
\fillin[2]
\begin{bmatrix} a \\ e \\ i \end{bmatrix}
+
\fillin[3]
\begin{bmatrix} b \\ f \\ j \end{bmatrix}
+
\fillin[4]
\begin{bmatrix} c \\ g \\ k \end{bmatrix}
+
\fillin[5]
\begin{bmatrix} d \\ h \\ l \end{bmatrix}
\end{equation*}
\question
Please fill in the blanks:
\begin{equation*}
\begin{bmatrix}
h & y & w & s \\
e & o & a & u \\
y & u & t & p
\end{bmatrix}
\begin{bmatrix} 3 \\ 4 \\ 5 \\ 6 \end{bmatrix}
=
3
\fillin[$\begin{bmatrix}h \\e \\y \\q \\w \end{bmatrix}$]
+
4
\fillin[$\begin{bmatrix}y \\o \\u \\q \\w\end{bmatrix}$]
+
5
\fillin[$\begin{bmatrix}w \\a \\t \\q \\w\end{bmatrix}$]
+
6
\fillin[$\begin{bmatrix}s \\u \\p \\q \\w\end{bmatrix}$]
\end{equation*}
\question
Please fill in the blanks:
\begin{equation*}
\begin{bmatrix}
h & y & w & s \\
y & u & t & p
\end{bmatrix}
\begin{bmatrix} 3 \\ 4 \\ 5 \\ 6 \end{bmatrix}
=
3
\fillin[$\begin{bmatrix}h \\y \end{bmatrix}$]
+
4
\fillin[$\begin{bmatrix}y \\u \end{bmatrix}$]
+
5
\fillin[$\begin{bmatrix}w \\t \end{bmatrix}$]
+
6
\fillin[$\begin{bmatrix}s \\p \end{bmatrix}$]
\end{equation*}
\end{questions}
\end{document}