エスケープされたテキスト内のリストの改行

エスケープされたテキスト内のリストの改行

私は、lstlisting 環境内の改行の表示を修正しようとしていますが、より具体的には、エスケープされた領域内にあるリストの一部を修正しようとしています。

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage[usenames,dvipsnames,table]{xcolor}
\usepackage{listings}
\lstset{}


\definecolor{keywordColor}{HTML}{0033B3}
\definecolor{parameterColor}{HTML}{067D17}
\definecolor{commentColor}{HTML}{8C8C8C}
\definecolor{scenarioColor}{HTML}{871094}

\newcommand{\lstKeyword}[1]{{\textcolor{keywordColor}{#1}}}
\newcommand{\lstParameter}[1]{{\textcolor{parameterColor}{#1}}}
\newcommand{\lstScenario}[1]{{\textcolor{scenarioColor}{\textit{#1}}}}

\lstdefinestyle{bddStory}
{
  frame=single,
  captionpos=b,
  commentstyle=\color{commentColor},
  keywordstyle=\color{keywordColor},
  morekeywords={Given ,When ,Then ,And ,Narrative,Examples},
  escapeinside={<@}{@>},
  showspaces=false,
  showtabs=false,
  showstringspaces=false,
  breaklines=true,
  postbreak=\mbox{\textcolor{red}{$\hookrightarrow$}\space},
  breakatwhitespace=true
}

\title{Example Issue}

\begin{document}
\begin{lstlisting}[style=bddStory]
<@\lstScenario{Scenario: A scenario title is too long and can't fit into a single line which causes issues in the highlighting}@>
Given there is some further content
\end{lstlisting}

\end{document}

コンテンツは次のようにレンダリングされます。ボックス内の 2 つの改行と新しい行の矢印が欠落していることが問題です。

改行のレンダリングが間違っている

答え1

listingsこのセグメント化されたボックスは、パッケージの既知のバグです。tcolorboxlistingsパッチを使用して修正できます。引数がパッケージに渡される方法がlistings異なることに注意してください。

ここに画像の説明を入力してください

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[usenames,dvipsnames,table]{xcolor}
\usepackage{tcolorbox}

\tcbuselibrary{skins, breakable, listings}

\definecolor{keywordColor}{HTML}{0033B3}
\definecolor{parameterColor}{HTML}{067D17}
\definecolor{commentColor}{HTML}{8C8C8C}
\definecolor{scenarioColor}{HTML}{871094}

\newcommand{\lstKeyword}[1]{{\textcolor{keywordColor}{#1}}}
\newcommand{\lstParameter}[1]{{\textcolor{parameterColor}{#1}}}
\newcommand{\lstScenario}[1]{{\textcolor{scenarioColor}{\textit{#1}}}}

\lstdefinestyle{bddStory}
{
  captionpos=b,
  commentstyle=\color{commentColor},
  keywordstyle=\color{keywordColor},
  morekeywords={Given ,When ,Then ,And ,Narrative,Examples},
  escapeinside={<@}{@>},
  showspaces=false,
  showtabs=false,
  showstringspaces=false,
  breaklines=true,
  postbreak=\mbox{\textcolor{red}{$\hookrightarrow$}\space},
  breakatwhitespace=true
}

\title{Example Issue}

\newtcblisting{mylisting}[1]{
  enhanced,
  breakable,
  listing only,
  boxrule=0.8pt,
  sharp corners,
  top=0mm,
  bottom=0mm,
  left=2mm,
  right=2mm,
  boxsep=0mm,
  colframe=black,
  colback=white,
  listing options={
    style=#1
  }
}


\begin{document}
\begin{mylisting}{bddStory}
<@\lstScenario{Scenario: A scenario title is too long and can't fit into a single line which causes issues in the highlighting}@>
Given there is some further content
\end{mylisting}


\end{document}

矢印が欠落している点については、listingsパッケージがエスケープされた領域にコンテンツを追加しようとしていないのではないかと思いますpostbreak。以下の例を参照してください。

ここに画像の説明を入力してください

もし、あんたが本当にこの機能を実装したいのですが、次の 2 つの投稿を見つけました:

関連情報