> 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/narejjibsu/099-is-there-a-way-to-run-a-word-count-that-doesn-t-include-latex-commands.md).

# LaTeXコマンドを含めずに単語数を数える方法はありますか？

## はじめに

はい、LaTeXコマンドを自動的に除外する単語数を取得するには、 `メニュー` 次に `単語数` を選択します。これはこの短いスクリーンキャストで示しています:

![Wordcount.gif](/files/5c1ade1c63653d8bf722b2d46eb0b1e810b158ec)

これにより [texcountユーティリティ](http://app.uio.no/ifi/texcount) を実行し、プロジェクトのメインファイル内の単語数と、次を介してメインファイルに取り込まれた任意のファイルの単語数を数えます: `\include` と `\input`。なお、Overleaf で texcount を動作させるには、プロジェクトのメイン文書がプロジェクトの最上位（つまりフォルダ内ではない場所）にある必要があります。

## 単語数に参考文献を含める

デフォルトでは、参考文献、見出し、キャプション、フロート、表示数式などはカウントに含まれません。引用や参考文献を含めるには:

1. 追加 `%TC:incbib` .texファイルのプリアンブルに入れて、次に
2. プロジェクトに latexmkrc という名前のファイル（拡張子なし）を作成し、そこに次の行を入れてください（"main" はメインの .tex ファイル名に置き換えてください）

   ```perl
   END { system('cp', 'output.bbl', 'main.bbl'); }
   ```

**なお、この回避策は手動の `thebibliography` のリスト、または BibTeX を使用している場合にのみ適用できます。** [**texcount は現在 biblatex をサポートしていません**](https://tex.stackexchange.com/q/102882/226)**.**

参照 [#カスタムパラメータで texcount を実行する](#run-texcount-with-custom-parameters) で、見出し、キャプション、フロート、表示数式などの単語数を表示できます。

## 一部のセクションを無視する

場合によっては、特定のセクションや範囲を単語数から除外したいことがあります。次のように配置できます: `%TC:ignore` と `%TC:endignore` そのような範囲の前後に。例:

```latex
%TC:ignore
\maketitle

\begin{abstract}
...したがって、タイトルページと要旨は単語数に含まれません...
\end{abstract}
%TC:endignore
```

## カスタムパラメータで texcount を実行する

独自の [texcount パラメータ](http://app.uio.no/ifi/texcount/documentation.html) を使って出力をカスタマイズしたり、文字数を数えたり、キャプションなどを含めたりしたい場合は、プロジェクト内でいくつかのコマンドを定義することで可能です（ただし、その場合は LaTeX コマンドを使うことになります...）。例:

```latex
\usepackage{verbatim}

\newcommand{\detailtexcount}[1]{%
  \immediate\write18{texcount -merge -sum -q #1.tex output.bbl > #1.wcdetail }%
  \verbatiminput{#1.wcdetail}%
}

\newcommand{\quickwordcount}[1]{%
  \immediate\write18{texcount -1 -sum -merge -q #1.tex output.bbl > #1-words.sum }%
  \input{#1-words.sum} 単語%
}

\newcommand{\quickcharcount}[1]{%
  \immediate\write18{texcount -1 -sum -merge -char -q #1.tex output.bbl > #1-chars.sum }%
  \input{#1-chars.sum} 文字（スペースを含まない）%
}
```

ファイル名が `main.tex`だとすると、これらのコマンドをプロジェクトで実行した場合、PDF には次のように出力されます。出力には各サブセクションごとの内訳に加え、キャプション、フロート、表示数式などの内訳も含まれます。Overleaf のビルドプロセスの設定上、BibTeX で生成された参考文献リストも数えるには、\`texcount\` コマンドに \`output.bbl\` を含める必要があることに注意してください。

```latex
% これらは数えないでください!
%TC:ignore
\quickwordcount{main}
\quickcharcount{main}
\detailtexcount{main}
%TC:endignore
```

![Custom-texcount.png](/files/13aabd428c6512ff8cc2ed4213aa885108114c5f)

参照: [texcount のドキュメント](http://app.uio.no/ifi/texcount/documentation.html#options) で各実行時フラグの働きを確認できます。これらの例の動作は [こちら](https://www.overleaf.com/read/dqvrqghbtmbc).

セクションごとの内訳にある「Words in headers」と「headers」は `\section`, `\subsection` などを含みますが、1、1.1 などの番号は除外します。

セクションごとの内訳にある「Word outside text」と「captions」は `\caption`、ただし「Table 1」などの接頭辞は除外します。

デフォルトでは、インライン引用はカウントされません。カウントしたい場合は、プリアンブルに次の行を追加してください:

```latex
%TC:macro \cite [option:text,text]
%TC:macro \citep [option:text,text]
%TC:macro \citet [option:text,text]
% ... および、使用している他の \cite コマンドについても同様です
```

ただし、各 `\citep{ddd}` は texcount では 1 語としてしか数えられません（これはまあ理にかなっています。そうでないと、複数著者の文献を引用することで単語数を不自然に大きく増やせてしまうからです）。したがって `\cite{faye1996}`は、(Fay, 1996) と表示されるものの、texcount では 1 語として数えられ、他のワープロソフトでは 2 語として数えられます。

「本文中の単語数」に表組みやテーブル内の単語を含めるには、 [次の texcount 指示を追加できます](https://tex.stackexchange.com/a/37777/226) 。

```latex
%TC:group table 0 1
%TC:group tabular 1 1
```

## texcount で \import コマンドを使う

デフォルトでは、texcount は次のような一般的なコマンドを認識します: `\input`, `\include` 取り込まれたサブファイルの単語数を数えるためのものです。ただし、コマンド `\import` の `import` パッケージはデフォルトではサポートされていません。

したがって、もし `\import` を文書で使っているなら、より一般的な `\input` と `\include` コマンドの使用を検討するとよいでしょう。そうすれば、texcount は追加の変更なしで動作します。

それでも引き続き `\import`を使いたい場合は、プリアンブルに texcount 指示を追加して、 `\import{foo}{bar}` が `\include{foo/bar}` のように見えるようにします

```latex
%TC:fileinclude \import dir,file
```

と texcount に認識させれば、サブファイル内の単語数を数えられます:

## この行を追加した後、「Word count」をクリックする前に、まず再コンパイルする必要があることに注意してください。

* [さらに読む\
  texcount の完全なドキュメント](http://app.uio.no/ifi/texcount/documentation.html)


---

# 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/narejjibsu/099-is-there-a-way-to-run-a-word-count-that-doesn-t-include-latex-commands.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.
