> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/ko/in-depth-articles/03-a-six-part-article-series-on-expandafter-tex-tokens-and-expansion.md).

# \expandafter, TeX 토큰, 확장에 관한 6부작 문서 시리즈

## 개요

TeX 기본 명령 `\expandafter` 는 다재다능한 명령으로, LaTeX/TeX 프로그래머들이 LaTeX 패키지가 제공하는 명령(매크로)과 같은 정교한 매크로를 만드는 데 사용한다. 표면적으로는, `\expandafter` 사용하기는 간단하지만, 여러 개가 연속으로 이어지는 것과 같은 더 복잡한 구성에 부딪히면 그 단순함의 가면은 금세 벗겨진다. `\expandafter` 각종 “토큰 주고받기”를 수행하는 데 쓰이는 명령 `...\expandafter\expandafter\expandafter...`.

이 글 연재의 목표는 야심차다: 설명하는 것이다 *어떻게* 그 `\expandafter` 명령과 TeX 확장이 실제로 어떻게 작동하는지—기본 원리부터 시작해 TeX 엔진 소프트웨어 내부 깊은 곳에서 일어나는 과정을 탐구하는 데까지—를 설명한다. 독자들은 곧바로 [글](#accessing-articles-the-navigation-bar) 또는 한 [소개](#introduction-and-who-is-this-series-for) 그리고 이 시리즈의 이유와 취지.

## 글에 접근하기: 내비게이션 바

각 글에는 본문 앞뒤에 다음 내비게이션 바가 있어 시리즈의 다른 글로 빠르게 이동할 수 있다:

[1부](/latex/ko/in-depth-articles/19-how-does-expandafter-work-an-introduction-to-tex-tokens.md) [2부](/latex/ko/in-depth-articles/22-how-does-expandafter-work-the-meaning-of-expansion.md) [3부](/latex/ko/in-depth-articles/21-how-does-expandafter-work-tex-uses-temporary-token-lists.md) [4부](/latex/ko/in-depth-articles/20-how-does-expandafter-work-from-basic-principles-to-exploring-tex-s-source-code.md) [5부](/latex/ko/in-depth-articles/17-how-does-expandafter-work-a-detailed-macro-case-study.md) [6부](/latex/ko/in-depth-articles/18-how-does-expandafter-work-a-detailed-study-of-consecutive-expandafter-commands.md)

이 시리즈의 6개 글 링크는 다음과 같다:

1. [TeX 토큰 소개](/latex/ko/in-depth-articles/19-how-does-expandafter-work-an-introduction-to-tex-tokens.md)
2. [확장의 의미](/latex/ko/in-depth-articles/22-how-does-expandafter-work-the-meaning-of-expansion.md)
3. [TeX는 임시 토큰 목록을 사용한다](/latex/ko/in-depth-articles/21-how-does-expandafter-work-tex-uses-temporary-token-lists.md)
4. [기본 원리에서 TeX의 소스 코드 탐구까지](/latex/ko/in-depth-articles/20-how-does-expandafter-work-from-basic-principles-to-exploring-tex-s-source-code.md)
5. [매크로에 대한 자세한 사례 연구](/latex/ko/in-depth-articles/17-how-does-expandafter-work-a-detailed-macro-case-study.md)
6. [연속적인 것에 대한 자세한 연구 `\expandafter` 명령](/latex/ko/in-depth-articles/18-how-does-expandafter-work-a-detailed-study-of-consecutive-expandafter-commands.md)

## 소개와 이 시리즈는 누구를 위한 것인가?

### \expandafter: 동작의 기본 원리

\expandafter의 목적은 입력된 토큰의 조기 확장을 강제로 일으키는 것이다: 입력에 연속된 두 토큰이 주어지면, $$\mathrm{T\_1}$$ 및 $$\mathrm{T\_2}$$, `\expandafter` 토큰을 저장하고 $$\mathrm{T\_1}$$, 토큰을 확장하고 $$\mathrm{T\_2}$$ 그리고 토큰을 $$\mathrm{T\_1}$$ 확장의 앞에 다시 놓는다 $$\mathrm{T\_2}$$:

$$\verb\*\expandafter\*\ \mathrm{T\_1}\mathrm{T\_2} \rightarrow \mathrm{T\_1}\text{\<expansion of }\mathrm{T\_2}\text{>}$$

의 표준 설명을 따르면 `\expandafter`’의 동작에 대해 우리는 그것이 “토큰을 저장하고 $$\mathrm{T\_1}$$”, 토큰의 “확장”을 강제로 일으키고 $$\mathrm{T\_2}$$ (TeX가 원래 그렇게 하기 전에) 그런 다음 토큰을 $$\mathrm{T\_1}$$ “다시 읽기 위해 입력으로 되돌려 놓는다”. 이 글의 저자는 다음의 몇몇 측면이 혼란스러웠다고 기억한다: `\expandafter`의 “토큰 주고받기” 동작; 특히:

* “토큰을 저장한다”거나 “토큰을 입력으로 되돌려 놓는다”는 것은 무슨 뜻인가—이렇게 저장된 토큰들은 “어디로” 가며, TeX는 그것들을 어떻게 다시 읽는가?
* 확장은 “어떻게 보이는” 것이며, 실제로 무엇을 의미하는가?
* TeX는 여러 개가 연속된 `\expandafter` 명령을 어떻게 처리하는가—그것은 *정말로* 작동하는가?

### 이 글 연재의 목표

이 연재는 TeX의 내부 작동 방식에 대한 연구 결과를 기록함으로써 위에서 제기한 질문들에 답하고자 한다. Overleaf는 TeX 엔진 중 하나의 맞춤형 버전을 만들고 다음을 사용했다 [Eclipse IDE](https://www.eclipse.org/ide/) TeX 소스 코드가 다음을 처리하는 동안 실제로 동작하는 모습을 관찰하기 위해 `.tex` 다음의 예시 사용을 담은 파일 `\expandafter`.

그 연구의 결과를 공유하여 다음을 살펴보겠다:

* TeX 토큰의 진정한 성격/의미;
* TeX가 임시 토큰 목록을 생성/사용하는 방식;
* “확장”이 실제로 무엇을 의미하는지.

이 주제들을 탐구하면서 우리는 전체 그림을 맞춰 보아 *어떻게* `\expandafter` 가 어떻게 “토큰 주고받기” 동작을 수행하는지 설명하겠다. 이 글 연재는 이러한 주제들에 대한 통찰을 얻고자 하는 누구나를 위해 쓰였다: TeX 내부를 더 깊이 들여다보고, 다음을 가능하게 하는 TeX 내부 동작의 부분들을 살펴보는 것 `\expandafter` 그 마법 같은 작동을 가능하게 한다.

TeX와 TeX 관련 개념/원리에 대한 글을 쓰는 것은 어렵다. TeX는 매우 복잡한 소프트웨어이기 때문이다—조판된 소스 코드는 수백 페이지에 이른다. 예를 들어, 이것을 보라 [Overleaf 프로젝트](https://www.overleaf.com/latex/examples/typeset-the-source-code-documentation-for-tex-e-tex-or-pdftex/qkgfgyspnhcv) 이는 기본적으로 다음의 소스 코드를 조판한다 $$\mathrm{\varepsilon}\text{-}\mathrm{\TeX}$$: 조판된 PDF 파일은 600페이지가 넘는다.

내부적으로 TeX는 서로 얽힌 동작과 과정의 복잡한 그물망으로, 그 동작의 고립된 측면을 논하려고 할 때 어려움을 준다: 다음과 같은 특정 “구성 요소”를 떼어내어 `\expandafter`, 그리고 TeX 소프트웨어의 다른 측면을 계속 참조하지 않고 설명하려는 시도. 그 본성상 `\expandafter` 명령은 TeX의 다음 과정과 관련된다 *확장*—이 과정은 우리 중 많은 사람에게 모호하고 다소 이해하기 어려운 개념이다. 그러나 확장은 TeX 동작의 진정한 기본 요소로, TeX의 내부 작동 전반에 깊이 얽혀 있으며 TeX 소프트웨어 내부 깊숙한 곳에서 일어난다. 이 글 연재에서는 확장의 실제 의미를 탐구할 것이다. 먼저 확장을 기본적으로 이해하는 데 충분한 관련 원리와 동작들을 모아 시작하고, 그 토대 위에서 마지막에는 TeX 내부를 들여다보는 “딥 다이브”를 통해 TeX의 확장 메커니즘을 구현하는 실제 소스 코드를 살펴볼 것이다.

## 결론적으로

이 글들에서는 가능한 한 많은 독자에게 유익/가치가 있거나 흥미로운 내용을 제공하고자 노력했다: 피할 수 없는 세부사항과 간결함 사이의 균형을 맞추면서, 동시에 독자에게 맥락 자료를 너무 많이도 너무 적게도 제공하지 않아 인내심을 시험하지 않으려 했다. 현재와, 어쩌면 미래의 TeX 공동체 구성원들이 즐겁게 읽을 수 있는 TeX 문헌에 무언가 유익/가치 있는 기여를 했기를 바란다.

즐거운 $$\mathrm{\TeX}\text{ing!}$$, Graham Douglas와 Overleaf 팀으로부터.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/ko/in-depth-articles/03-a-six-part-article-series-on-expandafter-tex-tokens-and-expansion.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
