
나는 연습문제가 곳곳에 흩어져 있는 강의 노트 모음을 가지고 있습니다. 나는 컴파일된 노트와 별도의 파일이지만 해당 TeX 코드가 노트와 동일한 코드에 있고 연습의 출처인 장/섹션을 참조하는 이 연습의 키를 제공하고 싶습니다.
예를 들어, 강의 코드가 다음과 같다면:
\begin{document}
\chapter{Lecture 1}
...
\begin{exercise}
What is 2 + 2?
\end{exercise}
\begin{solution}
4
\end{solution}
...
\begin{exercise}
What is 2 * 3?
\end{exercise}
\begin{solution}
6
\end{solution}
\chapter{Lecture 2}
...
\begin{exercise}
How many Canadian provinces are there?
\end{exercise}
\begin{solution}
10
\end{solution}
...
\begin{exercise}
What is the capital of Nova Scotia?
\end{exercise}
\begin{solution}
Halifax
\end{solution}
\end{document}
그런 다음 강의 노트에 해당하는 PDF에는 연습, 솔루션이 포함된 강의 1과 2가 있지만 강의 1의 연습에 대한 솔루션이 포함된 별도의 PDF와 강의 2의 솔루션에 대한 또 다른 PDF가 있으며 해당 PDF는 표시된 내용을 알 수 있습니다. 해결책은 강의 1의 연습 2에서 나왔습니다.
제가 생각할 수 있는 가장 확실한 해결책은 etoolbox
의 토글을 사용하여 연습이 포함된 노트만 표시하거나 솔루션만 표시하는 것입니다. 하지만 그렇게 하면 \iftoggle
어디서나 사용할 수 있고 각 강의 솔루션의 PDF를 수동으로 생성해야 하므로 금방 지루해집니다. 여러 강의가 있거나 다시 돌아가서 문제나 강의의 번호 매기기를 변경하는 변경 작업을 수행해야 하는 경우.
(LaTeX에서 이를 수행할 수 있는 좋은 방법이 없다면 쉘 스크립트와 관련된 비-TeX 솔루션은 괜찮을 것입니다.)
답변1
다음은 사용 방법입니다.답변패키지와\includeonly
기본(드라이버) 파일myfile.tex
\documentclass{book}
\usepackage{answers}
\newtheorem{exercise}{Exercise}[chapter]
\Newassociation{solution}{Soln}{mycor}
\renewcommand{\Solnlabel}[1]{\textbf{Answer #1}}
\includeonly{Lectures}
%\includeonly{Lecture1}
%\includeonly{Lecture2}
\begin{document}
\include{Lectures}
\include{Lecture1}
\include{Lecture2}
\end{document}
메인(소스) 파일Lectures.tex
\Opensolutionfile{mycor}[Lecture1]
\chapter{Lecture 1}
...
\begin{exercise}
What is 2 + 2?
\begin{solution}
4
\end{solution}
\end{exercise}
...
\begin{exercise}
What is 2 * 3?
\begin{solution}
6
\end{solution}
\end{exercise}
\Closesolutionfile{mycor}
\Opensolutionfile{mycor}[Lecture2]
\chapter{Lecture 2}
...
\begin{exercise}
How many Canadian provinces are there?
\begin{solution}
10
\end{solution}
\end{exercise}
...
\begin{exercise}
What is the capital of Nova Scotia?
\begin{solution}
Halifax
\end{solution}
\end{exercise}
\Closesolutionfile{mycor}