숨겨진 부분의 빈 줄

숨겨진 부분의 빈 줄

텍스트에 솔루션을 삽입하기 위해 다음 환경을 정의했습니다.

\newif\ifsolution
\def\solution#1{\ifsolution {\color{blue}\textbf{Oplossing:} #1} \else \relax\fi} 

파일에 추가하면 \solutiontrue파란색으로 솔루션이 추가되지만, 을 넣으면 \solutionfalse모두 생략됩니다. 여태까지는 그런대로 잘됐다.

하지만 내가 가진 문제는 솔루션 자체에서 실제로 필요한 빈 줄을 삽입할 수 없는 것 같다는 것입니다. 예를 들어, 내가 넣으면

\solution{This is the first line of the solution.

This is the second line. QED}

오류가 발생했습니다. 대신 글을 써야 한다는 걸 이해해요

\solution{This is the first line of the solution.
This is the second line. QED}

이제 빈 줄을 놓칠 수 없다면 오류를 피할 수 있는 방법이 있습니까?

답변1

이것이 정말로 당신이 원했던 것인지 잘 모르겠습니다. 그러나 매크로 입력에 빈 줄을 허용하고 출력에서 ​​공백을 와일드카드로 유지하면서 솔루션을 생략하는 방법은 다음과 같습니다.

\documentclass{article}
\usepackage{xcolor}

\newif\ifsolution
\long\def\solution#1{%
  \setbox0\vbox{#1}
  \vbox to \ht0 {
    \ifsolution {\color{blue}\textbf{Oplossing:} #1} \else \relax\fi}}
\solutiontrue
%\solutionfalse

\setlength\parindent{0em}

\begin{document}
(before solution)

\solution{%
  This is the first line of the solution.

  This is the second line. QED
}

(after solution)
\end{document}

~와 함께\solutiontrue

아웃1

~와 함께\solutionfalse

아웃2


기본적으로 매크로 입력에서 빈 줄이 작동하지 않는 이유는 TeX 기본 사항에 있습니다. 설계상 Knuth는 매크로 매개변수의 동작을 허용하지 않았습니다. 기본 요소 를 추가해야만 \long이 문제를 극복할 수 있습니다(일부 사람들은 이를 한계라고 부릅니다). ~ 안에이 질문이 주제에 대한 좋은 토론을 찾았습니다.

답변2

귀하의 질문을 다른 방식으로 의도했습니다. 이 솔루션은 어떻습니까 \makecell?

\documentclass{article}
\usepackage{color}
\usepackage{makecell}
\newif\ifsolution
\def\solution#1{\ifsolution {\color{blue}\textbf{Oplossing:} #1} \else \relax\fi}
\solutiontrue  
\begin{document}
 \solution{\makecell[l]{This is the first line of the solution.\vspace{3ex}\\   
    This is the second line. QED}}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보