Notice
Recent Posts
Recent Comments
Link
관리 메뉴

뛰는 놈 위에 나는 공대생

[LaTeX] 여러 줄 주석처리 본문

기타/논문작성 Writing

[LaTeX] 여러 줄 주석처리

보통의공대생 2023. 3. 16. 10:03

LaTeX는 주석처리를 하려면 주석처리하고 싶은 줄을 드래그하고 CTRL+/ 단축키를 통해 %를 추가하여 주석으로 만들 수 있다.

그런데 긴 줄의 코드를 주석처리하고 싶으면 이런 방식이 어려울 것이다. 이 글에서는 여러 줄을 한 보이게 하는 방법에 대해 다룬다.

 

1. 패키지 comment 또는 verbatim을 통해 comment 블록 생성

 

내가 찾아본 방법으로 가장 간단한 것은

 

\usepackage{verbatim}

\begin{comment}
% 주석처리할 내용
\end{comment}

 

다음과 같이 주석내용을 comment 블럭으로 감싸주는 것이다.

package verbatim도 필요하니 같이 넣어준다.

그런데 verbatim의 경우 문제가 발생할 수도 있다고 한다. 따라서 \usepackage{comment}를 사용해도 괜찮다고 한다.

 

더 advanced하게 사용하려면

\documentclass{article}
\usepackage{comment}

% uncomment to include stuff in standard comment-environment
%\includecomment{comment}

% define a mysection env which content is excluded
\excludecomment{mysection}

\begin{document}
    This text will be displayed
\begin{comment}
    This text will only be displayed, if \includecomment{comment} was given
\end{comment}
\begin{mysection}
    This text will only be displayed, if \includecomment{mysection} was given
\end{mysection}
\end{document}

위와 같이 comment나 mysection을 document이전에 배제할지, 포함할지를 결정하면 된다.

 

 

2. TeX 문법의 \iffalse 사용

\iffalse
I don't want this to happen
\fi

\iffalse로 처리해뒀다가 보이게 하고 싶으면 \iftrue로 바꿔주면 된다고 한다.

 

 


참고자료

 

https://tex.stackexchange.com/questions/87303/multi-line-block-comments-in-latex

https://tex.stackexchange.com/questions/17816/commenting-out-large-sections

Comments