줄 바꿈이 있는 인라인 코드 목록의 배경색

줄 바꿈이 있는 인라인 코드 목록의 배경색

회색 배경으로 코드 인라인을 강조하고 싶습니다. 바람직하게는listings ​이 질문은 다음과 관련이 있습니다.인라인 목록의 배경색.

그러나 내 MWE에서 알 수 있듯이 줄 바꿈에서는 작동하지 않습니다. 이 문제를 해결할 수 있는 방법이 있나요? 나는 또한 Soul 패키지를 시도했지만 이로 인해 많은 오류가 발생했습니다(MWE의 설명):

\documentclass{article}

\usepackage{listings}
\usepackage{xcolor}
\usepackage{soul}

\lstdefinestyle{ShellCmd}{
    language=bash,
    basicstyle=\small\ttfamily,
    backgroundcolor=\color{gray!10},
    linewidth=0.9\linewidth,
    breaklines=true
}
\def\ownstrut{\vrule height5.5pt depth0.8pt width0pt}

\newcommand\shellcmd[1]{\colorbox{gray!10}{\lstinline[style=ShellCmd,mathescape]`#1`}}
%\newcommand\shelltwo[1]{\hl{\lstinline[style=ShellCmd,mathescape]`#1`}} % this produces error

\begin{document}

\shellcmd{command}, some text \shellcmd{a very long command which should not destroy the whole layout when a line break occurs! Maybe it is possible to make even three or more lines}, and here it continues. 
%\shelltwo{a very long command which should not destroy the whole layout when a line break occurs! Maybe it is possible to make even three or more lines}

\end{document}

답변1

문제는 이것이 \colorbox{}상자라는 것입니다. 즉, 내부에 개행 문자를 사용할 수 없다는 의미입니다.

사용해 볼 수는 있지만 \parbox원하는 대로 작동하지 않습니다( 참조 \shellthree).

다음 MWE의 마지막 세 줄에 표시된 대로 패키지 soul로 문제를 해결할 수 있습니다 .\texttt

\documentclass{article}

\usepackage{listings}
\usepackage{xcolor,showframe}
\usepackage{soul}

\lstdefinestyle{ShellCmd}{
    language=bash,
    basicstyle=\small\ttfamily,
    backgroundcolor=\color{gray!10},
    linewidth=0.9\linewidth,
    breaklines=true
}

\newcommand\shellthree[1]{\colorbox{gray!10}{\parbox[t]{\textwidth}{\lstinline[style=ShellCmd,mathescape]`#1`}}}


\begin{document} 

\lstinline[{backgroundcolor=\color{gray!50}}]{Testzeile testzeile testzeile}
\lstinline[style=ShellCmd]{Testzeile testzeile testzeile}

Command some text \shellthree{a very long command which should not destroy the whole layout when a line break occurs! Maybe it is possible to make even three or more lines}, 
and here it continues. and here it continues and here it continues and here it continues 

\colorlet{hellgrau}{gray!10}
\sethlcolor{hellgrau}
Text Text Text Text Text Text Text Text Text Text Text Text \texthl{\texttt {text highlight with soul}}.

\end{document}

나는 package 를 사용하고 soul, 로 색상을 변경하고 \colorlet, 로 색상을 설정하고 , 텍스트를 설정하는 데 \sethlcolor사용합니다 . texthl{texttt{}}이는 줄바꿈에도 적용됩니다.

답변2

lua-el(줄을 강조 표시하기 위해) 및 piton(정보 목록의 구문 색상 지정을 위해)을 결합할 수 있습니다 . 두 패키지 모두 LuaLaTeX를 사용한 컴파일이 필요합니다.

\documentclass{article}
\usepackage{piton}
\usepackage{luacolor,lua-ul}
\LuaULSetHighLightColor{gray!15}

\usepackage{piton}

\begin{document}

\makeatletter
\newcommand\shellcmd[1]{{\@highLight\piton{#1}}}
\makeatother

\PitonOptions{break-lines-in-piton,language = minimal}

\shellcmd{command}, some text \shellcmd{a very long command which should not destroy the whole layout when a line
  break occurs! Maybe it is possible to make even three or more lines}, and here it continues.

\end{document}

위 코드의 출력

관련 정보