> 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/questions-and-answers/60-i-have-a-lot-of-tikz-matlab2tikz-or-pgfplots-figures-so-i-m-getting-a-compilation-timeout.-can-i.md).

# tikz, matlab2tikz 또는 pgfplots 그림이 많아서 컴파일 시간 초과가 발생합니다. 내가 e

## TikZ 그래픽을 외부화하는 방법

TikZ의 [external이라는 `라이브러리를`](https://tikz.dev/library-external) 사용하여 TikZ 그림을 PDF 파일로 만들고 저장(캐시)하는데, 이 과정은 종종 “*외부화*”라고 합니다.

다음 명령으로 라이브러리를 불러오세요. `\usetikzlibrary{external}`그다음 다음 명령을 사용해 외부화를 활성화합니다. `\tikzexternalize`:

```latex
\usetikzlibrary{external}
\tikzexternalize[<options>]
```

여기서 `<options>` 는 라이브러리를 구성하는 데 사용되는 선택적 매개변수 목록(키-값 쌍)입니다. `라이브러리를` 라이브러리.

* **참고**: Overleaf에서 TikZ 외부화가 작동하려면 `\tikzexternalize` 명령을 ***반드시*** 프로젝트의 메인 `.tex` 파일.

다음은 [TikZ 문서](https://tikz.dev/library-external):

```latex
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzexternalize[prefix=tikz/]

\begin{document}
% 이 TikZ 그림은
% 'output-figure0.pdf'라는 파일로 저장됩니다
% 'tikz' 폴더 안에
\begin{tikzpicture}

  \node {root}
    child {node {left}}
    child {node {right}
      child {node {child}}
      child {node {child}}
    };

\end{tikzpicture}

\end{document}
```

이 예제를 살펴보려면 [Overleaf에서 열어볼 수 있습니다.](https://www.overleaf.com/project/new/template/27519?id=1174669946\&templateName=Example+to+externalize+a+TikZ+graphic\&latexEngine=pdflatex\&texImage=texlive-full%3A2022.1\&mainFile=)

우리 예제의 코드는 다음 옵션을 사용합니다. `prefix=tikz/` 와 `\tikzexternalize`:

```latex
\tikzexternalize[prefix=tikz/]
```

옵션 `prefix=tikz/` 는 생성된(외부화된) 그림을 캐시하는 데 사용할 폴더 이름(여기서는 `tikz`)을 지정합니다. 이 폴더는 프로젝트에서 직접 만들어야 합니다. 그러나 LaTeX(TikZ 코드)가 그 폴더에 쓰기 전에, 그 안에는 파일이 하나 있어야 합니다. 아무 (더미) 파일이나 괜찮습니다. 예를 들어 빈 텍스트 파일 `foo.txt` 을 `tikz` 폴더에 추가할 수 있습니다.

Overleaf는 외부화된 TikZ PDF 그래픽을 생성된 출력 파일로 취급하므로 프로젝트의 보이는 파일 목록에는 나타나지 않습니다. 프로젝트 안에는 존재하지만 보이지 않을 뿐입니다. 이를 보려면 [생성된 파일](/latex/ko/knowledge-base/150-view-generated-files.md) 목록을 확인하면 됩니다.

다음의 (짧은) 동영상 클립은 위 예제의 컴파일 과정을 요약하고, TikZ가 생성한 파일 목록에 접근하는 방법을 보여줍니다:

{% embed url="<https://videos.ctfassets.net/nrgyaltdicpt/6VZVoHzhpNzOWSTvsWYm08/80d178255345da83bcd82b5fc64e5c6b/TikZExternalize.mp4>" %}

## 몇 가지 참고 사항

TikZ 그래픽을 외부화하는 것은 기반 TeX 엔진(pdfTeX, XeTeX, LuaTeX 등)에 계산적으로 부담이 될 수 있으므로 `라이브러리를` 라이브러리에는 이 과정을 “최적화”하는 옵션이 있습니다. 최적화를 활성화하면 TikZ는 일부 복잡한(비용이 큰) 하지만 (TikZ에) 필수적이지는 않은 명령을 “무시”함으로써 작업량을 줄이려고 시도합니다. 즉, 그것들을 (즉석에서) 재정의합니다. 또한 다른 패키지의 일부 명령은 외부화 모드에서 오류를 일으킬 수 있습니다. 예를 들어 `\includepdf` 는 `pdfpages` 패키지의 명령입니다. 이를 피하려면 이런 명령을 “최적화에서 제외”해야 합니다:

```latex
\tikzexternalize[prefix=tikz/,optimize command away=\includepdf]
```

## 외부화할 복잡한 그래픽이 너무 많습니다!

그래픽이 복잡하거나/그리고 수가 많다면, 처음 컴파일하는 동안 Overleaf [컴파일 시간 초과](/latex/ko/knowledge-base/038-fixing-and-preventing-compile-timeouts.md#compiletimeout) 를 겪을 가능성이 큽니다. 이는 외부화된 파일들이 생성되는 동안 발생합니다. 이 섹션에서는 컴파일 시간 초과를 피하기 위한 몇 가지 가능한 우회 방법을 소개합니다.

### 점진적으로 빌드하기

프로젝트를 [주석 처리하여](https://ctan.org/pkg/comment?lang=en) 다양한 부분으로 나누어 점진적으로 빌드하면 도움이 될 수 있지만, 생성된 모든 파일은 서버에서 일정 간격으로 가비지 컬렉션된다는 점을 기억하세요. 그러면 다음에 로그인했을 때 프로젝트가 컴파일되지 않을 수 있고, 모든 파일을 다시 점진적으로 생성해야 할 수도 있습니다.

### 그림을 로컬에서 생성하기

* **참고**: 이 섹션은 프로젝트가 `\tikzexternalize[prefix=tikz/]` 를 사용해 생성된 그래픽을 다음이라는 폴더에 캐시한다고 가정합니다. `tikz`.

우회 방법으로는 [Overleaf 프로젝트를 다운로드한 다음](/latex/ko/knowledge-base/036-exporting-your-work-from-overleaf.md) 로컬 머신에서 컴파일하여 그래픽 파일을 외부화(생성)하면 됩니다. 컴파일이 끝나면 `tikz` 폴더에는 생성된 각 그래픽에 대해 여러 파일 형식이 있어야 하며, 여기에는 다음이 포함됩니다. `*somegraphic*.pdf`, `*somegraphic*.md5` 및 `*somegraphic*.dpth`. 이 파일들을 Overleaf 프로젝트의 `tikz` 폴더에 업로드하면 컴파일 중에 사용되며, 이제 매우 빨라질 것입니다. 이 파일들은 업로드된 것이지 생성된 것이 아니므로 서버에서 삭제되지 않습니다. 업로드된 파일은 절대 가비지 컬렉션되지 않습니다.

* **참고(그래픽 파일 이름)**: Overleaf는 `\jobname` 에서 `출력`를 설정하며, 이는 외부화된(생성된) TikZ 그래픽의 이름에 영향을 줍니다. 기본적으로 생성된 그래픽 파일의 이름은 `output-figureN.EXT` 여기서
  * `N` 는 그래픽이 나타나는 순서/배열에서 도출된 정수이며(`N`=0, 1, 2, ...);
  * `EXT` 는 TikZ에서 사용하는 파일 확장자 중 하나로, 다음을 포함합니다. `pdf`, `md5` 및 `dpth` (또한 `log`).
* **주의 사항**: 그래픽 파일을 업로드한 뒤 프로젝트의 TikZ 코드를 변경하면, Overleaf가 새 버전을 생성하고 사용할 수 있도록 `tikz` 폴더에 있는 해당 그래픽 파일을 삭제해야 할 수 있습니다. 또는 로컬 머신에서 파일을 다시 생성한 뒤 Overleaf에 다시 업로드할 수도 있습니다. 해당 TikZ 그림의 모든 `.pdf`, `.md5` 및 `.dpth` 파일을 교체해야 한다는 점을 기억하세요.

### 별도의 프로젝트에서 그림 생성하기

또 다른 방법은 TikZ 그림만 포함된 별도의 그래픽 전용 프로젝트를 만드는 것입니다. 그 그림들이 완성되면 다음과 같이 그 별도 프로젝트의 PDF를 메인 프로젝트에 업로드할 수 있습니다:

* 파일 목록 패널 위에 있는 파일 업로드 아이콘(![Overleaf file upload icon](/files/39b637c883c2cc64d9210ead5eda2b635d48a8dc))을 클릭합니다.
* 선택 **다른 프로젝트에서**;
* 드롭다운 목록에서 TikZ 그림이 들어 있는 프로젝트를 선택하고;
* 선택 **출력 파일에서**;
* 선택하세요 **output.pdf** 를 고르고(선택 사항) 업로드된 파일 이름을 지정합니다.

업로드가 끝나면, 업로드된 PDF의 적절한 페이지를 선택해 개별 그림에 접근할 수 있습니다. 예를 들어 다음과 같은 명령으로 할 수 있습니다:

```latex
\includegraphics[page=1]{tikzpics.pdf}
```

이 [이 글 끝의 동영상](#videodemo) 은 별도의 프로젝트에서 PDF를 업로드하는 방법을 보여줍니다.

#### 별도의 그래픽 프로젝트를 만드는 방법

다음을 사용하세요 `standalone` 또는 `미리보기` 패키지를 사용해 TikZ 그림만 포함된 별도의 프로젝트를 만드세요. 출력 PDF에는 그래픽 크기에 맞게 가장자리가 잘린 페이지가 들어갑니다.

**예: standalone 패키지**

다음은 `standalone` 패키지를 사용하는 샘플 코드입니다:

```latex
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\node[fill=yellow]{Hello!};
\end{tikzpicture}

\begin{tikzpicture}
\node[fill=pink]{World!};
\end{tikzpicture}
\end{document}
```

[이 예제를 Overleaf에서 열기](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+standalone+package+and+TikZ\&snip=%5Cdocumentclass%5Btikz%5D%7Bstandalone%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Btikzpicture%7D%0A%5Cnode%5Bfill%3Dyellow%5D%7BHello%21%7D%3B%0A%5Cend%7Btikzpicture%7D%0A%0A%5Cbegin%7Btikzpicture%7D%0A%5Cnode%5Bfill%3Dpink%5D%7BWorld%21%7D%3B%0A%5Cend%7Btikzpicture%7D%0A%5Cend%7Bdocument%7D)

이 예제는 다음과 같은 출력을 생성합니다:

![standalone LaTeX 패키지의 예](/files/03b4a8dc04c85687f62bc98683d3bb17411d62ed)

**예: preview 패키지**

다음은 `미리보기` 패키지를 사용하는 샘플 코드입니다:

```latex
\documentclass{article}
\usepackage[active,tightpage]{preview}
\setlength{\PreviewBorder}{0pt}
\usepackage{tikz}
\PreviewEnvironment[{[]}]{tikzpicture}
\begin{document}
\begin{tikzpicture}
\node[fill=yellow]{Hello!};
\end{tikzpicture}

\begin{tikzpicture}
\node[fill=pink]{World!};
\end{tikzpicture}
\end{document}
```

[이 예제를 Overleaf에서 열기](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+the+preview+package+and+TikZ\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bactive%2Ctightpage%5D%7Bpreview%7D%0A%5Csetlength%7B%5CPreviewBorder%7D%7B0pt%7D%0A%5Cusepackage%7Btikz%7D%0A%5CPreviewEnvironment%5B%7B%5B%5D%7D%5D%7Btikzpicture%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Btikzpicture%7D%0A%5Cnode%5Bfill%3Dyellow%5D%7BHello%21%7D%3B%0A%5Cend%7Btikzpicture%7D%0A%0A%5Cbegin%7Btikzpicture%7D%0A%5Cnode%5Bfill%3Dpink%5D%7BWorld%21%7D%3B%0A%5Cend%7Btikzpicture%7D%0A%5Cend%7Bdocument%7D)

이 예제는 다음과 같은 출력을 생성합니다:

![preview LaTeX 패키지의 예](/files/488307f76a48aed070255d0a67cffe9c4e54753a)

### 동영상 데모: 다른 Overleaf 프로젝트에서 파일 업로드

다음 동영상은 그래픽만 포함된 PDF 파일(다른 Overleaf 프로젝트에서)을 업로드하는 방법을 보여줍니다. 여기서는 `standalone` 패키지를 사용해 TikZ 기반 일러스트레이션이 포함된 PDF를 만듭니다.

{% embed url="<https://videos.ctfassets.net/nrgyaltdicpt/6l4dDatlnqzIymJLofSnQP/61f8ad4b872f5a82f3cd45c487e2f101/TikzSeparateProjects.mp4>" %}


---

# 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/questions-and-answers/60-i-have-a-lot-of-tikz-matlab2tikz-or-pgfplots-figures-so-i-m-getting-a-compilation-timeout.-can-i.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.
