
私は講義ノートのコレクションを持っていますが、その中には演習が散りばめられています。これらの演習のキーを提供したいと思います。このキーはコンパイルされたノートとは別のファイルですが、対応する 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}