후자의 업데이트 [확장] 이후 목록이 포함된 lstlinebgrd 패키지의 최근 문제

후자의 업데이트 [확장] 이후 목록이 포함된 lstlinebgrd 패키지의 최근 문제

이 질문은 이전 질문에 계속됩니다.질문linebackground몇 줄의 코드에 색상 과 함께 배경색을 포함하도록 수정되었습니다 . MWE는 아래와 같습니다:

\documentclass{beamer}

\usepackage{listings, pgffor}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % \btIfInRange{number}{range list}{TRUE}{FALSE}
  %
  % Test if int number <number> is element of a (comma separated) list of ranges
  % (such as: {1,3-5,7,10-12,14}) and processes <TRUE> or <FALSE> respectively

\newcount\bt@rangea
\newcount\bt@rangeb

\newcommand\btIfInRange[2]{%
    \global\let\bt@inrange\@secondoftwo%
    \edef\bt@rangelist{#2}%
    \foreach \range in \bt@rangelist {%
        \afterassignment\bt@getrangeb%
        \bt@rangea=0\range\relax%
        \pgfmathtruncatemacro\result{ ( #1 >= \bt@rangea) && (#1 <= \bt@rangeb) }%
        \ifnum\result=1\relax%
            \breakforeach%
            \global\let\bt@inrange\@firstoftwo%
        \fi%
    }%
    \bt@inrange%
}%
\newcommand\bt@getrangeb{%
    \@ifnextchar\relax%
        {\bt@rangeb=\bt@rangea}%
        {\@getrangeb}%
}%
\def\@getrangeb-#1\relax{%
    \ifx\relax#1\relax%
        \bt@rangeb=100000%   \maxdimen is too large for pgfmath
    \else%
        \bt@rangeb=#1\relax%
    \fi%
}%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % \btLstHL<overlay spec>{range list}
  %
\newcommand<>{\btLstHL}[1]{%
    \only#2{\btIfInRange{\value{lstnumber}}{#1}{\color{blue!30}}{}}%
}%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % \btInputEmph<overlay spec>[listing options]{range list}{file name}
  %
\newcommand<>{\btLstInputEmph}[3][\empty]{%                                                    
    \only#4{%
        \lstset{linebackgroundcolor=\btLstHL{#2}}%
        \lstinputlisting{#3}%
    }% \only
}%
\makeatletter
    \let\old@lstKV@SwitchCases\lstKV@SwitchCases
    \def\lstKV@SwitchCases#1#2#3{}
\makeatother
\usepackage{lstlinebgrd}
\makeatletter
    \let\lstKV@SwitchCases\old@lstKV@SwitchCases
    \lst@Key{numbers}{none}{%
    \def\lst@PlaceNumber{\lst@linebgrd}%
    \lstKV@SwitchCases{#1}%
        {none:\\%
        left:\def\lst@PlaceNumber{\llap{\normalfont
            \lst@numberstyle{\thelstnumber}\kern\lst@numbersep} \lst@linebgrd}\\%
        right:\def\lst@PlaceNumber{\rlap{\normalfont
            \kern\linewidth \kern\lst@numbersep
            \lst@numberstyle{\thelstnumber}}\lst@linebgrd}%
    }{\PackageError{Listings}{Numbers #1 unknown}\@ehc}}
\makeatother

\begin{document}

\begin{frame}[fragile]{Problem}
Test programme:
\begin{lstlisting}[%
    language=C, 
    gobble=4, 
%   linebackgroundcolor={%
%       \btLstHL<1>{1,3,5-6}%
%       \btLstHL<2>{4}%
%   },
    backgroundcolor=\color{gray!10}
]
    #include <stdio.h>

    int main(void) {%
    printf("Hello World!");  
        return 0;
    }
\end{lstlisting}
\end{frame}
\end{document}

이 MWE [배경색 키 제외]는 다음에서 제공되었습니다.@모에웨. 이제 두 키를 모두 사용하면 linebackgroundcolor색상 backgroundcolor옵션이 backgroundcolor작동하지 않습니다. 패키지 작성자에게 연락을 시도했지만 성공하지 못했습니다. 해결 방법에 대한 제안을 부탁드립니다.

답변1

배경색은 원칙적으로 잘 작동합니다. 문제는 강조 표시할 선뿐만 아니라 다른 모든 선을 흰색으로 채워서 회색 배경을 덮는 매크로를 강조 표시한다는 것입니다.

\btLstHL해결 방법으로 다음 예와 같이 조정할 수 있습니다 .

\documentclass{beamer}

\usepackage{listings, pgffor}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % \btIfInRange{number}{range list}{TRUE}{FALSE}
  %
  % Test if int number <number> is element of a (comma separated) list of ranges
  % (such as: {1,3-5,7,10-12,14}) and processes <TRUE> or <FALSE> respectively

\newcount\bt@rangea
\newcount\bt@rangeb

\newcommand\btIfInRange[2]{%
    \global\let\bt@inrange\@secondoftwo%
    \edef\bt@rangelist{#2}%
    \foreach \range in \bt@rangelist {%
        \afterassignment\bt@getrangeb%
        \bt@rangea=0\range\relax%
        \pgfmathtruncatemacro\result{ ( #1 >= \bt@rangea) && (#1 <= \bt@rangeb) }%
        \ifnum\result=1\relax%
            \breakforeach%
            \global\let\bt@inrange\@firstoftwo%
        \fi%
    }%
    \bt@inrange%
}%
\newcommand\bt@getrangeb{%
    \@ifnextchar\relax%
        {\bt@rangeb=\bt@rangea}%
        {\@getrangeb}%
}%
\def\@getrangeb-#1\relax{%
    \ifx\relax#1\relax%
        \bt@rangeb=100000%   \maxdimen is too large for pgfmath
    \else%
        \bt@rangeb=#1\relax%
    \fi%
}%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % \btLstHL<overlay spec>{range list}
  %
\newcommand<>{\btLstHL}[1]{%
    \only#2{\btIfInRange{\value{lstnumber}}{#1}{\color{blue!30}}{\color{gray!20}}}%
}%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  %
  % \btInputEmph<overlay spec>[listing options]{range list}{file name}
  %
\newcommand<>{\btLstInputEmph}[3][\empty]{%                                                    
    \only#4{%
        \lstset{linebackgroundcolor=\btLstHL{#2}}%
        \lstinputlisting{#3}%
    }% \only
}%
\makeatletter
    \let\old@lstKV@SwitchCases\lstKV@SwitchCases
    \def\lstKV@SwitchCases#1#2#3{}
\makeatother
\usepackage{lstlinebgrd}
\makeatletter
    \let\lstKV@SwitchCases\old@lstKV@SwitchCases
    \lst@Key{numbers}{none}{%
    \def\lst@PlaceNumber{\lst@linebgrd}%
    \lstKV@SwitchCases{#1}%
        {none:\\%
        left:\def\lst@PlaceNumber{\llap{\normalfont
            \lst@numberstyle{\thelstnumber}\kern\lst@numbersep} \lst@linebgrd}\\%
        right:\def\lst@PlaceNumber{\rlap{\normalfont
            \kern\linewidth \kern\lst@numbersep
            \lst@numberstyle{\thelstnumber}}\lst@linebgrd}%
    }{\PackageError{Listings}{Numbers #1 unknown}\@ehc}}
\makeatother

\begin{document}

\begin{frame}[fragile]{Problem}
Test programme:
\begin{lstlisting}[%
    language=C, 
    gobble=4, 
   linebackgroundcolor={%
       \btLstHL<1>{1,3,5-6}%
       \btLstHL<2>{4}%
   },
    backgroundcolor=\color{gray!20}
]
    #include <stdio.h>

    int main(void) {%
    printf("Hello World!");  
        return 0;
    }
\end{lstlisting}
\end{frame}
\end{document}

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

관련 정보