%20%EC%88%A8%EA%B2%A8%EC%A7%84%20%EC%BD%98%ED%85%90%EC%B8%A0%EC%97%90%20%EB%8C%80%ED%95%9C%20%EC%B9%B4%EC%9A%B4%ED%84%B0%EB%A5%BC%20%EA%B3%84%EC%86%8D%20%EB%8A%98%EB%A6%AC%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
나는 각 하위 문제에 대한 솔루션의 내용이 \solution
전역 부울이 true로 설정된 경우에만 해당 내용을 표시하는 -macro에 공급되는 연습 문제를 만들기 위한 프레임워크를 가지고 있습니다.
내가 관심 있는 것은 솔루션이 있는 버전과 없는 버전 모두에 대해 고유한 방정식/그림/표/목록 번호를 갖는 것입니다. 특히 솔루션에서 카운터가 증가하는 경우를 고려해야 합니다. 이렇게 하면 의도된 이점은 학생들이 솔루션에서 참조할 수 있는 방정식 번호(및 기타 사항)가 나중에 솔루션이 게시된 후에도 번호가 변경되지 않는다는 것입니다.
이를 수행하려는 첫 번째 시도는 인쇄되지 않은 상자에 모든 것을 조판하는 것이었습니다(예: -environment에 의해 \sbox
또는 의해 lrbox
). 실제로 카운터가 증가하기를 바라지만, 이미 equation
환경 문제에 직면했습니다.
(3)
다음은 오일러의 공식에 토글의 두 설정에 대한 방정식 번호가 있어야 하는 MWE입니다 with_solution
. 솔루션이 없는 버전이 작동하려면 \iftoggle
in 의 세 번째 인수(내용)를 \solution
주석 처리해야 합니다.
편집하다:문제를 우회하는 한 가지 해결책은 모든 관련 카운터를 하위 문제에 종속시키는 것입니다. 왜냐하면 공식의 발생은 첫 번째이고 따라서 필연적으로 고유하기 때문입니다(공식이 솔루션이 있거나 없는 두 버전 모두에 나타나기 때문에). 그러나 이것은 나에게 흥미로운 해결책이 아닙니다. 왜냐하면 실제로(절감된 MWE와 비교하여) 내 방정식은 이미 (5.3.2)
eq와 유사하기 때문입니다. 문제 2 연습 5의 3, 하위 문제는 "5.3a)", "5.3b)" 등으로 보입니다. (일관적인 표기법을 사용합니다. 즉, (5.3a.2)
나에게는 매력적이지 않습니다.) 카운터를 종속시키는 것은 problem
도움이 되지 않습니다. 왜냐하면 각 하위 문제에 대한 다양한 공식 사이에서 솔루션은 호출로 재설정되지 않는 다양한 카운터를 증가시킬 수 있기 때문입니다 \subproblem
.
\documentclass{article}
\usepackage{etoolbox}
\usepackage{amsmath}
\usepackage{xparse}
\newtoggle{with_solution}
\newsavebox\tempbox
\NewDocumentCommand{\solution}{+m}{
\iftoggle{with_solution}{
\par\medskip\noindent\textbf{Solution:} #1
}
{
% \sbox\tempbox{#1}
\begin{lrbox}\tempbox
#1
\end{lrbox}
}
}
% \problem and \subproblem cut to bare bones for simplicity
\newcommand{\problem}[1]{\section{#1}}
\newcounter{subproblem}
\newcommand{\subproblem}{\par\medskip\noindent\stepcounter{subproblem}{\bfseries\alph{subproblem})}\quad}
\toggletrue{with_solution} % Set to true to include solution
%\togglefalse{with_solution} % Set to false to exclude solution
\begin{document}
\problem{A Problem}
\subproblem Problem Formulation
\solution{Solution}
\subproblem Problem Formulation with \eqref{eq:prb}
\begin{equation}\label{eq:prb}
a=b
\end{equation}
\solution{Solution with \eqref{eq:sol}
\begin{equation}\label{eq:sol}
x=y
\end{equation}
}
\subproblem Problem Formulation with \eqref{eq:prb2}, having the same number both with or without typesetting the solutions.
\begin{equation}\label{eq:prb2}
\mathrm{e}^{2\pi\mathrm{i}}=1
\end{equation}
\solution{The \texttt{$\backslash$solution}-macro should be able to handle \texttt{$\backslash$par}'s, figures, tables, listings (and also increase their counters accordingly, even when not typeset)...}
\end{document}
답변1
또 다른 방법
\NewDocumentCommand{\solution}{+m}{
\iftoggle{with_solution}
{\par\medskip\noindent\textbf{Solution:} #1\par}
%{\setbox\tempbox=\vbox{#1}}} % this line comes from egreg's comment
% The following line is my alternative
{\par\vbox to0cm{\vspace*{\paperheight}\medskip\noindent\textbf{Solution:} #1\vspace*{-\paperheight}}\par}}
출력 루틴 중에 다음과 같은 명령이 \addtocontents
실행된다는 점에 유의하세요. 그러므로 내 대답에는 \listoffigure
표시 여부에 관계없이 모든 수치가 포함되어 있습니다. (실제로 표시됩니다 ...) egreg의 답변이 생성되는 동안\listofshownfigure
.
간격을 위해
부정적인 공백을 다루는 것은 재미가 없습니다. 나는 그것을 제쳐두고 싶습니다. 실험에 따르면 다음 \par\marginpar{}\par
과 같이 동작합니다 \par
.
\NewDocumentCommand{\solution}{+m}{
\iftoggle{with_solution}
{\par\medskip\noindent\textbf{Solution:} #1\par}
%{\setbox\tempbox=\vbox{#1}}} % this line comes from egreg's comment
% The following line is my alternative
{\par\marginpar{\moveright\paperwidth\vbox to0cm{\medskip\noindent\textbf{Solution:} #1}}\par}}