LoginSignup
0

More than 3 years have passed since last update.

lstlistingにおいてLaTeXコマンドを扱う

Last updated at Posted at 2019-06-26

プログラム例

sample.tex
\begin{lstlisting}[escapechar=\@]
void function(int R) {
    printf("R[@$\Omega$@]: %d", R);
}
\end{lstlisting}

ポイント

  • escapechar=\任意の1文字\begin{lstlisting}の後に[]で囲んで書きます.
  • LaTeXコマンドを書きたい場所の前後に指定したエスケープ文字を書きます.
  • エスケープ文字で囲まれた部分は通常のLaTeXと同じ仕様であるため,数式を扱いたい場合は$でさらに囲む必要があります.
  • 今回のプログラム例では@を指定しましたが,!%などをエスケープ文字とすることもできます.ただし,lstlisting内で使用している文字をエスケープ文字に登録しないように気を付けましょう.

参考文献

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0