コード リスト内の一部のテキストを太字にする必要があり、そのためには、lstlisting で mathescape=true と \textbf を使用する次のコードを使用しています。
\begin{lstlisting}[language={}, basicstyle={\small\ttfamily},mathescape=true]
regular text
$\textbf{hello hi}$
regular text
\end{lstlisting}
これは、hello hi を太字のテキストにするため、正常に機能します。ただし、次のように、hello と hi の間に改行があると、
$\textbf{hello
hi}$
結果に改行がありません。\ を追加してみましたが、それでも機能しませんでした。
$\textbf{hello \\
hi}$
ここで改行を追加する方法をご存知ですか?
答え1
数式に逃げていますが、$\textbf{hello\\hi}$
リストの外では機能しません。escapechar=$
の代わりにを使用してくださいmathescape=true
。
\documentclass{article}
\usepackage{listings}
\begin{document}
$\textbf{hello\\hi}$
\begin{lstlisting}[language={}, basicstyle={\small\ttfamily},escapechar=$]
regular text
$\textbf{hello\\hi}$
regular text
\end{lstlisting}
\end{document}
(フォント設定を示す完全な例を提供していないため、太字ではありません。)