패키지 목록의 여러 줄 Matlab 주석

패키지 목록의 여러 줄 Matlab 주석

내 보고서에 일부 Matlab 코드를 포함하기 위해 패키지 목록을 사용하고 있습니다. 다음으로 시작하는 주석에서는 잘 작동 %하지만 여러 줄 주석은 인식하지 못합니다 %{ ... %}.

\usepackage{listings}
\lstset{language=Matlab}
...
\begin{lstlisting}
% normal comment
MATLAB code
%{
This is
a multiline
comment
%}
function [x,y] = test(x)
\end{lstlisting}

준다

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

대신에

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

Matlab에서.

\lstset작동하게 하려면 어떻게 변경해야 합니까 ?

답변1

내 추천은 패키지를 사용하는 것입니다matlab-prettifier이는 언어 정의(블록 주석 지원 포함) listings에서 제공하는 것 이상으로 ' MATLAB 코드에 대한 향상된 기능을 제공합니다 .listingsMatlab

\documentclass{article}
\usepackage{matlab-prettifier}
\lstset{style=Matlab-editor}

\begin{document}
\begin{lstlisting}
% normal comment
MATLAB code
%{
This is
a multiline
comment
%}
function [x,y] = test(x)
\end{lstlisting}
\end{document}

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

listings어떤 이유로 인해 기존 언어 구현과 함께 사용해야 하는 경우 Matlab패키지 morecomment키를 설정하여 블록 주석에 대한 지원을 추가할 수 있습니다.

morecomment=[s]{\%\{}{\%\}}

여기서는 [s]두 개의 구분 기호를 찾고 있음을 의미합니다. 첫 번째는 블록 주석을 열고 두 번째는 닫습니다. 다음 중괄호 그룹에는 각각 블록 주석의 여는 구분 기호와 닫는 구분 기호가 포함되어 있습니다. 주석 구분 기호를 정의할 때 백분율 기호와 개별 열기/닫기 중괄호는 모두 백슬래시로 이스케이프되어야 합니다.

\documentclass{article}
\usepackage{listings}
\lstset{
  language=Matlab,
  basicstyle=\ttfamily,
  morecomment=[s]{\%\{}{\%\}},
}

\begin{document}
\begin{lstlisting}
% normal comment
MATLAB code
%{
This is
a multiline
comment
%}
function [x,y] = test(x)
\end{lstlisting}
\end{document}

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

관련 정보