在问题计数器上添加半分/分数

在问题计数器上添加半分/分数

我希望能够为我的问题添加半分,但我不知道如何处理\stepcounter。下面是我的样式文件的一部分,您能帮忙吗?我本质上想说\mrks{0.5},并且必须将这些添加到打印在问题顶部的总分中,由我的\question{}命令定义。

   \typeout{ exam paper style -- Version 06/06/14}

%========================================================================
%  \ifnull  --- checks if parameter is null (spaces are NOT null)
%  \ifblank --- checks if parameter is blank (i.e. null or spaces)
%  \ifgiven --- checks if parameter is not blank: like \ifblank\else
%     use \ifgiven{#1}\then   ...  \else  ...  \fi   etc
\let\then\iftrue
{\catcode`\!=8 % funny catcode so ! will be a delimiter
\long\gdef\ifgiven#1\then{\Ifbl@nk#1@@@\empty!}% negative of \ifblank
\long\gdef\ifblank#1\then{\Ifbl@nk#1@@..!}% if null or spaces
\long\gdef\Ifbl@nk#1#2@#3#4!{\ifx#3#4}
\long\gdef\ifnull#1\then{\IfN@LL#1* {#1}!}% if null
\long\gdef\IfN@LL#1 #2!{\ifblank{#2}\then}
}
\setcounter{tocdepth}{0}
%\setlength{\parskip}{\medskipamount}  % a little space before a \par
\setlength{\parindent}{0pt}       % don't indent first lines of paragraphs
\renewcommand{\arraystretch}{1.2}
%
\newenvironment{paper}[1]{\ifgiven{#1}\then\papernum{#1}\fi\maketitle}%
{\label{last@quest}%
\@recordmarks{\arabic{question}}{\arabic{qmarkcnt}}\gentoctable}
%
\long\def\instructions#1{\long\def\@instructions{#1}}\def\@instructions{}
\def\papernum#1{\def\@papernum{#1}}\def\@papernum{}
\def\course#1{\def\@course{#1}}\def\@course{}
\def\totalmarks#1{\def\@totalmarks{#1}}\def\@totalmarks{}
\def\totaltime#1{\def\@totaltime{#1}}\def\@totaltime{}
\def\nocalculator{\def\@calcu{NOT }}\def\@calcu{}
%
\def\maketitle{\par
\begingroup
\global\@topnum\z@ \@maketitle 
\endgroup
\let\maketitle\relax
\let\@maketitle\relax
\gdef\@title{}\gdef\@course{}\gdef\@papernum{}\gdef\@instructions{}
\gdef\@totalmarks{}\gdef\@totaltime{}\gdef\@calcu{}
% \let\thanks\relax
}
%
\def\@maketitle{\newpage
\null
\begin{center}\Large
  Uni
  \bigskip
  CS \@course\\[\baselineskip]
  {\bf \@title}
  \ifx\@empty\@papernum
  \else
    \\[.5\baselineskip]{\bf Paper \@papernum} 
  \fi\\
\end{center}
\rule{\textwidth}{1pt}
\@instructions\par
\begin{minipage}[t]{.5\textwidth}
\begin{tabbing}
{\bf Marks:}x \= \kill
{\bf Marks:}\>\@totalmarks \\[\baselineskip]
{\bf Time:} \>\@totaltime
\end{tabbing}
\end{minipage}
\hfill
\begin{minipage}[t]{.5\textwidth}\raggedleft
\begin{itemize} \itemsep 0pt
\item Approximate marks per question are shown in brackets
\item The use of calculators is \@calcu permitted
\end{itemize}
\end{minipage}
\rule{\textwidth}{1pt}
}

\def\section{\par            % New paragraph
\ifnum \c@section >\z@ \addvspace{3ex}\hrule height1pt \fi
  \addvspace{4ex}           % Adds vertical space above title.
  \@afterindentfalse        % Suppresses indent in first paragraph.  Change
  \secdef\@section\@ssection}     % to \@afterindenttrue to have indent.

\def\@section[#1]#2{\ifnum \c@secnumdepth >\m@ne    % IF secnumdepth -1
    \refstepcounter{section}                    %  THEN step section counter
    \fi
  { \parindent \z@ \centering
    \large \bf Section           % Print 'Part'
      \ifnum \c@secnumdepth >\m@ne   % IF secnumdepth -1
      \thesection\@.                 %   THEN  print number
      \fi                            % FI
    #2\markboth{}{}\par }          % Print title and set heading marks null.
    \nobreak                       % TeX penalty to prevent page break.
    \vskip 2ex                     % Space between title and text.
  \@afterheading                  % Routine called after part and
    }                              %     section heading.
%
% Heading for \section* command
\def\@ssection#1{{\parindent \z@ \centering
    \large\bf Section: #1 \par}              % Title.
    \nobreak                        % TeX penalty to prevent page break.
    \vskip 2ex                      % Space between title and text.
    \@afterheading                  % Routine called after part and
  }                                 %     section heading.
\newcounter{question}
\newcounter{qmarkcnt}[question]
\def\questionmark#1{}  % we don't need header marks
%\def\thequestion{Question \arabic{question}}
%\def\question{\@startsection{question}{2}{\z@}{-3.25ex plus -1ex minus
% -.2ex}{1.5ex plus .2ex}{\bf}}
\def\question{\par             % New paragraph
  \addvspace{3.25ex plus 1ex minus .2ex}  % Adds vertical space before
  \@recordmarks{\arabic{question}}{\arabic{qmarkcnt}}
  \@afterindentfalse          % Suppresses indent in first paragraph.
  \secdef\@question\@squestion}
\def\@question[#1]#2{\@@quest{#2}}
% Heading for \question* command
\def\@squestion#1{\@@quest{#1}}
\def\@@quest#1{%
  \refstepcounter{question}         % step question counter
  {\bf Question \thequestion. #1    % Print 'Question n.' and title
    \hspace{2em}                     % Print total marks...
    [\qmarks{\arabic{question}} marks]
    \markboth{}{}\par}               % set heading marks null.
    \nobreak                       % TeX penalty to prevent page break.
    \vskip 1.5ex plus .2ex         % Space between title and text.
  \@afterheading                  % Routine called after part and
}                                  %     section heading.
%
\def\qmarks#1{\@ifundefined{q@#1}{??\@warning
  {Total marks for Question `#1' on page \thepage \space
    undefined}}{\edef\@tempa{\@nameuse{q@#1}}\@tempa}}
%
\def\@recordmarks#1#2{\@bsphack\ifnum #1 >\z@\if@filesw {%
\def\protect{\noexpand\noexpand\noexpand}%
\xdef\@gtempa{\write\@auxout{\string\newqmarks{#1}{#2}}}}\@gtempa
%\ifnum #1 >\lastquestion\lastquestion=#1\fi
\fi\fi\@esphack}
% 
% #1 = question number; #2 = total marks
\def\newqmarks#1#2{\@ifundefined{q@#1}{}{\@warning
  {Question `#1' total marks multiply defined}}\global\@namedef{q@#1}{#2}}
%

\leftmargini  2em
\leftmarginii \leftmarginiii
\leftmarginiii \leftmarginiv

\def\labelenumi{\alph{enumi})}
\def\theenumi{(\alph{enumi})}

\def\labelenumii{\theenumii)}
\def\theenumii{\roman{enumii}}
\def\p@enumii{\theenumi}

\def\labelenumiii{\theenumiii.}
\def\theenumiii{\Alph{enumiii}}
\def\p@enumiii{\theenumi\theenumii.}

\def\labelenumiv{\theenumiv.}
\def\theenumiv{\arabic{enumi}}
\def\p@enumiv{\p@enumiii\theenumiii.}
\newcount\lincnt

\newcommand{\mrks}[1]{\mbox{}\nobreak\hfill\nobreak[#1]%
\addtocounter{qmarkcnt}{#1}}
\newcommand{\linemarks}[1]{\mbox{}\nobreak\hrulefill\ \nobreak[#1]%
\addtocounter{qmarkcnt}{#1}}
\newcommand{\lines}[1]{\par\mbox{}\hrulefill\mbox{}\lincnt=1
\loop\ifnum\lincnt<#1 \advance\lincnt by 1
\\[.5\baselineskip]\mbox{}\hrulefill\mbox{}\repeat\\\mbox{}}
\newcommand{\forcemarks}[1]{\setcounter{qmarkcnt}{#1}}

\def\tableofcontents{%\begin{center}
% {\bf NAME: \fbox{\rule[-.2ex]{0pt}{2ex}\hspace*{9cm}}\hfill STUDENTNO:
%\framebox[3cm]{\rule[-.2ex]{0pt}{2ex}}}\\[.5\baselineskip]
%
{\bf NAME:} \raisebox{2.8ex}{\makebox[0pt][l]{Surname}}%
\fbox{\rule[-.2ex]{0pt}{2ex}\hspace*{9cm}}%
\raisebox{2.8ex}{\makebox[0pt][r]{Initials}}\\[.5ex]
{\bf STUDENT NO:} \framebox[3.5cm]{\rule[-.2ex]{0pt}{2ex}} \hfill
{\bf COURSE CODE:} \framebox[2.5cm][l]{CSC\rule[-.2ex]{0pt}{2ex}}\\[.5\baselineskip]
This paper consists of \ref{last@quest} questions and 
\pageref{last@quest} pages (including this cover page).
%   \\[1ex]
\begin{center}
\@starttoc{toc}\addtocontents{toc}{
\protect\begin{tabular}{|rr|l|l||rr|l|l|}
\protect\hline\protect\multicolumn{8}{|c|}{\bf Mark Allocation}\protect\\
\protect\hline\protect\hline
Quest & Marks & Internal & External &
Quest & Marks & Internal & External \protect\\\protect\hline}
\end{center}\clearpage}

\def\gentoctable{\@ifundefined{tf@toc}{}{%
\@tempcnta=\c@question\advance\@tempcnta by 1\divide\@tempcnta by 2
\@tempcntb=\c@question \divide\@tempcntb by 2 \lincnt=0%
\loop\ifnum\lincnt <\@tempcntb%
\advance\lincnt by 1\advance \@tempcnta by 1
\addtocontents{toc}{\number\lincnt & 
\protect\@ifundefined{q@\number\lincnt}{[??]}%
{[\protect\@nameuse{q@\number\lincnt}]} & & & 
\number\@tempcnta & 
\protect\@ifundefined{q@\number\@tempcnta}{}%
{[\protect\@nameuse{q@\number\@tempcnta}]}
& & \protect\\\protect\hline}%
\repeat%
\@tempcnta=\c@question\advance\@tempcnta by 1\divide\@tempcnta by 2
\ifnum\lincnt <\@tempcnta%
\addtocontents{toc}{
\number\@tempcnta & 
\protect\@ifundefined{q@\number\@tempcnta}{[??]}%
{[\protect\@nameuse{q@\number\@tempcnta}]} &&& &&&
\protect\\\protect\hline}%
\fi%
\addtocontents{toc}{
\protect\multicolumn{2}{|r|}{\bf Total}& & &
\protect\multicolumn{2}{r|}{\bf Total} & & \protect\\\protect\hline
\protect\multicolumn{6}{r|}{\bf Grand Total} &
\protect\rule{0pt}{4ex} &\protect\\\protect\cline{7-8}
\protect\multicolumn{6}{r|}{\bf Final Mark} & 
\protect\multicolumn{2}{|r|}{\protect\rule{0pt}{4ex}}
\protect\\\protect\cline{7-8}\protect\hline
\protect\multicolumn{4}{|l||}{\bf Internal Examiner:\protect\rule{0pt}{4ex}}& 
\protect\multicolumn{4}{l|}{\bf External Examiner:}
\protect\\\protect\hline
\protect\end{tabular}}%
}}%
%
% Change \enddocument so it checks the \q@i values for changes similar to
% what is done with references.
%
\def\enddocument{%
\@checkend{document}\clearpage\begingroup%
\if@filesw \immediate\closeout\@mainaux%
\def\global\@namedef##1##2{}\def\newlabel{\@testdef r}%
\def\newqmarks{\@testdef q}% <------- the only change (addition) we made
\def\bibcite{\@testdef b}\@tempswafalse \makeatletter\input \jobname.aux
\if@tempswa \@warning{Label(s) may have changed.  Rerun to get
cross-references right}\fi\fi\endgroup\deadcycles\z@\@@end}

母语:

    \documentclass[A4paper,test,11pt]{article}
\usepackage{test}

\begin{document}
\title{test}

\begin{paper}{}

\question{}
\begin{enumerate}
\item A question  \lines{3} \mrks{4}

\item Another question \lines{3} \mrks{4.5} % try 4

\item Another question \lines{3} \mrks{4.5} % try 4

\end{enumerate}


\end{paper}
\end{document}

编辑 老实说,我发布的样式文件不是我写的。这是几年前别人写的,我们联系不上他。我真的很想实现 David 的建议,但这超出了我对乳胶的理解和经验。我很想学习低级乳胶编码,但由于时间有限,我负担不起。任何针对我提交的样式文件更具体的建议都将非常受欢迎。

答案1

您的最小示例实际上并不接近最小示例,因此我没有使用它。TeX 计数器是整数,因此您可以选择保留 10 倍的标记并在.打印时添加,或者像这里一样使用长度寄存器并pt在末尾删除。

在此处输入图片描述

\documentclass{article}

\makeatletter

\newdimen\mrkscnt

\newenvironment{qn}
{\bigskip\mrkscnt\z@}
{\par Total: \strip@pt\mrkscnt}

\newcommand{\mrks}[1]{\par\mbox{}\nobreak\hfill\nobreak[#1]%
 \advance\mrkscnt#1\p@
}



\makeatother

\begin{document}

\begin{qn}
\mrks{1}
\mrks{3.5}
\mrks{2}
\end{qn}

\begin{qn}
\mrks{1.25}
\mrks{3.5}
\mrks{10}
\end{qn}

\end{document}

相关内容