> 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/ja/fonto/03-xelatex.md).

# XƎLaTeX で現代的なフォントをサポートする

## はじめに

[XeTeX](https://tug.org/xetex/) は、ドナルド・クヌースの元のTeXソフトウェアから派生した組版エンジンです。ただし、クヌースの元のプログラムとは異なり、XeTeXはUTF-8でエンコードされたUnicodeテキストをネイティブに読み取り（入力し）、さらに内蔵の [HarfBuzz](https://harfbuzz.github.io/) 字形整形エンジンの助けを借りて、次のような最新のフォント形式をサポートします [OpenType (OTF)](https://docs.microsoft.com/en-us/typography/opentype/) や [SILのGraphiteフォント技術](https://scripts.sil.org/cms/scripts/page.php?site_id=projects\&item_id=graphite_home)。対応するLaTeX [コンパイラ](/latex/ja/sononotopikku/08-choosing-a-latex-compiler.md) Overleafでは `xelatex`と呼ばれます。さまざまなTeXエンジンの進化をより深く理解したい方は、Overleafの記事 [What’s in a Name: A Guide to the Many Flavours of TeX](/latex/ja/xiang-xi-ji-shi/55-what-s-in-a-name-a-guide-to-the-many-flavours-of-tex.md).

## 基本：Times New Roman

Times New Romanはよく使われるフォントで、以下はXeLaTeXコンパイラ経由でOverleaf上での使用例です。この例では、文書のフォントは次を使って設定しています `\usemainfont{Times New Roman}`、ここでコマンド `\usemainfont{...}` はパッケージによって提供されます `fontspec`.

```latex
\documentclass[12pt]{article}
\usepackage{fontspec}

\setmainfont{Times New Roman}
\title{Sample font document}
\author{Overleaf}
\date{\today}

\begin{document}
\maketitle

これは、\textit{example} を含む、コンパイルされた文書の
\textbf{XeLaTeX}を使ったものです。LuaLaTeXでも動作します。

\end{document}
```

[OverleafでXeLaTeXを使ったTimes New Romanのサンプルを開く](https://www.overleaf.com/docs?engine=xelatex\&snip_name=Times+New+Roman+%28via+XeLaTeX%29\&snip=%5Cdocumentclass%5B12pt%5D%7Barticle%7D%0A%5Cusepackage%7Bfontspec%7D%0A+%0A%5Csetmainfont%7BTimes+New+Roman%7D%0A%5Ctitle%7BSample+font+document%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7B%5Ctoday%7D%0A+++%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0A+++++%0AThis+is+an+%5Ctextit%7Bexample%7D+of+a+document+compiled+%0Awith+%5Ctextbf%7BXeLaTeX%7D.+LuaLaTeX+should+also+work+too.%0A%0A%5Cend%7Bdocument%7D)

この例では次の出力が生成されます:

![XeLaTeXOverleaf.png](/files/0978bd02b4bafb4e3ac08f531a2c6117908d6cc0)

また、 [LuaLaTeXを使って同じコードを実行できます](https://www.overleaf.com/docs?engine=lualatex\&snip_name=Times+New+Roman+%28via+LuaLaTeX%29\&snip=%5Cdocumentclass%5B12pt%5D%7Barticle%7D%0A%5Cusepackage%7Bfontspec%7D%0A+%0A%5Csetmainfont%7BTimes+New+Roman%7D%0A%5Ctitle%7BSample+font+document%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7B%5Ctoday%7D%0A+++%0A%5Cbegin%7Bdocument%7D%0A%5Cmaketitle%0A+++++%0AThis+is+an+%5Ctextit%7Bexample%7D+of+a+document+compiled+%0Awith+%5Ctextbf%7BLuaLaTeX%7D.%0A%0A%5Cend%7Bdocument%7D) .

## さまざまなLaTeX要素のフォント設定

LaTeX文書内のさまざまな要素は異なるフォントで整形されます。たとえば、 `verbatim` \environmentでは、テキストはタイプライター風のスタイルで表示されます。文脈ごとに異なるフォントスタイルを設定できます：

```latex
\documentclass[12pt]{article}
\usepackage{fontspec}

%-----------------------------------------------------------------------
\setmainfont{Times New Roman}
\setsansfont{Arial}
\setmonofont[Color={0019D4}]{Courier New}
%-----------------------------------------------------------------------

\title{Sample font document}
\author{Overleaf}
\date{\today}
\begin{document}

\maketitle

これは、次を使ってコンパイルされた文書の\textit{example}です
\textbf{XeLaTeX}コンパイラです。コードを書く必要がある場合は、
\texttt{verbatim}環境を使えます：

    \begin{verbatim}
    通常、この環境はコードを表示するために使われますが、
    ここでは簡単なCプログラムを示します。

    #include <stdio.h>
    #define NUMYAYS 10

    int main()
    {
        int i;
        for (i = 0; i <= NUMYAYS; i++)
        {
            printf("Yay! Overleaf is Awesome!\n");
        }
        return 0;
    }
    \end{verbatim}
    {\sffamily これは\textbf{サンセリフ書体}のサンプルテキストです}

\end{document}
```

[結果を見るには、OverleafでこのXeLaTeXの例を開いてください](https://www.overleaf.com/docs?engine=xelatex\&snip_name=Document+formatted+with+different+fonts\&snip=%5Cdocumentclass%5B12pt%5D%7Barticle%7D%0A%5Cusepackage%7Bfontspec%7D%0A%0A%25-----------------------------------------------------------------------%0A%5Csetmainfont%7BTimes+New+Roman%7D%0A%5Csetsansfont%7BArial%7D%0A%5Csetmonofont%5BColor%3D%7B0019D4%7D%5D%7BCourier+New%7D%0A%25-----------------------------------------------------------------------%0A%0A%5Ctitle%7BSample+font+document%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7B%5Ctoday%7D%0A%5Cbegin%7Bdocument%7D%0A++++%0A%5Cmaketitle%0A+++++%0AThis+an+%5Ctextit%7Bexample%7D+of+document+compiled+with+the++%0A%5Ctextbf%7BXeLaTeX%7D+compiler.+If+you+have+to+write+some+code+you+can+%0Ause+the+%5Ctexttt%7Bverbatim%7D+environment%3A%0A%0A++++%5Cbegin%7Bverbatim%7D%0A++++Usually+this+environment+is+used+to+display+code%2C+%0A++++so+here%27s+a+simple+C+program.%0A%0A++++%23include+%3Cstdio.h%3E%0A++++%23define+NUMYAYS+10%0A++++++%0A++++int+main%28%29%0A++++%7B%0A++++++++int+i%3B+++%0A++++++++for+%28i+%3D+0%3B+i+%3C%3D+NUMYAYS%3B+i%2B%2B%29+%0A++++++++%7B%0A++++++++++++printf%28%22Yay%21+Overleaf+is+Awesome%21%5Cn%22%29%3B%0A++++++++%7D%0A++++++++return+0%3B%0A++++%7D%0A++++%5Cend%7Bverbatim%7D%0A++++%7B%5Csffamily+This+is+a+sample+text+in+%5Ctextbf%7BSans+Serif+Font+Typeface%7D%7D%0A+++++++%0A%5Cend%7Bdocument%7D)

前の例では3種類の異なるフォントを使用していました。次の行で、このフォントを使用する要素を指定します：

**\setmainfont{Times New Roman}**

これは文書の大部分で使用される標準フォントで、この例ではTimes New Romanです。

**\setsansfont{Arial}**

サンセリフフォントを必要とする要素は、例で\ssfamilyによって明示的に指定されており、Arialフォントで組版されます。

**\setmonofont{Courier New}**

等幅（タイプライター風）フォントで整形されるものはすべてCourier Newフォントを使用します。このコマンドには、中かっこの中に追加のオプション引数があります：

**Color={0019D4}**

これは、16進のHTML形式でColor=値を使ってテキストの色を設定します。プレゼンテーションを作成する際には、テキスト色を選択的かつ慎重に使うと便利です。

## Overleafのフォント

あります [Overleafには多数のフォントがインストールされています](/latex/ja/to-2/85-which-otf-or-ttf-fonts-are-supported-via-fontspec.md) それらはプロジェクトで使用でき、最も簡単なのは次を介してです `fontspec`。以下の例では、Google NotoなどのOverleafサーバーに含まれるフォントと、次からアップロードする必要があるフォントの両方の使用例を示します [Google Fonts](https://fonts.google.com/).

### Overleafのサーバーにインストールされているフォント：Google Notoフォント

なぜなら [TeX Live](https://www.tug.org/texlive/)—Overleafで使用されている—には、次が含まれています [Google Notoフォント](https://www.google.com/get/noto/) それらは、次を介して使用できます `fontspec` パッケージを使って、XeLaTeXまたはLuaLaTeXコンパイラでコンパイルされたOverleafプロジェクト内で利用できます。以下は、次を使ったサンプルプロジェクトです [`noto` パッケージ](https://ctan.org/pkg/noto?lang=en) 文書をNotoSerif、NotoSans、NotoSansMonoの各フォントファミリーで組版するように設定します。次のドキュメントは `noto` パッケージの [CTAN上のreadmeファイルにあります](http://mirrors.ctan.org/fonts/noto/README).

```latex
\documentclass{article}
\usepackage{xcolor}
\usepackage{noto}
\usepackage{hyperref}
\title{Google Notoフォントの使用}
\author{Overleaf}
\date{2021年4月}

\begin{document}

\maketitle

\section{導入}
このサンプルプロジェクトでは、\href{https://ctan.org/pkg/noto?lang=en}{\color{blue}\texttt{noto}}パッケージを使用して、GoogleのNotoフォント\footnote{\url{https://www.google.com/get/noto/}}で文書を組版します：
\begin{itemize}
\item \verb|\textbf{bold}| は \textbf{bold} を生成します
\item \verb|\textit{italic}| は \textit{italic} を生成します
\item \verb|\textbf{\textit{bold italic}}| は \textbf{\textit{bold italic}} を生成します
\item \verb|\emph{emphasis}| は \emph{emphasis} を生成します
\item \verb|\textbf{\emph{bold italic}}| は \textbf{\emph{bold italic}} を生成します
\end{itemize}

\subsection{等幅フォント}
Notoの等幅フォントは、\texttt{regular} および \texttt{\textbf{bold}} の等幅テキストに使用できます。

\subsection{サンセリフフォント}
以下は、\textsf{テキストはサンセリフフォントで組版されています} と \textbf{\textsf{太字サンセリフで組版されたテキスト}} の例です。

\section{参考文献}
\texttt{noto}パッケージのドキュメンテーションは、そのCTAN上の\href{http://mirrors.ctan.org/fonts/noto/README}{\color{blue}\texttt{readme}ファイル}にあります。

\end{document}
```

[Notoフォントを試すには、OverleafでこのXeLaTeXの例を開いてください](https://www.overleaf.com/docs?engine=xelatex\&snip_name=Using+Google+Noto+fonts\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bxcolor%7D%0A%5Cusepackage%7Bnoto%7D%0A%5Cusepackage%7Bhyperref%7D%0A%5Ctitle%7BUsing+Google+Noto+fonts%7D%0A%5Cauthor%7BOverleaf%7D%0A%5Cdate%7BApril+2021%7D%0A%0A%5Cbegin%7Bdocument%7D%0A%0A%5Cmaketitle%0A%0A%5Csection%7BIntroduction%7D%0AThis+example+project+uses+the+%5Chref%7Bhttps%3A%2F%2Fctan.org%2Fpkg%2Fnoto%3Flang%3Den%7D%7B%5Ccolor%7Bblue%7D%5Ctexttt%7Bnoto%7D%7D+package+to+typeset+your+document+using+Google%27s+Noto+fonts%5Cfootnote%7B%5Curl%7Bhttps%3A%2F%2Fwww.google.com%2Fget%2Fnoto%2F%7D%7D%3A%0A%5Cbegin%7Bitemize%7D%0A%5Citem+%5Cverb%7C%5Ctextbf%7Bbold%7D%7C+produces+%5Ctextbf%7Bbold%7D%0A%5Citem+%5Cverb%7C%5Ctextit%7Bitalic%7D%7C+produces+%5Ctextit%7Bitalic%7D%0A%5Citem+%5Cverb%7C%5Ctextbf%7B%5Ctextit%7Bbold+italic%7D%7D%7C+produces+%5Ctextbf%7B%5Ctextit%7Bbold+italic%7D%7D%0A%5Citem+%5Cverb%7C%5Cemph%7Bemphasis%7D%7C+produces+%5Cemph%7Bemphasis%7D%0A%5Citem+%5Cverb%7C%5Ctextbf%7B%5Cemph%7Bbold+italic%7D%7D%7C+produces+%5Ctextbf%7B%5Cemph%7Bbold+italic%7D%7D%0A%5Cend%7Bitemize%7D%0A%0A%5Csubsection%7BMonospaced+fonts%7D%0AYou+can+use+Noto%27s+monospaced+fonts+for+%5Ctexttt%7Bregular%7D+and+%5Ctexttt%7B%5Ctextbf%7Bbold%7D%7D+monospaced+text.%0A%0A%5Csubsection%7BSans+serif+fonts%7D%0AHere+is+some+%5Ctextsf%7Btext+is+typeset+in+a+sans+serif+font%7D+together+with+%5Ctextbf%7B%5Ctextsf%7Btext+typeset+in+bold+sans+serif%7D%7D.%0A%0A%5Csection%7BFurther+reading%7D%0ADocumentation+for+the+%5Ctexttt%7Bnoto%7D+package+can+be+found+in+its+%5Chref%7Bhttp%3A%2F%2Fmirrors.ctan.org%2Ffonts%2Fnoto%2FREADME%7D%7B%5Ccolor%7Bblue%7D%5Ctexttt%7Breadme%7D+file+on+CTAN%7D.%0A%0A%5Cend%7Bdocument%7D)

![Google Notoフォントを使ってLaTeX文書を組版する](/files/f3cb045d853b2840fe749d5d75429bb192d2f1b7)

### Overleafのサーバーにインストールされていないフォントを使う：Google Fontsの例

OverleafのサーバーにインストールされていないOpenTypeフォントを使用するには、まずフォントファイルをOverleafプロジェクトにアップロードする必要があります—ただし、フォントのライセンスがそれを許可している場合に限ります。OpenTypeフォントをアップロードしたら、プロジェクトのコンパイラをXƎLaTeX（またはLuaLaTeX）に設定し、 `fontspec` フォントを設定するために使います。

以下で示すサンプルプロジェクトでは、フォルダの作成、フォントのアップロード、および次を使った設定方法を示します `fontspec`。この例では、次から選んだ以下のフォントを使用します [Google Fonts](https://fonts.google.com/):

* セリフフォント： [Brygada1918](https://fonts.google.com/specimen/Brygada+1918)
* サンセリフフォント： [Asap](https://fonts.google.com/specimen/Asap)
* 等幅フォント： [JetBrains Mono](https://fonts.google.com/specimen/JetBrains+Mono)

注意：この例が書体として調和の取れた組み合わせだと示しているわけではなく、単にお好みのフォントをアップロード、設定、使用する方法を示しているだけです。

各書体について、Google Fontsからフォントファミリーをダウンロードする必要があります：

![GoogleDownload.png](/files/e9b9d2c8162dbad3e42ddbc649bdf7d96fa1c209)

注意：一部のGoogleフォントは「static」OpenTypeフォントと、いわゆる「variable」OpenTypeフォントの両方で利用できます。ダウンロードしたZIPファイルに「static」というフォルダがある場合は、可変フォント版ではなく、そのフォルダ内のフォントをアップロードしてください：

![OpenTypeStatic.png](/files/e5ab48999f9e1fa4e4a3fd68d0a609ef3e241762)

次に、フォントファイルをプロジェクトにアップロードする必要がありますが、フォントファミリーには複数のフォントファイルが含まれているため、各フォントファミリーごとに1つのフォルダを使って個別のOverleafプロジェクトフォルダを作成するとよいでしょう。次の動画ではその方法を示します。後で、XƎLaTeXにプロジェクトのフォントの場所を指定する必要があります。これらはOverleafのサーバーに事前インストールされていないためです。

{% embed url="<https://videos.ctfassets.net/nrgyaltdicpt/4lQFkZ1Ni1FHFdHJUJSNH4/4aee7c5bafeb021a6f21b4637d0fe6ec/UploadingGoogleFonts.mp4>" %}

### fontspecでフォントを使用するように設定する

フォントファミリーのファイルをOverleafプロジェクトのフォルダにアップロードしたら、次を使って使用設定できます `fontspec`。以下のLaTeXコードでは、次を使っていることに注目してください `Path` というパラメータで `fontspec` フォントファイルが、プロジェクトのファイルシステム内のローカルフォルダにあることを指定しています：

```latex
\setmainfont{Brygada1918}[
    Path=./BrygadaFontFiles/,
    Extension = .ttf,
    UprightFont=*-Regular,
    BoldFont=*-Bold,
    ItalicFont=*-Italic,
    BoldItalicFont=*-BoldItalic
    ]

\setsansfont{Asap}[
    Path=./AsapFontFiles/,
    Scale=0.9,
    Extension = .ttf,
    UprightFont=*-Regular,
    BoldFont=*-Bold,
    ItalicFont=*-Italic,
    BoldItalicFont=*-BoldItalic
    ]

\setmonofont{JetBrainsMono}[
    Path=./JetbrainsFontFiles/,
    Scale=0.85,
    Extension = .ttf,
    UprightFont=*-Regular,
    BoldFont=*-Bold,
    ItalicFont=*-Italic,
    BoldItalicFont=*-BoldItalic
    ]
```

![FontSpecPathUpdated.png](/files/76201570f608a2dbec69c870215f436caaff42b8)

[OverleafでXeLaTeXとGoogle Fontsのデモを開く](https://www.overleaf.com/project/new/template/31226?id=835225587\&templateName=XeLaTeX+font+demo+with+Google+Fonts\&latexEngine=xelatex\&texImage=texlive-full%3A2022.1\&mainFile=)

この [`fontspec` パッケージ](https://ctan.org/pkg/fontspec?lang=en) LuaLaTeXまたはXƎLaTeXで使用するOpenTypeフォントの設定には豊富な選択肢が用意されています—その [優れたドキュメンテーション](http://mirrors.ctan.org/macros/unicodetex/latex/fontspec/fontspec.pdf) には多数の例があり、それらを参照して文書のデザインや組版を微調整できます。

## さらに読む

詳しくは以下を参照してください：

* [太字、斜体、下線](/latex/ja/latexno/03-bold-italics-and-underlining.md)
* [フォントサイズ、ファミリー、スタイル](/latex/ja/fonto/01-font-sizes-families-and-styles.md)
* [フォントの書体](/latex/ja/fonto/02-font-typefaces.md)
* [段落の書式設定](/latex/ja/shu-shi-she-ding/04-articles-how-to-change-paragraph-spacing-in-latex.md)
* [改行と空白](/latex/ja/shu-shi-she-ding/05-line-breaks-and-blank-spaces.md)
* [テキスト配置](/latex/ja/shu-shi-she-ding/06-text-alignment.md)
* [複数カラム](/latex/ja/shu-shi-she-ding/09-multiple-columns.md)
* [大規模プロジェクトでの管理](/latex/ja/wen-shu-gou-zao/07-management-in-a-large-project.md)
* [複数ファイルの LaTeX プロジェクト](/latex/ja/wen-shu-gou-zao/08-multi-file-latex-projects.md)
* [国際言語サポート](/latex/ja/yan-yu/03-international-language-support.md)
* [LaTeXコンパイラの選択](/latex/ja/sononotopikku/08-choosing-a-latex-compiler.md)
* [OverleafにインストールされているOTFおよびTTFフォント一覧](/latex/ja/to-2/85-which-otf-or-ttf-fonts-are-supported-via-fontspec.md)
* [Googleのフォントコレクション](http://www.google.com/fonts/)
* [`fontspec` パッケージマニュアル](http://tug.ctan.org/tex-archive/macros/latex/contrib/fontspec/fontspec.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/ja/fonto/03-xelatex.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.
