시험 수업: 사용자 정의 형식을 적용하기 위해 \question 명령을 재정의하는 가장 좋은 방법

시험 수업: 사용자 정의 형식을 적용하기 위해 \question 명령을 재정의하는 가장 좋은 방법

편집: 요약하자면 답변은 정말 우아하고 간단했습니다. 아래의 모든 답변에 감사드립니다!

\usepackage{etoolbox}
%...
\renewcommand\questionshook{\preto{\question}{\large\bfseries}}

% If we don't want the question's parts to be huge as well!
%\renewcommand\partshook{\normalsize\normalfont}

곧, 저는 다음을 기반으로 사용자 정의 시험 시트 문서 클래스를 생성하고 싶습니다.exam수업동료 그룹에서 사용합니다. 이를 위해 \question일부 사용자 지정 형식을 적용하도록 기본 명령을 재정의하고 싶습니다.

\question기본 섹션을 크고 굵게 만들고 싶다고 가정해 보겠습니다 . 내가 지금 하고 있는 일은 다음과 같습니다.

\newcommand\lquestion{\large\bfseries\question}

따라서 사용자 정의 형식을 사용하려면 대신 문서에 다음을 작성해야 합니다.

\begin{lquestion}
A large and bold question: what is the mass of the sun?
\end{lquestion}

(LaTeX에서는 명령을 환경으로 사용하는 것이 괜찮다는 것을 읽었지만 수중 돌이 숨겨지면 정정해 주십시오.)

환경 시작 부분에 해당 보너스를 추가할 필요 없이 기본 포함된 이름을 대신 사용할 수 있도록 question에서 제공되는 명령을 환경으로 재정의하는 가장 좋은 방법은 무엇입니까 ?exam.clslquestion

편집: 최소한의 작업 예:

\documentclass{exam}
\usepackage[utf8]{inputenc}

\title{MWE}
\author{John Doe}
\date{November 2020}

%print solutions by default (for MWE's sake)
\printanswers
% do not put a box/frame around printed solutions
\unframedsolutions

\begin{document}

\maketitle

\begin{questions}
    %this is basically what I want the result to look like:
    {\large\bfseries
        \question My large and bold question:
        \begin{parts}
        \part First part
        \part Second part
        \end{parts}
    }
    %but instead of this rather inconvenient form, I want to define an environment {question} with the same effect and use it like:
    %
    % \begin{question}
    % My large and bold question:
    % \begin{parts}
    %     \part First part
    %     \part Second part
    % \end{parts}
    % \end{question}
    
    
    \begin{solution}
    My general solution prerequisite.
    \begin{parts}
        \part My first part solution
        \part My second part solution
    \end{parts}
    \end{solution}
\end{questions}

\end{document}

\question정의는 2845행에서 찾을 수 있습니다.exam.cls환경 내부 questions:


\newenvironment{questions}{%
  %.... lots of code here
  \def\question{%
    \@bonusfalse
    \def\thequestiontitle{\csname p@question\endcsname
                          \csname thequestion\endcsname}%
    \process@question
  }%
  %.... lots of other code here
%and waaaaay down on line 3143
}% End of the second argument of \newenvironment{questions}

미리 감사드립니다!

답변1

명령을 환경으로 사용할 수 있다는 것을 이미 발견한 것 같습니다. 따라서 귀하의 질문은 실제로 " 처음에 question있도록 명령 을 재정의할 수 있는 방법"입니다. \large\bfseries발견한 문제는 환경 이 명령 questions을 정의한다는 것입니다 \question. 어떤 경우에는 귀하의 예가

\usepackage{etoolbox}
\appto{\questions}{%
 \preto{\question}{\large\bfseries}%
 \printanswers%
}

거기에 필요한 것이 만족스럽지 않지만 \printanswers그렇지 않으면 솔루션이 사라집니다. 따라서 두 가지 다른 명령을 추적해야 할 수도 있습니다 \printanswers.

환경 질문에 관해서는 \begin{myenv}...\end{myenv}다음과 같습니다 \begingroup\myenv ...\endmyenv\endgroup( \endmyenv존재하지 않으면 오류가 발생하지 않습니다). 결과적으로 \large\bfseries문서의 나머지 부분이 변경되지 않도록 자동으로 그룹화됩니다.

답변2

실제로 형식 변경을 처리하기 위해 \questionshook\partshook를 사용할 수 있습니다.\SolutionEmphasis

\documentclass{exam}
\usepackage[utf8]{inputenc}

\title{MWE}
\author{John Doe}
\date{November 2020}

%print solutions by default (for MWE's sake)
\printanswers
% do not put a box/frame around printed solutions
\unframedsolutions

\renewcommand\questionshook{\large\bfseries}
\renewcommand\partshook{\normalsize\normalfont}
\SolutionEmphasis{\normalsize\normalfont}

\begin{document}

\maketitle

\begin{questions}
     \question %\begingroup ... \endgroup not needed
     My large and bold question:
     \begin{parts}
         \part First part
         \part Second part
     \end{parts}
    
    \begin{solution}
    My general solution prerequisite.
    \begin{parts}
        \part My first part solution
        \part My second part solution
    \end{parts}
    \end{solution}
\end{questions}

\end{document}

답변3

환경을 만드는 가장 기본적인 방법은 \newenvironment{<name>}{<begin code>}{<end code>}. 따라서 귀하의 경우에는 \newenvironment{\lquestion}{\large\bfseries\question}{}시작 코드나 종료 코드에 원하는 다른 것을 추가할 수 있습니다. 시작 코드는 \begin{lquestion}태그에서 발생하는 코드이고 종료 코드는 \end{lquestion}태그에서 발생하는 코드입니다. 물론 이를 수행하는 더 진보된 방법이 있지만 이것이 가장 간단한 방법이며 이 경우 더 복잡한 방법이 필요하지 않습니다.

관련 정보