라텍스에서 새로운 명령 중 일부가 컴파일되는 것을 방지하는 방법

라텍스에서 새로운 명령 중 일부가 컴파일되는 것을 방지하는 방법

\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

그래서 내 질문은 다음과 같습니다.

  1. 해당 명령을 개선할 수 있는 방법이 있나요?
  2. 컴파일할 때 두 가지 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}'

main.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}

관련 정보