기사에 나온 lstsample 환경(lstdoc 패키지)을 어떻게 사용할 수 있나요?

기사에 나온 lstsample 환경(lstdoc 패키지)을 어떻게 사용할 수 있나요?

와 함께 배포되는 패키지 lstsample의 환경을 시험해 보고 싶습니다.lstdoclistings패키지.

이를 위해 나는 다음 문서를 작성했습니다.

\documentclass{article}
\usepackage{lstdoc}
\usepackage{lipsum}

\begin{document}

\begin{lstsample}{}{}
  \color{blue}
  \lipsum[68]
\end{lstsample}

\end{document}

그러나 다음 메시지와 함께 컴파일이 실패합니다.

! Undefined control sequence.
\lst@sampleInput ->\MakePercentComment 
                                       \catcode `\^^M=10\relax \small \lst@s...
l.10     \end{lstsample}

내가 무엇을 놓치고 있나요?

답변1

패키지 lstdoc는 주로 클래스를 사용하는 문서에 사용됩니다 ltxdoc. 해당 클래스는 doc여기서 특히 관련된 두 개의 매크로 정의를 포함하는 클래스를 내부적으로 로드합니다.

\def\MakePercentIgnore{\catcode`\%9\relax}
\def\MakePercentComment{\catcode`\%14\relax}

환경 lstsample에는 두 개의 매크로가 필요하지만 사용 중인 클래스가 article이를 정의하지 않기 때문에 LaTeX는 코드를 컴파일하려고 할 때 해당 매크로를 정의되지 않은 것으로 정당하게 보고합니다. 위에 표시된 두 가지 정의를 전문에 추가하면 해당 문제가 해결됩니다.

또한 lstsample환경의 한 가지 특이한 점은 모든 것이 제대로 작동하려면그 안에 있는 모든 줄은 a로 시작하고 %그 뒤에 최소한 4개의 공백이 와야 합니다.. 그 규칙을 따르면 당신은 행복해질 것입니다.

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

\documentclass{article}

\usepackage{lstdoc}
\usepackage{xcolor}
\usepackage{lipsum}

% The following definitions are taken from doc.dtx.
% see http://mirrors.ctan.org/macros/latex/base/doc.dtx
\def\MakePercentIgnore{\catcode`\%9\relax}
\def\MakePercentComment{\catcode`\%14\relax}

\begin{document}

\begin{lstsample}{}{}
%    \color{blue}
%    \lipsum[68]  
\end{lstsample}

\end{document}

관련 정보