
我正在為我的學生編寫考試,並定義了 3 個命令來插入空格,並\dotfill
允許他們寫下自己的答案:\rep
, \replarge
,\repLarge
用於簡短和大的答案:
\newcommand{\rep}{\noindent \dotfill
\noindent\dotfill
\noindent\dotfill
\noindent\dotfill
}
\newcommand{\repshort}\rep \rep
\newcommand{\repLarge}\rep \rep \rep \rep
所以,我的問題是:
- 有什麼辦法可以改善這些命令嗎?
- 編譯時如何產生兩個pdf版本:一個有指令產生的空格,另一個不帶空格?
答案1
這是第二個問題的一個快速而骯髒的解決方案以及更高級解決方案的連結(上面的評論還包含兩個問題的有用連結):
a) 建立兩個主文件,在其中 (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}