> 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/texlive/ko/package-related/minted.md).

# {Minted}

이 글에서는 다음을 사용하는 방법을 보여줍니다 [`minted` 패키지](https://ctan.org/pkg/minted?lang=en) LaTeX 문서 안에서 프로그래밍 언어 소스 코드를 서식 지정하고 강조 표시하는 방법을 예제로 시작하여 보여줍니다:

```latex
\documentclass{article}
\usepackage{minted}
\begin{document}
\begin{minted}{python}
import numpy as np
    
def incmatrix(genl1,genl2):
    m = len(genl1)
    n = len(genl2)
    M = None # 인시던스 행렬이 되도록
    VT = np.zeros((n*m,1), int)  # 더미 변수
    
    # 비트 단위 xor 행렬을 계산
    M1 = bitxormatrix(genl1)
    M2 = np.triu(bitxormatrix(genl2),1) 

    for i in range(m-1):
        for j in range(i+1, m):
            [r,c] = np.where(M2 == M1[i,j])
            for k in range(len(r)):
                VT[(i)*n + r[k]] = 1;
                VT[(i)*n + c[k]] = 1;
                VT[(j)*n + r[k]] = 1;
                VT[(j)*n + c[k]] = 1;
                
                if M is None:
                    M = np.copy(VT)
                else:
                    M = np.concatenate((M, VT), 1)
                
                VT = np.zeros((n*m,1), int)
    
    return M
\end{minted}
\end{document}
```

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

<p align="center"><img src="https://sharelatex-wiki-cdn-671420.c.cdn77.org/learn-scripts/images/f/f0/OLV2minted.png" alt="Example displaying the output of the minted package"></p>

여기에는 두 가지 중요한 명령이 있습니다. 서문에서는 패키지를 다음과 같이 가져옵니다

```latex
\usepackage{minted}
```

그런 다음 태그 `\begin{minted}{python}` 와 `\end{minted}` 는 텍스트를 고정폭 글꼴로 그대로 출력하고, 주석, 키워드, 함수에도 색을 적용하는 환경을 구분합니다. 매개변수 `python` 는 소스 코드가 작성된 프로그래밍 언어입니다. `minted` 는 150개가 넘는 프로그래밍 및 마크업 언어와 설정 파일을 지원합니다. 지원되는 언어 목록은 [참조 가이드](https://www.overleaf.com/learn/latex/Code_Highlighting_with_minted#Reference_guide) 를 확인하세요.

**참고**: `minted` 가 작동하려면 *로컬* LaTeX 배포판에서, 다음과 같은 추가 프로그램인 [Pygments](https://pygments.org/) 를 설치해야 합니다. [Overleaf는](https://www.overleaf.com/) 을 설치하고 문서를 컴파일하기 위해 특별한 명령을 실행해야 하는 번거로움을 덜어줄 수 있습니다. Overleaf에서는 `minted` 를 사용하는 문서가 바로 사용할 수 있습니다.

### 기본 사용법

다음 예제에서 보이듯이, `minted` 환경은 조판된 코드의 시각적 표현을 수정하도록 구성할 수 있습니다. 여기서 `minted` 환경은 다음 형식의 쉼표로 구분된 여러 매개변수를 사용합니다 `key=value`:

```latex
\documentclass{article}
\usepackage{minted}
\usepackage{xcolor} % 이름이 지정된 색 LightGray에 접근하기 위해
\definecolor{LightGray}{gray}{0.9}
\begin{document}
\begin{minted}
[
frame=lines,
framesep=2mm,
baselinestretch=1.2,
bgcolor=LightGray,
fontsize=\footnotesize,
linenos
]
{python}
import numpy as np
    
def incmatrix(genl1,genl2):
    m = len(genl1)
    n = len(genl2)
    M = None # 인시던스 행렬이 되도록
    VT = np.zeros((n*m,1), int)  # 더미 변수
    
    # 비트 단위 xor 행렬을 계산
    M1 = bitxormatrix(genl1)
    M2 = np.triu(bitxormatrix(genl2),1) 

    for i in range(m-1):
        for j in range(i+1, m):
            [r,c] = np.where(M2 == M1[i,j])
            for k in range(len(r)):
                VT[(i)*n + r[k]] = 1;
                VT[(i)*n + c[k]] = 1;
                VT[(j)*n + r[k]] = 1;
                VT[(j)*n + c[k]] = 1;
                
                if M is None:
                    M = np.copy(VT)
                else:
                    M = np.concatenate((M, VT), 1)
                
                VT = np.zeros((n*m,1), int)
    
    return M
\end{minted}
\end{document}
```

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

<p align="center"><img src="https://sharelatex-wiki-cdn-671420.c.cdn77.org/learn-scripts/images/f/ff/OLV2minted2.png" alt="Example applying formatting to typeset code produced by the minted package"></p>

이 예제에서 사용된 매개변수는 다음과 같습니다:

* `frame=lines`: 코드의 위와 아래에 각각 한 줄씩 두 줄을 그려 테두리를 만듭니다. 사용할 수 있는 다른 값은 `leftline`, `topline`, `bottomline` 와 `single`.
* `framesep=2mm`: 프레임 간격을 2mm로 설정합니다. 다른 [길이 단위](https://www.overleaf.com/learn/latex/Lengths_in_LaTeX) 를 사용할 수 있습니다.
* `baselinestretch=1.2`: 코드의 줄 간격을 1.2로 설정합니다.
* `bgcolor=LightGray`: 배경색을 `LightGray`로 설정합니다. 이 기능을 사용하려면 `xcolor` 패키지를 가져와야 합니다. 다음을 참조하세요: [LaTeX에서 색 사용하기](https://www.overleaf.com/learn/latex/Using_colours_in_LaTeX) 에서 색 조작에 대해 자세히 알아보세요.
* `fontsize=\footnotesize`: 글꼴 크기를 `footnotesize`로 설정합니다. 다른 [글꼴 크기](https://www.overleaf.com/learn/latex/Font_sizes_and_kinds%23Reference_guide) 도 설정할 수 있습니다.
* `linenos`: 줄 번호를 표시합니다.

유용할 수 있는 다른 옵션은 다음과 같습니다:

* `mathescape`: 코드 주석에서 수학 모드를 사용할 수 있게 합니다.
* `rulecolor`: 프레임 색상을 변경합니다.
* `showspaces`: 공백을 보이게 하는 특수 문자를 표시합니다.

### 파일에서 코드 포함하기

코드는 보통 소스 파일에 저장되므로, 파일에서 코드를 자동으로 가져오는 명령은 매우 편리합니다. 다음 예제에서 이를 보여줍니다:

```latex
\documentclass{article}
\usepackage{minted}
\title{minted를 사용하여 파일 가져오기}
\begin{document}
다음 코드는 파일에서 직접 가져옵니다:

\inputminted{octave}{BitXorMatrix.m}
\end{document}
```

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

<img src="https://sharelatex-wiki-cdn-671420.c.cdn77.org/learn-scripts/images/c/c8/OLV2mintedinput.png" alt="minted를 사용하여 코드 파일 가져오기" height="392" width="600">

명령 `\inputminted{octave}{BitXorMatrix.m}` 는 다음 파일에서 코드를 가져옵니다 `BitXorMatrix.m`, 매개변수 `octave` 는 LaTeX에 코드의 프로그래밍 언어를 알려줍니다. 이 명령은 파일의 일부만 가져오기 위해 두 개의 추가 매개변수를 받을 수 있습니다. 예를 들어 2번째 줄부터 12번째 줄까지의 코드를 가져오려면 명령은 다음과 같습니다:

```latex
\inputminted[firstline=2, lastline=12]{octave}{BitXorMatrix.m}
```

### 한 줄 코드

코드 한 줄만 입력해야 한다면, 다음 명령 `\mint`을 사용하면 됩니다. 그 문법은 다음 예제에서 제시됩니다.

{% code overflow="wrap" %}

```latex
한 줄 코드 서식 지정은 \texttt{minted}에서도 작동합니다. 예를 들어 다음과 같은 작은 HTML 조각:
\mint{html}|<h2>무언가 <b>여기</b></h2>|
\noindent를 올바르게 서식 지정할 수 있습니다.
```

{% endcode %}

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

<img src="https://sharelatex-wiki-cdn-671420.c.cdn77.org/learn-scripts/images/d/d9/OLV2mintedHTML.png" alt="minted를 사용한 한 줄 코드 예제" height="112" width="600">

중괄호 사이의 매개변수는 프로그래밍 언어(`html` 이 경우에는 마크업 언어)를 설정하며, 실제로 서식 지정할 텍스트는 '|' 문자로 구분됩니다.

### 셀프 호스팅 Overleaf의 문제

샌드박스 컴파일과 Overleaf 서버를 함께 사용하여 Overleaf를 배포하는 경우, minted가 제대로 작동하지 않을 수 있습니다. 자세한 정보는 다음을 참조하세요: [issues/131](https://github.com/yu-i-i/overleaf-cep/issues/131). minted가 동작하려면 ARM instruction profile과 일부 시스템 호출을 활성화해야 합니다.


---

# 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/texlive/ko/package-related/minted.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.
