HOWTO · R

R を使用した未定義の制御シーケンス ラテックス

このチュートリアルでは、R の未定義の制御シーケンス ラテックス エラーについて説明します。

このチュートリアルでは、R の undefined control sequence latex エラーについて説明します。

R を使用した未定義の制御シーケンス ラテックス

R で Latex を使用する場合、Latex 構文に構文エラーまたは入力ミスがあると、undefined control sequence latex エラーが発生します。

通常、Latex の間に R コードを挿入する必要がある場合があり、そのファイルは Rtex 拡張子で保存されます。

このエラーの一般的な原因はタイプミスです。 たとえば、ギリシャ文字 $\alpha$ を書き、$\slpha$ のような入力ミスをすると、undefined control sequence latex エラーがスローされます。 例を試してみましょう。

\documentclass{article}
\begin{document}

Let's use R commands in our \LaTeX{} document which will be processed and output will be included in the document:

\begin{equation}
\slpha
\end{equation}

<<>>=
# Use R to create a sequence of numbers
a = 1:100

# Use R to display basic statistical measures
summary(a)

@
\end{document}

上記のコードを実行すると、Latex 画面に \alpha のない出力が表示され、ログに undefined control sequence エラーも表示されます。 出力を参照してください:

ラテックス文書:

未定義の制御シーケンス

ログファイル:

未定義の制御シーケンス エラー

このエラーを解決するには、Latex 構文を正しく記述し、タイプミスがないことを確認する必要があります。 これは、R を Latex で使用する場合、または Latex を R で使用する場合に適用されます。

解決策を見てみましょう。

\documentclass{article}
\begin{document}

Let's use R commands in our \LaTeX{} document which will be processed and output will be included in the document:

\begin{equation}
\alpha
\end{equation}

<<>>=
# Use R to create a sequence of numbers
a = 1:100

# Use R to display basic statistical measures
summary(a)

@
\end{document}

唯一の入力ミスが修正されると、undefined control sequence latex は解決されます。 出力を参照してください:

未定義の制御シーケンスの解決策