코드 목록 내의 일부 텍스트를 굵게 표시해야 하며 이를 위해 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}
(글꼴 설정을 보여주는 전체 예를 제공하지 않았기 때문에 굵게 표시되지 않았습니다.)