`\lstinline`을 강조하려고 할 때 페이지 경계에 문제가 있습니다.

`\lstinline`을 강조하려고 할 때 페이지 경계에 문제가 있습니다.

나는 주어진 코드를 시도하고 있었다인라인 목록의 배경색, 실제로는 의 것과 동일합니다.모든 인라인 코드 조각 주위에 프레임을 자동으로 강조 표시하거나 그리도록 \lstinline을 재정의하는 방법은 무엇입니까?, 다음과 같은 문제가 발생했습니다.

나타나는 단락이 \lstinline페이지 간에 끊어지면 강조 표시가 잘못된 페이지로 이동합니다(항상 그런 것은 아님). 문단이 깨지지 않더라도 라텍스 각주나 플로팅 메커니즘이 방해하여 해당 문단을 다음 페이지로 보내는 경우에도 발생합니다.

다음 MWE는 두 가지 문제를 모두 보여줍니다. 인용된 답변과 동일한 코드이며 첫 번째 경우(단락에서 페이지 나누기)에 문제를 일으키는 예제 앞에 텍스트가 더 있습니다. \begin{document}두 번째 문제도 보려면 근처에 있는 각주를 사용하여 줄의 주석 처리를 해제할 수 있습니다 (전체 단락은 다음 페이지로 이동하지만 강조 표시는 첫 번째 페이지에 남아 있음).

\documentclass[a4paper]{article}
\usepackage{etoolbox}
\usepackage{atbegshi,ifthen,listings,tikz}
\usepackage{lipsum}

% change this to customize the appearance of the highlight
\tikzstyle{highlighter} = [
  yellow,% set the color for inline listings here.
  line width = \baselineskip,
]

% enable these two lines for a more human-looking highlight
%\usetikzlibrary{decorations.pathmorphing}
%\tikzstyle{highlighter} += [decorate, decoration = random steps]

% implementation of the core highlighting logic; do not change!
\newcounter{highlight}[page]
\newcommand{\tikzhighlightanchor}[1]{\ensuremath{\vcenter{\hbox{\tikz[remember picture, overlay]{\coordinate (#1 highlight \arabic{highlight});}}}}}
\newcommand{\bh}[0]{\stepcounter{highlight}\tikzhighlightanchor{begin}}
\newcommand{\eh}[0]{\tikzhighlightanchor{end}}
\AtBeginShipout{\AtBeginShipoutUpperLeft{\ifthenelse{\value{highlight} > 0}{\tikz[remember picture, overlay]{\foreach \stroke in {1,...,\arabic{highlight}} \draw[highlighter] (begin highlight \stroke) -- (end highlight \stroke);}}{}}}
%--------------------------


\makeatletter %   Redefine macros from listings package:
\newtoggle{@InInlineListing}%
\togglefalse{@InInlineListing}%

\renewcommand\lstinline[1][]{%
    \leavevmode\bgroup\toggletrue{@InInlineListing}\bh % \hbox\bgroup --> \bgroup
      \def\lst@boxpos{b}%
      \lsthk@PreSet\lstset{flexiblecolumns,#1}%
      \lsthk@TextStyle
      \@ifnextchar\bgroup{\afterassignment\lst@InlineG \let\@let@token}%
                         \lstinline@}%

\def\lst@LeaveAllModes{%
    \ifnum\lst@mode=\lst@nomode
        \expandafter\lsthk@EndGroup\iftoggle{@InInlineListing}{\eh{}}{}%
    \else
        \expandafter\egroup\expandafter\lst@LeaveAllModes
    \fi%
    }
\makeatother

\lstset{backgroundcolor=\color{green!10}}%

\begin{document}
\lipsum[1-5]
% Foo\footnote{\lipsum[6]}

This is a somewhat large paragraph which latex perhaps will break among two
pages. Hopefully this will show the intended problem, that is, that the
highligthed yellow box is shown in the page in which the paragraph started,
instead of the page in which the code actually landed. Some more sentences to
fill the required space will do. Blah, blah, lorem ipsum or whatever.
This is a test where \lstinline{A=1} should have a yellow background.

This, on the other hand, actually works:
  \begin{lstlisting}[backgroundcolor=\color{green}]
    A = 1
  \end{lstlisting}
\end{document}

결과는 다음과 같습니다(두 번 컴파일한 후). "ipsum" 근처의 노란색 상자는 A=1두 번째 페이지의 인라인 코드에 있어야 합니다.

주먹 페이지두 번째 페이지

이 문제를 해결할 수 있나요?

답변1

의 도움으로 포장이 제공되는 tcolorbox version 2.80 (2014/03/31)오늘 출시된 솔루션을 기반으로 솔루션을 제공할 수 있습니다 . 버전의 새 매크로를 사용하는 대신 다음과 같은 답변을 변형할 수도 있습니다.\lstinlinexparse\RenewTotalTCBox2.80\newtcbinputlisting을 사용하여 축어적 상자를 어떻게 생성합니까?버전으로 2.72.

°귀하의 예를 적용하기 위해 구분할 특수 문자를 선택했습니다 \lstline.

\documentclass[a4paper]{article}
\usepackage{etoolbox}
\usepackage{atbegshi,ifthen,listings,tikz}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}% version 2.80 (2014/03/31)

\let\lstinlineoriginal=\lstinline

% change this to customize the appearance of the highlight
\tikzstyle{highlighter} = [
  yellow,% set the color for inline listings here.
  line width = \baselineskip,
]

\RenewTotalTCBox{\lstinline}{ O{} v }
  {blank,boxsep=1pt,nobeforeafter,tcbox raise base,interior style={fill,highlighter}}
  {\lstinlineoriginal[flexiblecolumns,#1]°#2°}

\lstset{backgroundcolor=\color{green!10}}%

\begin{document}
\lipsum[1-5]
% Foo\footnote{\lipsum[6]}

This is a somewhat large paragraph which latex perhaps will break among two
pages. Hopefully this will show the intended problem, that is, that the
highligthed yellow box is shown in the page in which the paragraph started,
instead of the page in which the code actually landed. Some more sentences to
fill the required space will do. Blah, blah, lorem ipsum or whatever.
This is a test where \lstinline{A=1} should have a yellow background.

This, on the other hand, actually works:
  \begin{lstlisting}[backgroundcolor=\color{green}]
    A = 1
  \end{lstlisting}
\end{document}

여기에 이미지 설명을 입력하세요 여기에 이미지 설명을 입력하세요

관련 정보