缺失数字,视为零。(自定义类)

缺失数字,视为零。(自定义类)

我正在尝试为科学碗问题包编写一个类。出于某种原因,它\switchletter按预期工作,但内部实际相同的用法\printmc却不行。

错误信息:

/testing.tex:9: Missing number, treated as zero.
<to be read again> 
                   {
l.9 ...{Choice W}{Choice X}{Choice Y}{Choice Z}{2}

testing.tex

\documentclass{scibowlset}
\usepackage[utf8]{inputenc}
\usepackage[letterpaper, portrait, margin=1in]{geometry}


\begin{document}
\newcounter{qnumber}\stepcounter{qnumber}
\switchletter{Choice W}{Choice X}{Choice Y}{Choice Z}{1}
\printmc{Choice W}{Choice X}{Choice Y}{Choice Z}{2}
\end{document}

scibowlset.cls

\ProvidesClass{scibowlset}

\LoadClass[11pt,letterpaper]{article}

\usepackage[letterpaper, portrait, margin=1in]{geometry}
\usepackage[overload]{textcase}
\usepackage{enumitem}
\nofiles

\def \numtoletter #1 {
    \ifcase #1
        \or W
        \or X
        \or Y
        \or Z
    \fi
}

\def \switchletter #1#2#3#4#5 {
    \ifcase #5
        \or #1
        \or #2
        \or #3
        \or #4
    \fi
}

\def \printmc #1#2#3#4#5 {
    % \printmc {<choice w text>}{<choice x text>}{<choice y text>}{<choice z text>}{<correct choice index from 1>}
    \begingroup
        \begin{enumerate}[label=\Alph*),start=23]
            \item #1
            \item #2
            \item #3
            \item #4
        \end{enumerate}
    \endgroup
    ANSWER: \numtoletter{#5}) \switchletter{#1}{#2}{#3}{#4}{#5}
}

答案1

TeX 不是“自由形式”。

%%% file scibowlset.cls
\ProvidesClass{scibowlset}

\LoadClass[11pt,letterpaper]{article}

\usepackage[letterpaper, portrait, margin=1in]{geometry}
\usepackage[overload]{textcase}
\usepackage{enumitem}
\nofiles

\def\numtoletter#1{%
    \ifcase #1
        \or W%
        \or X%
        \or Y%
        \or Z%
    \fi
}

\def\switchletter#1#2#3#4#5{%
    \ifcase #5
        \or #1%
        \or #2%
        \or #3%
        \or #4%
    \fi
}

\def\printmc#1#2#3#4#5{%
    % \printmc {<choice w text>}{<choice x text>}{<choice y text>}{<choice z text>}{<correct choice index from 1>}
    \begingroup
        \begin{enumerate}[label=\Alph*),start=23]
            \item #1
            \item #2
            \item #3
            \item #4
        \end{enumerate}
    \endgroup
    ANSWER: \numtoletter{#5}) \switchletter{#1}{#2}{#3}{#4}{#5}
}

另一方面你应该做

\newcommand{\numtoletter}[1]{%
  ...
}
\newcommand{\switchletter}[5]{%
  ...
}
\newcommand{\printmc}[5]{%
  ...
}

在您的代码中,TeX 要求在三个宏的尾部参数后有一个空格。还要注意行尾会产生空格。

相关内容