Introduction
이 시리즈에서 내가 가장 강조하고 싶은 내용이 바로 이것이다: LaTeX에서 한 문장당 한 줄에 쓸 것.
LaTeX을 처음 접하는 사람들은 대부분 Microsoft Word처럼 한 문단을 하나의 덩어리로 주저리주저리 이어서 쓴다. 하지만 LaTeX은 Word가 아니다. LaTeX은 compile 언어이다. C++이나 Python처럼 ‘코딩’하는 것이다. C++ 코드를 짤 때 한 줄에 여러 statement를 이어 쓰는 사람이 어디 있는가? LaTeX도 마찬가지이다.
Word처럼 쓰면 안 되는 이유
먼저, 대부분의 사람들이 LaTeX을 어떻게 쓰는지 보자.
Word 스타일 (잘못된 예시)
LiDAR-based simultaneous localization and mapping (SLAM) is a fundamental technology for autonomous robots. It enables robots to build maps of unknown environments while simultaneously estimating their own pose. However, existing approaches often struggle with dynamic environments where moving objects corrupt the map quality. In this paper, we propose a novel approach that addresses this limitation by leveraging temporal consistency of static structures.
한 문단이 통째로 한 덩어리다. 이게 왜 문제인지, 아래에서 하나씩 살펴보겠다.
코드 스타일 (올바른 예시)
LiDAR-based simultaneous localization and mapping (SLAM) is a fundamental technology for autonomous robots.
It enables robots to build maps of unknown environments while simultaneously estimating their own pose.
However, existing approaches often struggle with dynamic environments where moving objects corrupt the map quality.
In this paper, we propose a novel approach that addresses this limitation by leveraging temporal consistency of static structures.
compile 결과물은 완전히 동일하다.
LaTeX은 빈 줄(\n\n)이 나올 때만 문단을 나누기 때문에, 한 줄에 한 문장을 쓰든 통으로 쓰든 PDF 출력은 같다.
그런데 소스 코드 관점에서는 천지 차이이다.
한 줄에 한 문장씩 써야 하는 이유
1. Git Diff의 가독성
이 글에서 가장 핵심적인 이유이다.
논문을 쓰다가 두 번째 문장의 “simultaneously”를 “concurrently”로 바꿨다고 해보자.
Word 스타일로 작성한 경우의 git diff:
- LiDAR-based simultaneous localization and mapping (SLAM) is a fundamental technology for autonomous robots. It enables robots to build maps of unknown environments while simultaneously estimating their own pose. However, existing approaches often struggle with dynamic environments where moving objects corrupt the map quality. In this paper, we propose a novel approach that addresses this limitation by leveraging temporal consistency of static structures.
+ LiDAR-based simultaneous localization and mapping (SLAM) is a fundamental technology for autonomous robots. It enables robots to build maps of unknown environments while concurrently estimating their own pose. However, existing approaches often struggle with dynamic environments where moving objects corrupt the map quality. In this paper, we propose a novel approach that addresses this limitation by leveraging temporal consistency of static structures.
단어 하나 바꿨을 뿐인데, 문단 전체가 변경된 것으로 표시된다. 4줄짜리 문단에서 어디가 바뀌었는지 찾으려면 두 눈 부릅뜨고 한 글자씩 비교해야 한다.
코드 스타일로 작성한 경우의 git diff:
LiDAR-based simultaneous localization and mapping (SLAM) is a fundamental technology for autonomous robots.
- It enables robots to build maps of unknown environments while simultaneously estimating their own pose.
+ It enables robots to build maps of unknown environments while concurrently estimating their own pose.
However, existing approaches often struggle with dynamic environments where moving objects corrupt the map quality.
In this paper, we propose a novel approach that addresses this limitation by leveraging temporal consistency of static structures.
딱 바뀐 문장만 표시된다. 어디가 수정되었는지 0.5초 만에 파악할 수 있다.
2. 협업 시 Conflict 최소화
공저자와 함께 논문을 작성할 때, Word 스타일로 쓰면 비극이 발생한다.
예를 들어, A가 첫 번째 문장을 수정하고 B가 세 번째 문장을 수정했다고 하자. 서로 다른 문장을 건드렸으니 conflict가 없어야 정상이다.
Word 스타일: 문단이 한 줄이므로, Git 입장에서는 같은 줄을 두 사람이 수정한 것이다. Merge conflict 발생. 수동으로 해결해야 한다.
코드 스타일: 각각 다른 줄을 수정했으므로, 자동 merge 성공. Conflict 없이 깔끔하게 합쳐진다.
논문 deadline 전날, 공저자들이 각자 맡은 section을 마무리하면서 push하는 상황을 생각해보면, 이 차이가 얼마나 큰지 체감될 것이다.
3. 문장 단위 수정이 편하다
한 줄에 한 문장이면 다음과 같은 작업들이 매우 쉬워진다:
- 문장 삭제/주석 처리: 해당 줄에
%만 붙이면 끝 - 문장 순서 변경: 줄을 잘라서 옮기면 끝 (vim에서는
dd로 잘라서p로 붙여넣기) - 문장 길이 파악: 한 줄이 지나치게 길면, 그 문장이 너무 복잡하다는 신호
- LaTeX 주석으로 메모:
% TODO: 이 문장 다시 확인을 해당 줄 바로 위에 적을 수 있음
4. Latexdiff와의 궁합
교수님께 수정본을 드릴 때 Latexdiff를 쓰면 이전 버전과 현재 버전의 차이를 PDF에서 시각적으로 보여줄 수 있다. 이때 한 줄에 한 문장씩 작성되어 있으면, latexdiff가 문장 단위로 깔끔하게 차이를 표시해준다. 반면 Word 스타일로 쓰면 문단 전체가 변경으로 잡혀서 diff가 난잡해진다.
실제 예시
아래는 KISS-Matcher를 작성할 때의 실제 LaTeX 소스의 한 부분이다:
Our objective is to align two unordered voxelized point clouds with a voxel size $v$,
namely the source~$\srccloud$ and target~$\tgtcloud$ point clouds.
To this end, we establish correspondences between the two point clouds,
which is followed by robust estimation to suppress the undesirable effect of outliers.
각 문장이 한 줄에 하나씩 작성되어 있고, 너무 긴 문장은 적절히 줄바꿈했다.
이렇게 쓰면 git log에서 어떤 문장이 언제 수정되었는지도 git blame으로 추적할 수 있다.
정리
| Word 스타일 | 코드 스타일 (한 줄에 한 문장) | |
|---|---|---|
| Git diff | 문단 전체가 변경으로 표시 | 수정된 문장만 표시 |
| Merge conflict | 같은 문단 수정 시 conflict | 다른 문장이면 자동 merge |
| 문장 수정 | 문단 속에서 찾아야 함 | 해당 줄만 수정 |
| Latexdiff | 문단 단위 diff (난잡) | 문장 단위 diff (깔끔) |
| PDF 출력 | 동일 | 동일 |
PDF 출력은 완전히 동일한데, 소스 관리의 효율성은 비교할 수 없을 만큼 차이가 난다. LaTeX은 코드다. 한 줄에 한 문장씩, 코드처럼 작성하자.
실제로 나는 24년부터 논문 writing도 vim으로 하는 걸로 완전히 정착했다. LaTeX은 ‘코딩’이다!
다음 글에서는 human error를 방지하는 가장 효과적인 무기, \newcommand 활용법에 대해 다루겠다.
LaTex을 통한 심화 논문 작성법 시리즈입니다.