
私は生徒のために試験を作成しており、\dotfill
生徒が回答を記入できるようにスペースを挿入する 3 つのコマンドを定義しました: \rep
、\replarge
、\repLarge
は短い回答用、 は長い回答用です:
\newcommand{\rep}{\noindent \dotfill
\noindent\dotfill
\noindent\dotfill
\noindent\dotfill
}
\newcommand{\repshort}\rep \rep
\newcommand{\repLarge}\rep \rep \rep \rep
私の質問は次のとおりです。
- これらのコマンドを改善する方法はありますか?
- コンパイル時に、コマンドで生成されたスペースを含む PDF バージョンと、スペースを含まない PDF バージョンの 2 つを作成するにはどうすればよいですか?
答え1
2 番目の質問に対する簡単な解決策と、より高度な解決策へのリンクを次に示します (上記のコメントには、両方の質問に対する役立つリンクも含まれています)。
a) 2 つのメイン ファイルを作成し、(1) スペースを含むコマンドを指定し、(2) 同じコマンドを空のコマンドとして指定します (単に次のような内容を追加して\renewcommand{\rep}{}
、コメント インまたはコメント アウトすることもできます)。
または
b) ドキュメントにパラメータを使用し、Makefileを使用します。ドキュメントにパラメータを渡すインスピレーションを得るために、このような Makefile の例と、.tex ファイルでそれをどのように使用できるかを示します。
メイクファイル:
default: Exercise.pdf Solution.pdf
Exercise.pdf: *.tex
-rm Exercise.pdf
pdflatex -file-line-error --jobname=Exercise '\def\isexercise{1} \input{main.tex}'
pdflatex -file-line-error --jobname=Exercise '\def\isexercise{1} \input{main.tex}'
Solution.pdf: *.tex
-rm Solution.pdf
pdflatex -file-line-error --jobname=Solution '\input{main.tex}'
pdflatex -file-line-error --jobname=Solution '\input{main.tex}'
メイン.tex:
\documentclass{article}
\newcommand{\rep}{}
\ifdefined\isexercise
\renewcommand{\rep}{
\noindent\dotfill
\noindent\dotfill
\noindent\dotfill
\noindent\dotfill
}
\fi
\begin{document}
Exercise 1: \rep
\end{document}