> 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/class-files/04-writing-your-own-class.md).

# 자신만의 클래스 작성하기

때로는 문서를 맞춤화하는 가장 좋은 방법은 처음부터 새 클래스를 작성하는 것입니다. 이 글에서는 새 클래스에 필요한 기본 구조와 명령을 설명합니다.

## 소개

새 클래스를 코딩하기 전에 먼저 정말로 새 클래스가 필요한지 여부를 판단해야 합니다. 다음을 권장합니다. [CTAN(Comprehensive TeX Archive Network)에서](http://www.ctan.org/ctan-portal/search/) 그리고 필요한 문서 클래스와 비슷한 것을 이미 누군가 만들었는지 확인해 보세요.

또 한 가지 중요하게 염두에 둘 것은 [패키지와 클래스의 차이입니다](/latex/ko/class-files/01-understanding-packages-and-class-files.md). 잘못 선택하면 최종 결과물의 유연성에 영향을 줄 수 있습니다.

## 전체 구조

모든 클래스 파일의 구조는 대략 다음 네 부분으로 설명할 수 있습니다:

* ***식별***. 이 파일은 LaTeX2ε 문법으로 작성된 클래스임을 선언합니다.
* ***예비 선언***. 여기에서는 필요한 외부 패키지와 클래스가 불러와집니다. 또한 파일의 이 부분에서 선언된 옵션에 필요한 명령과 정의가 코딩됩니다.
* ***옵션***. 클래스가 옵션을 선언하고 처리합니다.
* ***추가 선언***. 클래스의 본문입니다. 클래스가 하는 거의 모든 내용이 여기에서 정의됩니다.

다음 소단원에서는 구조에 대한 더 자세한 설명과 함께 동작 예제인 *exampleclass.cls*를 제시합니다.

### 식별

모든 클래스에 반드시 있어야 하는 간단한 명령 두 가지가 있습니다:

```latex
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{exampleclass}[2014/08/16 Example LaTeX class]
```

명령은 `\NeedsTeXFormat{LaTeX2e}` 클래스가 동작할 수 있도록 LaTeX 버전을 설정합니다. 또한 대괄호 안에 날짜를 추가하여 필요한 최소 릴리스 날짜를 지정할 수 있습니다.

명령은 `ProvidesClass{exampleclass}[...]` 이 클래스를 다음으로 식별합니다 *exampleclass* 로 식별하며, 대괄호 안에는 릴리스 날짜와 일부 추가 정보가 포함됩니다. 날짜는 YYYY/MM/DD 형식이어야 합니다.

[Overleaf에서 클래스를 작성하는 방법의 예 열기](https://www.overleaf.com/project/new/template/19419?id=65524436\&templateName=An+example+of+writing+a+LaTeX+class\&latexEngine=\&texImage=texlive-full%3A2020.1\&mainFile=)

### 예비 선언

대부분의 클래스는 기존 클래스를 확장하고 맞춤화하며, 작동하기 위해 몇몇 외부 패키지도 필요합니다. 아래에서는 샘플 클래스에 몇 가지 코드가 더 추가됩니다. `exampleclass.cls`.

```latex
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{exampleclass}[2014/08/16 Example LaTeX class]

\newcommand{\headlinecolor}{\normalcolor}
\LoadClass[twocolumn]{article}
\RequirePackage{xcolor}
\definecolor{slcolor}{HTML}{882B21}
```

이 부분의 명령은 나중에 옵션을 관리하는 데 사용될 몇몇 매개변수를 초기화하거나 외부 파일을 불러옵니다.

명령은 `\LoadClass[twocolumn]{article}` 해당 클래스를 불러옵니다 `article` 추가 매개변수와 함께 `twocolumn`. 따라서 표준 `article` 클래스의 모든 명령은 자동으로 **예제** 해당 클래스에서 사용할 수 있지만, 문서는 두 단 형식으로 출력됩니다.

`\RequirePackage` 는 잘 알려진 `\usepackage`와 매우 비슷하며, 대괄호 안에 선택적 매개변수를 추가하는 것도 가능합니다. 유일한 차이점은 `\usepackage` 는 `\documentclass` 명령 앞에서는 사용할 수 없다는 점입니다. 새 패키지나 클래스를 작성할 때는 `\RequirePackage` 새 클래스나 패키지를 작성할 때.

[Overleaf에서 클래스를 작성하는 방법의 예 열기](https://www.overleaf.com/project/new/template/19419?id=65524436\&templateName=An+example+of+writing+a+LaTeX+class\&latexEngine=\&texImage=texlive-full%3A2020.1\&mainFile=)

### 옵션

클래스에 어느 정도 유연성을 허용하려면 몇 가지 추가 옵션이 매우 유용합니다. 파일의 다음 부분은 `exampleclass.cls` documentclass 명령에 전달된 매개변수를 처리합니다. 또한 우리는 `\LoadClass` 을 *뒤에* 옵션이 처리되므로 .tex 파일에서 설정한 옵션을 기본 클래스로 전달할 수 있습니다.

```latex
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{exampleclass}[2014/08/16 Example LaTeX class]

\newcommand{\headlinecolor}{\normalcolor}
\RequirePackage{xcolor}
\definecolor{slcolor}{HTML}{882B21}

\DeclareOption{onecolumn}{\OptionNotUsed}
\DeclareOption{green}{\renewcommand{\headlinecolor}{\color{green}}}
\DeclareOption{red}{\renewcommand{\headlinecolor}{\color{slcolor}}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\LoadClass[twocolumn]{article}
```

여기에는 클래스에 전달된 옵션을 처리하는 네 가지 주요 명령이 있습니다.

명령은 `\DeclareOption{}{}` 는 주어진 옵션을 처리합니다. 두 개의 매개변수를 가지며, 첫 번째는 옵션 이름이고 두 번째는 해당 옵션이 전달되었을 때 실행할 코드입니다.

명령은 `\OptionNotUsed` 컴파일러와 로그에 메시지를 출력하고, 해당 옵션은 사용되지 않습니다. 이 경우 문서는 두 단으로 설정되며, 사용자가 이를 한 단으로 바꾸려 해도 작동하지 않으므로 해당 옵션은 무시됩니다.

명령은 `\Declareoption*{}` 명시적으로 정의되지 않은 모든 옵션을 처리합니다. 하나의 매개변수만 받으며, 알려지지 않은 옵션이 전달되었을 때 실행할 코드를 받습니다. 이 경우 다음 명령을 실행합니다:

`\PassOptionsToClass{}{}`. 첫 번째 중괄호 안의 옵션을 두 번째 중괄호 안에 지정된 문서 클래스로 전달합니다. 예에서는 모든 알 수 없는 옵션이 다음으로 전달됩니다. **article** 문서 클래스.

`\CurrentOption` 특정 시점에 처리 중인 클래스 옵션의 이름을 저장합니다.

명령은 `\ProcessOptions\relax` 각 옵션에 대한 코드를 실행하며, 모든 옵션 처리 명령을 입력한 뒤에 삽입해야 합니다. 이 명령에는 별표 버전이 있으며, 호출 명령에서 지정한 정확한 순서대로 옵션을 실행합니다.

예제에서는 옵션 `red` 또는 `초록색` 문서에 전달되면 제목과 섹션에 사용되는 글꼴이 해당 색상으로 설정됩니다. 색상 이름은 `slcolor` 다음에서 정의되었습니다 [예비 선언](#preliminary-declaration) 에서 `xcolor` 패키지.

[Overleaf에서 클래스를 작성하는 방법의 예 열기](https://www.overleaf.com/project/new/template/19419?id=65524436\&templateName=An+example+of+writing+a+LaTeX+class\&latexEngine=\&texImage=texlive-full%3A2020.1\&mainFile=)

### 추가 선언

이 부분에는 대부분의 명령이 나타납니다. "exampleclass.cls"에서는 페이지 크기와 제목, 본문, 섹션의 글꼴 크기가 설정됩니다. 아래에서 전체 클래스 파일을 볼 수 있습니다.

```latex
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{exampleclass}[2014/08/16 Example LaTeX class]

\newcommand{\headlinecolor}{\normalcolor}
\RequirePackage{xcolor}
\definecolor{slcolor}{HTML}{882B21}

\DeclareOption{onecolumn}{\OptionNotUsed}
\DeclareOption{green}{\renewcommand{\headlinecolor}{\color{green}}}
\DeclareOption{red}{\renewcommand{\headlinecolor}{\color{slcolor}}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions\relax
\LoadClass[twocolumn]{article}

\renewcommand{\maketitle}{%
    \twocolumn[%
        \fontsize{50}{60}\fontfamily{phv}\fontseries{b}%
        \fontshape{sl}\selectfont\headlinecolor
        \@title
        \medskip
        ]%
}

\renewcommand{\section}{%
    \@startsection
    {section}{1}{0pt}{-1.5ex plus -1ex minus -.2ex}%
    {1ex plus .2ex}{\large\sffamily\slshape\headlinecolor}%
}

\renewcommand{\normalsize}{\fontsize{9}{10}\selectfont}
\setlength{\textwidth}{17.5cm}
\setlength{\textheight}{22cm}
\setcounter{secnumdepth}{0}
```

나머지 명령을 이해하려면 다음을 보세요: [참조 안내서](#reference-guide) 와 [추가 읽기 섹션의](#further-reading).

예제의 마지막 네 개 명령은 모든 클래스에 반드시 포함되어야 하는 네 가지를 보여줍니다:

* 정의는 `normalsize`. 기본값을 설정합니다 [글꼴 크기](/latex/ko/fonts/01-font-sizes-families-and-styles.md).
* 다음의 기본값 [`textwidth`](/latex/ko/formatting/07-page-size-and-margins.md)
* 다음의 기본값 [`textheight`](/latex/ko/formatting/07-page-size-and-margins.md)
* 다음에 대한 사양 [페이지 번호 매기기](/latex/ko/formatting/03-page-numbering.md).

아래는 해당 클래스를 사용하는 문서입니다 *exampleclass.cls*.

```latex
\documentclass[red]{exampleclass}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}

\usepackage{blindtext}

\title{Example to show how classes work}
\author{Team Learn ShareLaTeX}
\date{August 2014}

\begin{document}

\maketitle

\noindent
여기서 간단한 작동 예제로 시작해 봅시다.

\blindtext

\section{Introduction}

몬티 홀 문제...

\section{The same thing}

몬티...
```

![WrittingClassesEx1.png](/files/328952fa8247a6616f89bb58e0c7fe15b8b67c87)

여기서 첫 번째 명령은

```latex
\documentclass[red]{exampleclass}
```

[Overleaf에서 클래스를 작성하는 방법의 예 열기](https://www.overleaf.com/project/new/template/19419?id=65524436\&templateName=An+example+of+writing+a+LaTeX+class\&latexEngine=\&texImage=texlive-full%3A2020.1\&mainFile=)

## 오류 처리

새 클래스를 개발할 때는 사용자가 문제가 발생했음을 알 수 있도록 가능한 오류를 처리하는 것이 중요합니다. 컴파일러에서 오류를 보고하는 네 가지 주요 명령이 있습니다.

* `\ClassError{*class-name*}{*error-text*}{*help-text*}`. 중괄호 안에 각각 세 개의 매개변수를 받습니다: 클래스 이름, 표시될 오류 텍스트(컴파일 과정이 일시 중지됩니다), 그리고 오류로 인해 컴파일이 멈췄을 때 사용자가 "h"를 누르면 출력될 도움말 텍스트입니다.
* `\ClassWarning{*class-name*}{*warning-text*}`. 이 경우 텍스트는 표시되지만 컴파일 과정은 중단되지 않습니다. 경고가 발생한 줄 번호가 표시됩니다.
* `\ClassWarningNoLine{*class-name*}{*warning-text*}`. 이전 명령과 거의 같지만, 경고가 발생한 줄은 표시하지 않습니다.
* `\ClassInfo{*class name*}{*info-text*}`. 이 경우 두 번째 매개변수의 정보는 줄 번호를 포함하여 전사 파일에만 출력됩니다.

[Overleaf에서 클래스를 작성하는 방법의 예 열기](https://www.overleaf.com/project/new/template/19419?id=65524436\&templateName=An+example+of+writing+a+LaTeX+class\&latexEngine=\&texImage=texlive-full%3A2020.1\&mainFile=)

## 참조 안내서

**클래스와 패키지에서 일반적으로 사용되는 명령 목록**

* `\newcommand{*name*}{*definition*}`. [새 명령을 정의합니다](/latex/ko/commands/01-commands.md#defining-a-new-command), 첫 번째 매개변수는 새 명령의 이름이고, 두 번째 매개변수는 명령이 수행할 일입니다.
* `\renewcommand{}{}`. `\newcommand` 는 동일하지만 기존 명령을 덮어씁니다.
* `\providecommand{}{}`. `\newcommand` 와 동일하게 동작하지만, 명령이 이미 정의되어 있으면 조용히 무시됩니다.
* `\CheckCommand{}{}`. 문법은 `\newcommand`, 대신 해당 명령이 존재하고 예상한 정의를 가지고 있는지 확인합니다. 명령이 기대한 것과 다르면 LaTeX가 경고를 표시합니다 `\CheckCommand` 가 예상한 것과 다르면 LaTeX가 경고를 표시합니다.
* `\setlength{}{}`. 첫 번째 매개변수로 전달된 요소의 길이를 두 번째 매개변수에 적힌 값으로 설정합니다.
* `\mbox{}`. 중괄호 안에 적힌 요소를 담는 상자를 만듭니다.
* `\fbox{}`. `\mbox`, 하지만 내용 주위에 실제로 상자가 출력됩니다.

## 추가 읽을거리

자세한 내용은 다음을 참조하세요

* [패키지와 클래스 파일 이해하기](/latex/ko/class-files/01-understanding-packages-and-class-files.md)
* [사용자 정의 패키지 작성하기](/latex/ko/class-files/03-writing-your-own-package.md)
* [명령](/latex/ko/commands/01-commands.md) 및 [환경](/latex/ko/commands/02-environments.md)
* [LaTeX의 길이](/latex/ko/formatting/01-lengths-in-latex.md)
* [LaTeX에서 색상 사용](/latex/ko/formatting/13-using-colors-in-latex.md)
* [대규모 프로젝트에서의 관리](/latex/ko/document-structure/07-management-in-a-large-project.md)
* [클래스 및 패키지 작성자를 위한 LaTeX2ε](http://www.latex-project.org/guides/clsguide.pdf)
* [tex에서의 프로그래밍 노트](http://pgfplots.sourceforge.net/TeX-programming-notes.pdf)
* [시간보다 짧은 분: LaTeX 리소스 사용하기](https://tug.org/pracjourn/2005-4/hefferon/hefferon.pdf)
* [The LaTeX Companion. 제2판](http://ptgmedia.pearsoncmg.com/images/9780201362992/samplepages/0201362996.pdf)


---

# 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/class-files/04-writing-your-own-class.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.
