> 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/52-using-luatex-to-run-tools-and-utilities-installed-on-overleaf-s-servers.md).

# LuaTeX를 사용해 Overleaf 서버에 설치된 도구와 유틸리티 실행하기

## Overleaf의 서버: 소프트웨어 실행 및 구동

Overleaf의 강력한 서버는 다음을 기반으로 한 샌드박스에서 프로젝트를 컴파일합니다 [Docker의 Linux 컨테이너 기술](https://www.docker.com/). 각 프로젝트는 자체 샌드박스를 가지며, 이를 통해 프로젝트 컴파일의 일부로 우리가 실행하는 모든 코드는 다른 프로젝트와 분리됩니다. 이는 프로젝트를 안전하게 컴파일하기 위해 사용하는 여러 보호 계층 중 첫 번째입니다. TeX 사용자에게 이는 서버에 들어 있는 도구와 유틸리티에 안전하게 접근하고 사용할 수 있다는 뜻입니다. 하지만 어떻게 할 수 있을까요? 이 짧은 글에서는 LuaTeX를 통해 Lua 스크립트를 사용하여 외부 프로그램을 실행하고, 일반적으로 터미널 창에 출력되는 모든 텍스트를 캡처하는 방법을 보여줍니다. 예를 들어, 다음을 사용하여 일부 DVI 파일을 SVG로 변환하는 데 관심이 있다고 가정해 봅시다 `dvisvgm` 유틸리티를 사용하고 싶지만 다양한 명령줄 옵션이 기억나지 않는다면 어떨까요? 기억을 되살리기 위해 옵션 목록을 빠르게 조판할 수 있으면 좋지 않을까요? 그렇다면 계속 읽어 보세요. 하지만 실제 동작을 먼저 보고 싶다면 이곳으로 이동해 [갤러리 프로젝트 예시](https://www.overleaf.com/latex/examples/using-luatex-to-run-software-installed-on-overleafs-servers/nnvfvnfhzwsy) 에서 어떻게 하는지 확인해 보세요.

![Overleaf 프로젝트의 스크린샷](/files/b2af47f9fe294dbec0fbbc6b98acd1510f6fd15b)

### LuaTeX를 사용하여 Lua 스크립트를 통해 외부 프로그램 실행하기

LuaTeX에는 Lua 스크립트 언어가 TeX 엔진에 내장되어 있으므로, 외부 프로그램을 실행할 뿐만 아니라 그 프로그램이 일반적으로 터미널 창에 출력했을 텍스트를 캡처하여 파일로 저장하는 짧은 스크립트를 작성하는 것은 거의 사소한 일입니다. 그 텍스트가 파일로 저장되면 다음을 사용하여 `verbatim` 패키지를 사용해 이를 메인 TeX 문서로 가져올 수 있습니다. LuaTeX로 이를 수행하는 데 필요한 전체 코드는 다음과 같습니다:

```latex

\documentclass{article}
\usepackage{verbatim}
\begin{document}
\directlua{
function runcommand(cmd)
local fout = assert(io.popen(cmd, 'r'))
local str = assert(fout:read('*a'))
fout:close()
return str
end

local sout=runcommand("dvisvgm --help")
local marg = assert(io.open("command.txt","w"))
marg:write(sout)
marg:flush()
marg:close()
}
\verbatiminput{command.txt}
\end{document}
```

위 코드에서 핵심 줄은 `local sout=runcommand("dvisvgm --help")` 이며, 이는 `dvisvgm` 를 다음 명령줄 옵션과 함께 실행합니다 `--help` 를 사용해 `dvisvgm` 가 모든 명령줄 옵션을 나열하도록 지시합니다. 도움말 텍스트는 캡처되어 다음 이름의 텍스트 파일에 저장됩니다 `command.txt`. Lua 코드가 `\directlua{...}` 내에서 실행을 마치면 `command.txt` 의 내용이 `\verbatiminput{command.txt}`를 사용하여 메인 TeX 문서에 삽입됩니다. 가져온 텍스트 안에 `$, #, \\, _, ^` 등과 같은 문자가 포함될 수 있으므로, 캡처된 텍스트는 반드시 그대로의 재료로 삽입하는 것이 중요합니다.

다음의 코드를 자유롭게 수정해 보세요 `runcommand("dvisvgm --help")` 그리고 GhostScript와 같은 다른 프로그램을 실행해 보거나, 사용해 보고 싶은 TeX Live 소프트웨어를 탐색해 보세요.


---

# 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/52-using-luatex-to-run-tools-and-utilities-installed-on-overleaf-s-servers.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.
